diff --git a/example/do_it_yourself_converters.cpp b/example/do_it_yourself_converters.cpp new file mode 100644 index 00000000..ad31f708 --- /dev/null +++ b/example/do_it_yourself_converters.cpp @@ -0,0 +1,126 @@ +/* + This example shows how to convert a class from and to native + Python objects, such as tuples. + + We do not want to expose the helper class MillerIndex as an + Extension Class. However, in order to simplify the wrapper code, + we want to define from_python() and to_python() functions for + class MillerIndex. + + Consider the alternatives: + + - Expose MillerIndex as an Extension Class. + We need a constructor MillerIndex(python::tuple). + Python function calls become more complex: + foo(MillerIndex((1,2,3)) instead of foo((1,2,3)) + We need a method such as MillerIndex().as_tuple(). + + - Define a wrapper function for each function that we + want to expose, e.g.: + void add(const IndexingSet& ixset, const python::tuple PyMIx) + + The first alternative introduces a new type that the user has to + deal with. Other modules using Miller indices might organize them in + different ways, for example to increase runtime efficiency for + important procedures. This means, the user has to know how to + convert between the different kinds of Miller index representations. + This can quickly become a nuisance. Relying on native Python data + structures minimizes the number of special types the user has to + learn and convert. Of course, this argument is only valid for + small and relatively simply classes. + + If there are many member functions with MillerIndex arguments, the + second alternative is impractical, and concentrating the conversion + mechanism in one central place is essential for code + maintainability. An added benefit is that more convenient (smarter) + conversion functions can be provided without cluttering the rest of + the wrapper code. + + */ + +#include +#include +#include +namespace python = boost::python; + +namespace { // Avoid cluttering the global namespace. + + // The helper class. + // + class MillerIndex { + public: + int v[3]; + }; + + // The main class. Imagine that there are MANY member functions + // like add() and get(). + // + class IndexingSet { + private: + std::vector VMIx; + public: + void add(const MillerIndex& MIx) { VMIx.push_back(MIx); } + MillerIndex get(std::size_t i) const { return VMIx[i]; } + }; +} + +BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE + + // Convert a Python tuple to a MillerIndex object. + // + MillerIndex from_python(PyObject* p, python::type) + { + python::tuple tup + = python::tuple(python::ref(p, python::ref::increment_count)); + if (tup.size() != 3) { + PyErr_SetString(PyExc_ValueError, + "expecting exactly 3 values in tuple."); + throw python::error_already_set(); + } + MillerIndex result; + for (int i = 0; i < 3; i++) + result.v[i] = from_python(tup[i].get(), python::type()); + return result; + } + + // Similar conversion for MillerIndex objects passed by value. + // Not actually used, but included to show the principle. + // + MillerIndex from_python(PyObject* p, python::type) + { + return from_python(p, python::type()); + } + + // Convert a MillerIndex object to a Python tuple. + // + PyObject* to_python(const MillerIndex& hkl) + { + python::tuple result(3); + for (int i = 0; i < 3; i++) + result.set_item(i, python::ref(to_python(hkl.v[i]))); + return result.reference().release(); + } + +BOOST_PYTHON_END_CONVERSION_NAMESPACE + +BOOST_PYTHON_MODULE_INIT(do_it_yourself_converters) +{ + try + { + // Create an object representing this extension module. + python::module_builder this_module("do_it_yourself_converters"); + + // Create the Python type object for our extension class. + python::class_builder ixset_class(this_module, "IndexingSet"); + + // Add the __init__ function. + ixset_class.def(python::constructor<>()); + // Add the member functions. + ixset_class.def(&IndexingSet::add, "add"); + ixset_class.def(&IndexingSet::get, "get"); + } + catch(...) + { + python::handle_exception(); // Deal with the exception for Python + } +} diff --git a/example/dvect_conversions.cpp b/example/dvect_conversions.cpp new file mode 100644 index 00000000..21527243 --- /dev/null +++ b/example/dvect_conversions.cpp @@ -0,0 +1,51 @@ + // basics first: const reference converters + boost::python::tuple const_dvect_reference_as_tuple(const vects::dvect& dv) + { + return dv.as_tuple(); + } + + // to_python smart pointer conversions + std::auto_ptr dvect_as_auto_ptr(const vects::dvect& dv) + { + return std::auto_ptr(new vects::dvect(dv)); + } + boost::shared_ptr dvect_as_shared_ptr(const vects::dvect& dv) + { + return boost::shared_ptr(new vects::dvect(dv)); + } + + // smart pointers passed by value + boost::python::ref auto_ptr_value_dvect_as_tuple(std::auto_ptr dv) + { + if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return dv->as_tuple().reference(); + } + boost::python::ref shared_ptr_value_dvect_as_tuple(boost::shared_ptr dv) + { + if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return dv->as_tuple().reference(); + } + + // smart pointers passed by reference + boost::python::ref auto_ptr_reference_dvect_as_tuple(std::auto_ptr& dv) + { + if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return dv->as_tuple().reference(); + } + boost::python::ref shared_ptr_reference_dvect_as_tuple(boost::shared_ptr& dv) + { + if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return dv->as_tuple().reference(); + } + + // smart pointers passed by const reference + boost::python::ref auto_ptr_const_reference_dvect_as_tuple(const std::auto_ptr& dv) + { + if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return dv->as_tuple().reference(); + } + boost::python::ref shared_ptr_const_reference_dvect_as_tuple(const boost::shared_ptr& dv) + { + if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return dv->as_tuple().reference(); + } diff --git a/example/dvect_defs.cpp b/example/dvect_defs.cpp new file mode 100644 index 00000000..2739b219 --- /dev/null +++ b/example/dvect_defs.cpp @@ -0,0 +1,13 @@ + this_module.def(dvect_as_auto_ptr, "dvect_as_auto_ptr"); + this_module.def(dvect_as_shared_ptr, "dvect_as_shared_ptr"); + + this_module.def(const_dvect_reference_as_tuple, "const_dvect_reference_as_tuple"); + + this_module.def(auto_ptr_value_dvect_as_tuple, "auto_ptr_value_dvect_as_tuple"); + this_module.def(shared_ptr_value_dvect_as_tuple, "shared_ptr_value_dvect_as_tuple"); + + this_module.def(auto_ptr_reference_dvect_as_tuple, "auto_ptr_reference_dvect_as_tuple"); + this_module.def(shared_ptr_reference_dvect_as_tuple, "shared_ptr_reference_dvect_as_tuple"); + + this_module.def(auto_ptr_const_reference_dvect_as_tuple, "auto_ptr_const_reference_dvect_as_tuple"); + this_module.def(shared_ptr_const_reference_dvect_as_tuple, "shared_ptr_const_reference_dvect_as_tuple"); diff --git a/example/ivect_conversions.cpp b/example/ivect_conversions.cpp new file mode 100644 index 00000000..4f59573d --- /dev/null +++ b/example/ivect_conversions.cpp @@ -0,0 +1,51 @@ + // basics first: const reference converters + boost::python::tuple const_ivect_reference_as_tuple(const vects::ivect& iv) + { + return iv.as_tuple(); + } + + // to_python smart pointer conversions + std::auto_ptr ivect_as_auto_ptr(const vects::ivect& iv) + { + return std::auto_ptr(new vects::ivect(iv)); + } + boost::shared_ptr ivect_as_shared_ptr(const vects::ivect& iv) + { + return boost::shared_ptr(new vects::ivect(iv)); + } + + // smart pointers passed by value + boost::python::ref auto_ptr_value_ivect_as_tuple(std::auto_ptr iv) + { + if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return iv->as_tuple().reference(); + } + boost::python::ref shared_ptr_value_ivect_as_tuple(boost::shared_ptr iv) + { + if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return iv->as_tuple().reference(); + } + + // smart pointers passed by reference + boost::python::ref auto_ptr_reference_ivect_as_tuple(std::auto_ptr& iv) + { + if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return iv->as_tuple().reference(); + } + boost::python::ref shared_ptr_reference_ivect_as_tuple(boost::shared_ptr& iv) + { + if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return iv->as_tuple().reference(); + } + + // smart pointers passed by const reference + boost::python::ref auto_ptr_const_reference_ivect_as_tuple(const std::auto_ptr& iv) + { + if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return iv->as_tuple().reference(); + } + boost::python::ref shared_ptr_const_reference_ivect_as_tuple(const boost::shared_ptr& iv) + { + if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); + return iv->as_tuple().reference(); + } diff --git a/example/ivect_defs.cpp b/example/ivect_defs.cpp new file mode 100644 index 00000000..811c243d --- /dev/null +++ b/example/ivect_defs.cpp @@ -0,0 +1,13 @@ + this_module.def(ivect_as_auto_ptr, "ivect_as_auto_ptr"); + this_module.def(ivect_as_shared_ptr, "ivect_as_shared_ptr"); + + this_module.def(const_ivect_reference_as_tuple, "const_ivect_reference_as_tuple"); + + this_module.def(auto_ptr_value_ivect_as_tuple, "auto_ptr_value_ivect_as_tuple"); + this_module.def(shared_ptr_value_ivect_as_tuple, "shared_ptr_value_ivect_as_tuple"); + + this_module.def(auto_ptr_reference_ivect_as_tuple, "auto_ptr_reference_ivect_as_tuple"); + this_module.def(shared_ptr_reference_ivect_as_tuple, "shared_ptr_reference_ivect_as_tuple"); + + this_module.def(auto_ptr_const_reference_ivect_as_tuple, "auto_ptr_const_reference_ivect_as_tuple"); + this_module.def(shared_ptr_const_reference_ivect_as_tuple, "shared_ptr_const_reference_ivect_as_tuple"); diff --git a/example/simple_vector.cpp b/example/simple_vector.cpp new file mode 100644 index 00000000..f18f2cad --- /dev/null +++ b/example/simple_vector.cpp @@ -0,0 +1,101 @@ +#include +namespace python = boost::python; + +namespace { // Avoid cluttering the global namespace. + + // A wrapper is used to define additional constructors. + // + struct vector_double_wrapper: std::vector + { + // Tell the compiler how to convert a base class object to + // this wrapper object. + vector_double_wrapper(PyObject*, const std::vector& vd) + : std::vector(vd) {} + + vector_double_wrapper(PyObject* self) + : std::vector() {} + + vector_double_wrapper(PyObject* self, int n) + : std::vector(n) {} + + vector_double_wrapper(PyObject* self, python::tuple tuple) + : std::vector(tuple.size()) + { + std::vector::iterator vd = begin(); + for (int i = 0; i < tuple.size(); i++) + vd[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(), + python::type()); + } + }; + + double getitem(const std::vector& vd, std::size_t key) { + return vd[key]; + } + + void setitem(std::vector& vd, std::size_t key, double d) { + std::vector::iterator vditer = vd.begin(); + vditer[key] = d; + } + + void delitem(std::vector& vd, std::size_t key) { + std::vector::iterator vditer = vd.begin(); + vd.erase(&vditer[key]); + } + + // Convert vector_double to a regular Python tuple. + // + python::tuple as_tuple(const std::vector& vd) + { + python::tuple t(vd.size()); + for (int i = 0; i < vd.size(); i++) t.set_item(i, + python::ref(BOOST_PYTHON_CONVERSION::to_python(vd[i]))); + return t; + } + + // Function returning a vector_double object to Python. + // + std::vector foo(int n) + { + std::vector vd(n); + std::vector::iterator vditer = vd.begin(); + for (int i = 0; i < n; i++) vditer[i] = double(i); + return vd; + } + + // Same as foo(), but avoid copying on return. + // + std::auto_ptr > bar(int n) + { + std::auto_ptr > vdptr(new std::vector(n)); + std::vector::iterator vditer = vdptr->begin(); + for (int i = 0; i < n; i++) vditer[i] = double(10 * i); + return vdptr; + } +} + +BOOST_PYTHON_MODULE_INIT(simple_vector) +{ + try + { + python::module_builder this_module("simple_vector"); + + python::class_builder, vector_double_wrapper> + vector_double(this_module, "vector_double"); + + vector_double.def(python::constructor<>()); + vector_double.def(python::constructor()); + vector_double.def(python::constructor()); + vector_double.def(&std::vector::size, "__len__"); + vector_double.def(getitem, "__getitem__"); + vector_double.def(setitem, "__setitem__"); + vector_double.def(delitem, "__delitem__"); + vector_double.def(as_tuple, "as_tuple"); + + this_module.def(foo, "foo"); + this_module.def(bar, "bar"); + } + catch(...) + { + python::handle_exception(); // Deal with the exception for Python + } +} diff --git a/example/swap_iv_dv.sh b/example/swap_iv_dv.sh new file mode 100644 index 00000000..fc072bee --- /dev/null +++ b/example/swap_iv_dv.sh @@ -0,0 +1 @@ +sed 's/iv/xv/g' $1 | sed 's/dv/iv/g' | sed 's/xv/dv/g' diff --git a/example/test_do_it_yourself_converters.py b/example/test_do_it_yourself_converters.py new file mode 100644 index 00000000..e256c614 --- /dev/null +++ b/example/test_do_it_yourself_converters.py @@ -0,0 +1,22 @@ +r'''>>> import do_it_yourself_converters + >>> ixset = do_it_yourself_converters.IndexingSet() + >>> ixset.add((1,2,3)) + >>> ixset.add((4,5,6)) + >>> ixset.add((7,8,9)) + >>> print ixset.get(0) + (1, 2, 3) + >>> print ixset.get(1) + (4, 5, 6) + >>> print ixset.get(2) + (7, 8, 9) +''' + +def run(args = None): + if args is not None: + import sys + sys.argv = args + import doctest, test_do_it_yourself_converters + doctest.testmod(test_do_it_yourself_converters) + +if __name__ == '__main__': + run() diff --git a/example/test_simple_vector.py b/example/test_simple_vector.py new file mode 100644 index 00000000..a19e205b --- /dev/null +++ b/example/test_simple_vector.py @@ -0,0 +1,35 @@ +r'''>>> import simple_vector + >>> v=simple_vector.vector_double() + >>> print v.as_tuple() + () + >>> v=simple_vector.vector_double(5) + >>> print v.as_tuple() + (0.0, 0.0, 0.0, 0.0, 0.0) + >>> print len(v) + 5 + >>> v=simple_vector.vector_double((3,4,5)) + >>> print v.as_tuple() + (3.0, 4.0, 5.0) + >>> print v[1] + 4.0 + >>> v[1] = 40 + >>> print v.as_tuple() + (3.0, 40.0, 5.0) + >>> del v[1] + >>> print v.as_tuple() + (3.0, 5.0) + >>> print simple_vector.foo(11).as_tuple() + (0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) + >>> print simple_vector.bar(12).as_tuple() + (0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0) +''' + +def run(args = None): + if args is not None: + import sys + sys.argv = args + import doctest, test_simple_vector + doctest.testmod(test_simple_vector) + +if __name__ == '__main__': + run() diff --git a/example/tst_dvect1.py b/example/tst_dvect1.py new file mode 100644 index 00000000..12c53739 --- /dev/null +++ b/example/tst_dvect1.py @@ -0,0 +1,23 @@ +def f(): + 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.const_ivect_reference_as_tuple(iv) + aiv = dvect.ivect_as_auto_ptr(iv) + print dvect.const_ivect_reference_as_tuple(aiv) + siv = dvect.ivect_as_shared_ptr(iv) + print dvect.const_ivect_reference_as_tuple(siv) + print aiv.as_tuple() + print siv.as_tuple() + +if (__name__ == "__main__"): + import sys, string + n = 1 + if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) + for i in xrange(n): + f() diff --git a/example/tst_dvect2.py b/example/tst_dvect2.py new file mode 100644 index 00000000..868c107d --- /dev/null +++ b/example/tst_dvect2.py @@ -0,0 +1,85 @@ +def f(): + import dvect + import ivect + # + dv = dvect.dvect((1,2,3,4,5)) + iv = dv.as_ivect() + # + aiv = dvect.ivect_as_auto_ptr(iv) + print '1. auto_ptr_value_ivect_as_tuple' + print ivect.auto_ptr_value_ivect_as_tuple(aiv) + print '2. auto_ptr_value_ivect_as_tuple' + print ivect.auto_ptr_value_ivect_as_tuple(aiv) + # + adv = dvect.dvect_as_auto_ptr(dv) + print '1. auto_ptr_value_dvect_as_tuple' + print ivect.auto_ptr_value_dvect_as_tuple(adv) + print '2. auto_ptr_value_dvect_as_tuple' + print ivect.auto_ptr_value_dvect_as_tuple(adv) + # + siv = dvect.ivect_as_shared_ptr(iv) + print '1. shared_ptr_value_ivect_as_tuple' + print ivect.shared_ptr_value_ivect_as_tuple(siv) + print '2. shared_ptr_value_ivect_as_tuple' + print ivect.shared_ptr_value_ivect_as_tuple(siv) + # + sdv = dvect.dvect_as_shared_ptr(dv) + print '1. shared_ptr_value_dvect_as_tuple' + print ivect.shared_ptr_value_dvect_as_tuple(sdv) + print '2. shared_ptr_value_dvect_as_tuple' + print ivect.shared_ptr_value_dvect_as_tuple(sdv) + # + aiv = dvect.ivect_as_auto_ptr(iv) + print '1. auto_ptr_reference_ivect_as_tuple' + print ivect.auto_ptr_reference_ivect_as_tuple(aiv) + print '2. auto_ptr_reference_ivect_as_tuple' + print ivect.auto_ptr_reference_ivect_as_tuple(aiv) + # + adv = dvect.dvect_as_auto_ptr(dv) + print '1. auto_ptr_reference_dvect_as_tuple' + print ivect.auto_ptr_reference_dvect_as_tuple(adv) + print '2. auto_ptr_reference_dvect_as_tuple' + print ivect.auto_ptr_reference_dvect_as_tuple(adv) + # + siv = dvect.ivect_as_shared_ptr(iv) + print '1. shared_ptr_reference_ivect_as_tuple' + print ivect.shared_ptr_reference_ivect_as_tuple(siv) + print '2. shared_ptr_reference_ivect_as_tuple' + print ivect.shared_ptr_reference_ivect_as_tuple(siv) + # + sdv = dvect.dvect_as_shared_ptr(dv) + print '1. shared_ptr_reference_dvect_as_tuple' + print ivect.shared_ptr_reference_dvect_as_tuple(sdv) + print '2. shared_ptr_reference_dvect_as_tuple' + print ivect.shared_ptr_reference_dvect_as_tuple(sdv) + # + aiv = dvect.ivect_as_auto_ptr(iv) + print '1. auto_ptr_const_reference_ivect_as_tuple' + print ivect.auto_ptr_const_reference_ivect_as_tuple(aiv) + print '2. auto_ptr_const_reference_ivect_as_tuple' + print ivect.auto_ptr_const_reference_ivect_as_tuple(aiv) + # + adv = dvect.dvect_as_auto_ptr(dv) + print '1. auto_ptr_const_reference_dvect_as_tuple' + print ivect.auto_ptr_const_reference_dvect_as_tuple(adv) + print '2. auto_ptr_const_reference_dvect_as_tuple' + print ivect.auto_ptr_const_reference_dvect_as_tuple(adv) + # + siv = dvect.ivect_as_shared_ptr(iv) + print '1. shared_ptr_const_reference_ivect_as_tuple' + print ivect.shared_ptr_const_reference_ivect_as_tuple(siv) + print '2. shared_ptr_const_reference_ivect_as_tuple' + print ivect.shared_ptr_const_reference_ivect_as_tuple(siv) + # + sdv = dvect.dvect_as_shared_ptr(dv) + print '1. shared_ptr_const_reference_dvect_as_tuple' + print ivect.shared_ptr_const_reference_dvect_as_tuple(sdv) + print '2. shared_ptr_const_reference_dvect_as_tuple' + print ivect.shared_ptr_const_reference_dvect_as_tuple(sdv) + +if (__name__ == "__main__"): + import sys, string + n = 1 + if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) + for i in xrange(n): + f() diff --git a/example/tst_ivect1.py b/example/tst_ivect1.py new file mode 100644 index 00000000..62d3ecf4 --- /dev/null +++ b/example/tst_ivect1.py @@ -0,0 +1,23 @@ +def f(): + 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.const_dvect_reference_as_tuple(dv) + adv = ivect.dvect_as_auto_ptr(dv) + print ivect.const_dvect_reference_as_tuple(adv) + sdv = ivect.dvect_as_shared_ptr(dv) + print ivect.const_dvect_reference_as_tuple(sdv) + print adv.as_tuple() + print sdv.as_tuple() + +if (__name__ == "__main__"): + import sys, string + n = 1 + if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) + for i in xrange(n): + f() diff --git a/example/tst_ivect2.py b/example/tst_ivect2.py new file mode 100644 index 00000000..0db6903d --- /dev/null +++ b/example/tst_ivect2.py @@ -0,0 +1,85 @@ +def f(): + import ivect + import dvect + # + iv = ivect.ivect((1,2,3,4,5)) + dv = iv.as_dvect() + # + adv = ivect.dvect_as_auto_ptr(dv) + print '1. auto_ptr_value_dvect_as_tuple' + print dvect.auto_ptr_value_dvect_as_tuple(adv) + print '2. auto_ptr_value_dvect_as_tuple' + print dvect.auto_ptr_value_dvect_as_tuple(adv) + # + aiv = ivect.ivect_as_auto_ptr(iv) + print '1. auto_ptr_value_ivect_as_tuple' + print dvect.auto_ptr_value_ivect_as_tuple(aiv) + print '2. auto_ptr_value_ivect_as_tuple' + print dvect.auto_ptr_value_ivect_as_tuple(aiv) + # + sdv = ivect.dvect_as_shared_ptr(dv) + print '1. shared_ptr_value_dvect_as_tuple' + print dvect.shared_ptr_value_dvect_as_tuple(sdv) + print '2. shared_ptr_value_dvect_as_tuple' + print dvect.shared_ptr_value_dvect_as_tuple(sdv) + # + siv = ivect.ivect_as_shared_ptr(iv) + print '1. shared_ptr_value_ivect_as_tuple' + print dvect.shared_ptr_value_ivect_as_tuple(siv) + print '2. shared_ptr_value_ivect_as_tuple' + print dvect.shared_ptr_value_ivect_as_tuple(siv) + # + adv = ivect.dvect_as_auto_ptr(dv) + print '1. auto_ptr_reference_dvect_as_tuple' + print dvect.auto_ptr_reference_dvect_as_tuple(adv) + print '2. auto_ptr_reference_dvect_as_tuple' + print dvect.auto_ptr_reference_dvect_as_tuple(adv) + # + aiv = ivect.ivect_as_auto_ptr(iv) + print '1. auto_ptr_reference_ivect_as_tuple' + print dvect.auto_ptr_reference_ivect_as_tuple(aiv) + print '2. auto_ptr_reference_ivect_as_tuple' + print dvect.auto_ptr_reference_ivect_as_tuple(aiv) + # + sdv = ivect.dvect_as_shared_ptr(dv) + print '1. shared_ptr_reference_dvect_as_tuple' + print dvect.shared_ptr_reference_dvect_as_tuple(sdv) + print '2. shared_ptr_reference_dvect_as_tuple' + print dvect.shared_ptr_reference_dvect_as_tuple(sdv) + # + siv = ivect.ivect_as_shared_ptr(iv) + print '1. shared_ptr_reference_ivect_as_tuple' + print dvect.shared_ptr_reference_ivect_as_tuple(siv) + print '2. shared_ptr_reference_ivect_as_tuple' + print dvect.shared_ptr_reference_ivect_as_tuple(siv) + # + adv = ivect.dvect_as_auto_ptr(dv) + print '1. auto_ptr_const_reference_dvect_as_tuple' + print dvect.auto_ptr_const_reference_dvect_as_tuple(adv) + print '2. auto_ptr_const_reference_dvect_as_tuple' + print dvect.auto_ptr_const_reference_dvect_as_tuple(adv) + # + aiv = ivect.ivect_as_auto_ptr(iv) + print '1. auto_ptr_const_reference_ivect_as_tuple' + print dvect.auto_ptr_const_reference_ivect_as_tuple(aiv) + print '2. auto_ptr_const_reference_ivect_as_tuple' + print dvect.auto_ptr_const_reference_ivect_as_tuple(aiv) + # + sdv = ivect.dvect_as_shared_ptr(dv) + print '1. shared_ptr_const_reference_dvect_as_tuple' + print dvect.shared_ptr_const_reference_dvect_as_tuple(sdv) + print '2. shared_ptr_const_reference_dvect_as_tuple' + print dvect.shared_ptr_const_reference_dvect_as_tuple(sdv) + # + siv = ivect.ivect_as_shared_ptr(iv) + print '1. shared_ptr_const_reference_ivect_as_tuple' + print dvect.shared_ptr_const_reference_ivect_as_tuple(siv) + print '2. shared_ptr_const_reference_ivect_as_tuple' + print dvect.shared_ptr_const_reference_ivect_as_tuple(siv) + +if (__name__ == "__main__"): + import sys, string + n = 1 + if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) + for i in xrange(n): + f()