From 8631427d4e74e9b9b2b05490cfe950a3d1af5db7 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 21 Mar 2001 01:11:03 +0000 Subject: [PATCH] Much more extensive testing of import_converters. [SVN r9618] --- example/dvect.cpp | 41 +++++++---------------------------------- example/ivect.cpp | 41 +++++++---------------------------------- example/tst_dvect.py | 16 ---------------- example/tst_ivect.py | 16 ---------------- 4 files changed, 14 insertions(+), 100 deletions(-) delete mode 100644 example/tst_dvect.py delete mode 100644 example/tst_ivect.py diff --git a/example/dvect.cpp b/example/dvect.cpp index 937e2ac0..8f298b26 100644 --- a/example/dvect.cpp +++ b/example/dvect.cpp @@ -1,10 +1,13 @@ -#include "ivect.h" #include "dvect.h" +#include "ivect.h" #include namespace python = boost::python; namespace { +# include "dvect_conversions.cpp" +# include "ivect_conversions.cpp" + vects::ivect dvect_as_ivect(const vects::dvect& dv) { vects::ivect iv(dv.size()); @@ -12,36 +15,9 @@ namespace { for (int i = 0; i < dv.size(); i++) iviter[i] = static_cast(dv[i]); return iv; } - - boost::python::tuple ivect_as_tuple(const vects::ivect& iv) - { - return iv.as_tuple(); - } - - std::auto_ptr auto_ptr_ivect(const vects::dvect& dv) - { - return std::auto_ptr(new vects::ivect(dvect_as_ivect(dv))); - } - - boost::shared_ptr shared_ptr_ivect(const vects::dvect& dv) - { - return boost::shared_ptr(new vects::ivect(dvect_as_ivect(dv))); - } - - boost::python::tuple auto_ptr_ivect_as_tuple(std::auto_ptr& iv) - { - return iv->as_tuple(); - } - - boost::python::tuple shared_ptr_ivect_as_tuple(boost::shared_ptr& iv) - { - return iv->as_tuple(); - } } -extern "C" -DL_EXPORT(void) -initdvect() +BOOST_PYTHON_MODULE_INIT(dvect) { try { @@ -56,11 +32,8 @@ initdvect() dvect_class.def(&vects::dvect::as_tuple, "as_tuple"); dvect_class.def(dvect_as_ivect, "as_ivect"); - this_module.def(ivect_as_tuple, "ivect_as_tuple"); - dvect_class.def(auto_ptr_ivect, "auto_ptr_ivect"); - dvect_class.def(shared_ptr_ivect, "shared_ptr_ivect"); - this_module.def(auto_ptr_ivect_as_tuple, "auto_ptr_ivect_as_tuple"); - this_module.def(shared_ptr_ivect_as_tuple, "shared_ptr_ivect_as_tuple"); +# include "dvect_defs.cpp" +# include "ivect_defs.cpp" } catch(...) { diff --git a/example/ivect.cpp b/example/ivect.cpp index a3c7b3e0..abd065c1 100644 --- a/example/ivect.cpp +++ b/example/ivect.cpp @@ -1,10 +1,13 @@ -#include "ivect.h" #include "dvect.h" +#include "ivect.h" #include namespace python = boost::python; namespace { +# include "dvect_conversions.cpp" +# include "ivect_conversions.cpp" + vects::dvect ivect_as_dvect(const vects::ivect& iv) { vects::dvect dv(iv.size()); @@ -12,36 +15,9 @@ namespace { for (int i = 0; i < iv.size(); i++) dviter[i] = static_cast(iv[i]); return dv; } - - boost::python::tuple dvect_as_tuple(const vects::dvect& dv) - { - return dv.as_tuple(); - } - - std::auto_ptr auto_ptr_dvect(const vects::ivect& iv) - { - return std::auto_ptr(new vects::dvect(ivect_as_dvect(iv))); - } - - boost::shared_ptr shared_ptr_dvect(const vects::ivect& iv) - { - return boost::shared_ptr(new vects::dvect(ivect_as_dvect(iv))); - } - - boost::python::tuple auto_ptr_dvect_as_tuple(std::auto_ptr& dv) - { - return dv->as_tuple(); - } - - boost::python::tuple shared_ptr_dvect_as_tuple(boost::shared_ptr& dv) - { - return dv->as_tuple(); - } } -extern "C" -DL_EXPORT(void) -initivect() +BOOST_PYTHON_MODULE_INIT(ivect) { try { @@ -56,11 +32,8 @@ initivect() ivect_class.def(&vects::ivect::as_tuple, "as_tuple"); ivect_class.def(ivect_as_dvect, "as_dvect"); - this_module.def(dvect_as_tuple, "dvect_as_tuple"); - ivect_class.def(auto_ptr_dvect, "auto_ptr_dvect"); - ivect_class.def(shared_ptr_dvect, "shared_ptr_dvect"); - this_module.def(auto_ptr_dvect_as_tuple, "auto_ptr_dvect_as_tuple"); - this_module.def(shared_ptr_dvect_as_tuple, "shared_ptr_dvect_as_tuple"); +# include "dvect_defs.cpp" +# include "ivect_defs.cpp" } catch(...) { diff --git a/example/tst_dvect.py b/example/tst_dvect.py deleted file mode 100644 index 563f0ad5..00000000 --- a/example/tst_dvect.py +++ /dev/null @@ -1,16 +0,0 @@ -import dvect -print dvect.dvect.__converters__ -dv = dvect.dvect((1,2,3,4,5)) -print dv -print dv.as_tuple() -iv = dv.as_ivect() -print iv -print iv.as_tuple() -print dvect.ivect_as_tuple(iv) -aiv = dv.auto_ptr_ivect() -print aiv -siv = dv.shared_ptr_ivect() -print dvect.auto_ptr_ivect_as_tuple(aiv) -print dvect.ivect_as_tuple(aiv) -print dvect.shared_ptr_ivect_as_tuple(siv) -print dvect.ivect_as_tuple(siv) diff --git a/example/tst_ivect.py b/example/tst_ivect.py deleted file mode 100644 index 58bc323f..00000000 --- a/example/tst_ivect.py +++ /dev/null @@ -1,16 +0,0 @@ -import ivect -print ivect.ivect.__converters__ -iv = ivect.ivect((1,2,3,4,5)) -print iv -print iv.as_tuple() -dv = iv.as_dvect() -print dv -print dv.as_tuple() -print ivect.dvect_as_tuple(dv) -adv = iv.auto_ptr_dvect() -print adv -sdv = iv.shared_ptr_dvect() -print ivect.auto_ptr_dvect_as_tuple(adv) -print ivect.dvect_as_tuple(adv) -print ivect.shared_ptr_dvect_as_tuple(sdv) -print ivect.dvect_as_tuple(sdv)