// -*- mode:c++ -*- // // Module testlinear.cpp // // Copyright (c) 2003 Raoul M. Gough // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy // at http://www.boost.org/LICENSE_1_0.txt) // // History // ======= // 2003/ 9/ 8 rmg File creation as testsuite.cpp // 2003/ 9/29 rmg Renamed testlinear.cpp to allow division into parts // // $Id$ // #include "IntWrapper.hpp" #include #include #include #include #include #include #include #include #include #include #include bool IntWrapper::gIntWrapperTrace = true; unsigned IntWrapper::ourObjectCounter = 0; boost::python::indexing::iterator_pair getArray() { static IntWrapper array[] = { IntWrapper(8), IntWrapper(6), IntWrapper(4), IntWrapper(2) , IntWrapper(1), IntWrapper(3), IntWrapper(5) , IntWrapper(7), IntWrapper(0) }; return boost::python::indexing::iterator_pair (boost::python::indexing::begin(array) , boost::python::indexing::end(array)); } std::string repr (IntWrapper const &i) { std::stringstream temp; temp << i; return temp.str(); } BOOST_PYTHON_MODULE(testlinear) { boost::python::implicitly_convertible (); boost::python::def ("setTrace", &IntWrapper::setTrace); boost::python::class_ ("IntWrapper", boost::python::init()) .def ("increment", &IntWrapper::increment) .def ("__repr__", repr) .def ("__cmp__", compare) ; typedef std::vector Container1; boost::python::class_("Vector") .def (boost::python::indexing::container_suite()) .def ("reserve", &Container1::reserve) ; typedef std::list Container2; boost::python::class_("List") .def (boost::python::indexing::container_suite()); typedef boost::python::indexing::iterator_pair Container3; boost::python::class_ ("Array", boost::python::init()) .def (boost::python::indexing::container_suite()); boost::python::def ("getArray", getArray); typedef std::vector Container4; // Returning internal references to elements of a vector is // dangerous! The references can be invalidated by inserts or // deletes! boost::python::class_("Vector_ref") .def (boost::python::indexing::container_suite ::with_policies (boost::python::return_internal_reference<>())); typedef boost::python::indexing::container_proxy< std::vector > Container5; boost::python::class_("Vector_proxy") .def (boost::python::indexing::container_suite()) .def ("reserve", &Container5::reserve) ; /* The no-partial-specialization version for vector using namespace boost::python; using namespace indexing; class_ > ("vector_int") .def (visitor < default_algorithms < default_sequence_traits < std::vector > >, return_value_policy >()); */ }