File tree Expand file tree Collapse file tree
include/boost/python/suite/indexing/detail Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111# include < boost/get_pointer.hpp>
1212# include < boost/detail/binary_search.hpp>
1313# include < boost/numeric/conversion/cast.hpp>
14+ # include < boost/type_traits/is_pointer.hpp>
1415# include < vector>
1516# include < map>
1617#include < iostream>
@@ -462,13 +463,29 @@ namespace boost { namespace python { namespace detail {
462463 {
463464 }
464465
466+ template <class DataType >
467+ static object
468+ base_get_item_helper (DataType const & p, mpl::true_)
469+ {
470+ return object (ptr (p));
471+ }
472+
473+ template <class DataType >
474+ static object
475+ base_get_item_helper (DataType const & x, mpl::false_)
476+ {
477+ return object (x);
478+ }
479+
465480 static object
466481 base_get_item_ (back_reference<Container&> const & container, PyObject* i)
467482 {
468- return object (
483+ return base_get_item_helper (
469484 DerivedPolicies::get_item (
470485 container.get (), DerivedPolicies::
471- convert_index (container.get (), i)));
486+ convert_index (container.get (), i))
487+ , is_pointer<BOOST_DEDUCED_TYPENAME Container::value_type>()
488+ );
472489 }
473490
474491 static void
Original file line number Diff line number Diff line change @@ -162,6 +162,8 @@ bpl-test crossmod_exception
162162[ bpl-test docstring ]
163163
164164[ bpl-test vector_indexing_suite ]
165+ [ bpl-test pointer_vector ]
166+
165167
166168[ extension map_indexing_suite_ext
167169 : map_indexing_suite.cpp int_map_indexing_suite.cpp <template>../build/extension ]
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ bpl-test crossmod_exception
115115[ bpl-test docstring ]
116116
117117[ bpl-test vector_indexing_suite ]
118+ [ bpl-test pointer_vector ]
118119
119120[ python-extension map_indexing_suite_ext
120121 : map_indexing_suite.cpp int_map_indexing_suite.cpp
Original file line number Diff line number Diff line change 1+ #include < vector>
2+ #include < boost/python.hpp>
3+ #include < boost/python/suite/indexing/vector_indexing_suite.hpp>
4+
5+ using namespace boost ::python;
6+
7+ class Abstract
8+ {
9+ public:
10+ virtual std::string f () =0;
11+ };
12+
13+ class Concrete1 : public Abstract
14+ {
15+ public:
16+ virtual std::string f () { return " harru" ; }
17+ };
18+
19+ typedef std::vector<Abstract*> ListOfObjects;
20+
21+ class DoesSomething
22+ {
23+ public:
24+ DoesSomething () {}
25+
26+ ListOfObjects returnList ()
27+ {
28+ ListOfObjects lst;
29+ lst.push_back (new Concrete1 ()); return lst;
30+ }
31+ };
32+
33+ BOOST_PYTHON_MODULE (pointer_vector_ext)
34+ {
35+ class_<Abstract, boost::noncopyable>(" Abstract" , no_init)
36+ .def (" f" , &Abstract::f)
37+ ;
38+
39+ class_<ListOfObjects>(" ListOfObjects" )
40+ .def ( vector_indexing_suite<ListOfObjects>() )
41+ ;
42+
43+ class_<DoesSomething>(" DoesSomething" )
44+ .def (" returnList" , &DoesSomething::returnList)
45+ ;
46+ }
47+
48+
Original file line number Diff line number Diff line change 1+ # Copyright Joel de Guzman 2004. Distributed under the Boost
2+ # Software License, Version 1.0. (See accompanying
3+ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4+ '''
5+
6+ >>> import pointer_vector_ext
7+ >>> d = pointer_vector_ext.DoesSomething()
8+ >>> lst = d.returnList()
9+ >>> lst[0].f();
10+ 'harru'
11+
12+ '''
13+
14+
15+ def run (args = None ):
16+ import sys
17+ import doctest
18+
19+ if args is not None :
20+ sys .argv = args
21+ return doctest .testmod (sys .modules .get (__name__ ))
22+
23+ if __name__ == '__main__' :
24+ print 'running...'
25+ import sys
26+ status = run ()[0 ]
27+ if (status == 0 ): print "Done."
28+ sys .exit (status )
29+
30+
31+
You can’t perform that action at this time.
0 commit comments