From c014dee6dc273ef613682643c7387b7cbfc0174b Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Thu, 7 Aug 2003 08:45:57 +0000 Subject: [PATCH] Fixed no proxy handling for containers of primitive types. [SVN r19484] --- .../boost/python/indexing/indexing_suite.hpp | 57 ++++++++++++------- test/vector_indexing_suite.cpp | 5 ++ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/include/boost/python/indexing/indexing_suite.hpp b/include/boost/python/indexing/indexing_suite.hpp index 58398c59..e8ae1d91 100644 --- a/include/boost/python/indexing/indexing_suite.hpp +++ b/include/boost/python/indexing/indexing_suite.hpp @@ -110,16 +110,46 @@ namespace boost { namespace python { , Index > > { - public: - + private: + + typedef boost::mpl::or_< + boost::mpl::bool_ + , boost::mpl::or_< + boost::is_integral + , boost::is_float + , boost::is_pointer + , boost::is_member_pointer + , boost::is_enum + > + > no_proxy; + typedef detail::container_element container_element_t; + + typedef typename boost::mpl::if_< + no_proxy + , iterator + , iterator > >::type + def_iterator; + + static void + register_container_element(boost::mpl::false_) + { + register_ptr_to_python(); + } + + static void + register_container_element(boost::mpl::true_) + { + } + public: + template void visit(Class& cl) const { // Hook into the class_ generic visitation .def function - register_ptr_to_python(); + register_container_element(no_proxy()); cl .def("__len__", base_size) @@ -127,8 +157,7 @@ namespace boost { namespace python { .def("__delitem__", &base_delete_item) .def("__getitem__", &base_get_item) .def("__contains__", &base_contains) - .def("__iter__", - iterator >()) + .def("__iter__", def_iterator()) .def("append", &base_append) .def("extend", &base_extend) @@ -136,9 +165,7 @@ namespace boost { namespace python { } private: - - typedef boost::mpl::bool_ no_proxy; - + static object base_get_item_( back_reference const& container, @@ -170,7 +197,7 @@ namespace boost { namespace python { // No Proxy return object( DerivedPolicies::get_item( - container, DerivedPolicies:: + container.get(), DerivedPolicies:: convert_index(container.get(), i))); } @@ -181,17 +208,7 @@ namespace boost { namespace python { return base_get_slice( container.get(), reinterpret_cast(i)); - return base_get_item_(container, i, - boost::mpl::or_< - no_proxy - , boost::mpl::or_< - boost::is_integral - , boost::is_float - , boost::is_pointer - , boost::is_member_pointer - , boost::is_enum - > - >()); + return base_get_item_(container, i, no_proxy()); } static object diff --git a/test/vector_indexing_suite.cpp b/test/vector_indexing_suite.cpp index 6edd7625..e60aee62 100644 --- a/test/vector_indexing_suite.cpp +++ b/test/vector_indexing_suite.cpp @@ -39,5 +39,10 @@ BOOST_PYTHON_MODULE(vector_indexing_suite_ext) class_ >("XVec") .def(vector_indexing_suite >()) ; + + // Compile check only... + class_ >("FloatVec") + .def(vector_indexing_suite >()) + ; }