2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 18:12:43 +00:00

fixed bug where a vector<T*> is being wrapped by the indexing suite.

[SVN r29930]
This commit is contained in:
Joel de Guzman
2005-07-07 14:00:31 +00:00
parent 331209d8b5
commit 980733a96d
5 changed files with 101 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
# include <boost/get_pointer.hpp>
# include <boost/detail/binary_search.hpp>
# include <boost/numeric/conversion/cast.hpp>
# include <boost/type_traits/is_pointer.hpp>
# include <vector>
# include <map>
#include <iostream>
@@ -462,13 +463,29 @@ namespace boost { namespace python { namespace detail {
{
}
template <class DataType>
static object
base_get_item_helper(DataType const& p, mpl::true_)
{
return object(ptr(p));
}
template <class DataType>
static object
base_get_item_helper(DataType const& x, mpl::false_)
{
return object(x);
}
static object
base_get_item_(back_reference<Container&> const& container, PyObject* i)
{
return object(
return base_get_item_helper(
DerivedPolicies::get_item(
container.get(), DerivedPolicies::
convert_index(container.get(), i)));
convert_index(container.get(), i))
, is_pointer<BOOST_DEDUCED_TYPENAME Container::value_type>()
);
}
static void

View File

@@ -162,6 +162,8 @@ bpl-test crossmod_exception
[ bpl-test docstring ]
[ bpl-test vector_indexing_suite ]
[ bpl-test pointer_vector ]
[ extension map_indexing_suite_ext
: map_indexing_suite.cpp int_map_indexing_suite.cpp <template>../build/extension ]

View File

@@ -115,6 +115,7 @@ bpl-test crossmod_exception
[ bpl-test docstring ]
[ bpl-test vector_indexing_suite ]
[ bpl-test pointer_vector ]
[ python-extension map_indexing_suite_ext
: map_indexing_suite.cpp int_map_indexing_suite.cpp

48
test/pointer_vector.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include <vector>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
using namespace boost::python;
class Abstract
{
public:
virtual std::string f() =0;
};
class Concrete1 : public Abstract
{
public:
virtual std::string f() { return "harru"; }
};
typedef std::vector<Abstract*> ListOfObjects;
class DoesSomething
{
public:
DoesSomething() {}
ListOfObjects returnList()
{
ListOfObjects lst;
lst.push_back(new Concrete1()); return lst;
}
};
BOOST_PYTHON_MODULE(pointer_vector_ext)
{
class_<Abstract, boost::noncopyable>("Abstract", no_init)
.def("f", &Abstract::f)
;
class_<ListOfObjects>("ListOfObjects")
.def( vector_indexing_suite<ListOfObjects>() )
;
class_<DoesSomething>("DoesSomething")
.def("returnList", &DoesSomething::returnList)
;
}

31
test/pointer_vector.py Normal file
View File

@@ -0,0 +1,31 @@
# Copyright Joel de Guzman 2004. Distributed under 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)
'''
>>> import pointer_vector_ext
>>> d = pointer_vector_ext.DoesSomething()
>>> lst = d.returnList()
>>> lst[0].f();
'harru'
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print 'running...'
import sys
status = run()[0]
if (status == 0): print "Done."
sys.exit(status)