15 #ifndef __PYIPSDKBASE_PYTHONSTDVECTORUTILS_H__ 16 #define __PYIPSDKBASE_PYTHONSTDVECTORUTILS_H__ 19 #include <boost/python/iterator.hpp> 20 #include <boost/python/self.hpp> 21 #include <boost/python/operators.hpp> 22 #include <boost/python/suite/indexing/vector_indexing_suite.hpp> 31 template <
typename Container>
35 static void* convertible(PyObject*
object)
37 return PyObject_GetIter(
object) ? object : NULL;
47 static void construct(
49 boost::python::converter::rvalue_from_python_stage1_data* data)
51 namespace python = boost::python;
54 python::handle<> handle(python::borrowed(
object));
58 typedef python::converter::rvalue_from_python_storage<Container>
60 void* storage =
reinterpret_cast<storage_type*
>(data)->storage.bytes;
62 typedef python::stl_input_iterator<typename Container::value_type>
69 new (storage)Container(
70 iterator(python::object(handle)),
72 data->convertible = storage;
76 static std::string to_string(
const Container& cl)
81 for (
typename Container::const_iterator
82 i = cl.begin(), e = cl.end(); i != e; ++i) {
97 template<
class Container>
void 98 export_vector_no_proxy(
const char* py_name)
100 boost::python::type_info info = boost::python::type_id<Container>();
101 const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
102 if (reg == 0 || reg->m_to_python == 0) {
104 boost::python::class_<Container>(py_name)
105 .def(boost::python::vector_indexing_suite<Container, true>())
107 boost::python::converter::registry::push_back(
110 boost::python::type_id<Container>());
115 template<
class Container>
void 116 export_vector(
const char* py_name)
118 boost::python::type_info info = boost::python::type_id<Container>();
119 const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
120 if (reg == 0 || reg->m_to_python == 0) {
122 boost::python::class_<Container>(py_name)
123 .def(boost::python::vector_indexing_suite<Container>())
124 .def(
"__str__", &VectorConverter<Container>::to_string);
125 boost::python::converter::registry::push_back(
126 &VectorConverter<Container>::convertible,
127 &VectorConverter<Container>::construct,
128 boost::python::type_id<Container>());
133 template<
class Container>
void 134 export_vector_no_str(
const char* py_name)
136 boost::python::type_info info = boost::python::type_id<Container>();
137 const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
138 if (reg == 0 || reg->m_to_python == 0) {
140 boost::python::class_<Container>(py_name)
141 .def(boost::python::vector_indexing_suite<Container>());
142 boost::python::converter::registry::push_back(
143 &VectorConverter<Container>::convertible,
144 &VectorConverter<Container>::construct,
145 boost::python::type_id<Container>());
150 template<
class Container>
void 151 export_vector_no_str_no_proxy(
const char* py_name)
153 boost::python::type_info info = boost::python::type_id<Container>();
154 const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
155 if (reg == 0 || reg->m_to_python == 0) {
157 boost::python::class_<Container>(py_name)
158 .def(boost::python::vector_indexing_suite<Container, true>());
159 boost::python::converter::registry::push_back(
160 &VectorConverter<Container>::convertible,
161 &VectorConverter<Container>::construct,
162 boost::python::type_id<Container>());
172 #endif // __PYIPSDKBASE_PYTHONSTDVECTORUTILS_H__ Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: PythonStdVectorUtils.h:32