15 #ifndef __PYIPSDKBASE_PYTHONSTDPAIRUTILS_H__ 16 #define __PYIPSDKBASE_PYTHONSTDPAIRUTILS_H__ 19 #include <boost/python/iterator.hpp> 20 #include <boost/python/self.hpp> 21 #include <boost/python/operators.hpp> 22 #include <boost/python/tuple.hpp> 31 template<
typename T1,
typename T2>
33 operator<< (std::ostream& os, const std::pair<T1, T2>& pairData)
35 os <<
"{" << pairData.first <<
", " << pairData.second <<
"}";
51 template<
typename T1,
typename T2>
54 static PyObject* convert(
const std::pair<T1, T2>& pair)
56 return boost::python::incref(boost::python::make_tuple(pair.first, pair.second).ptr());
60 template<
typename T1,
typename T2>
63 static void* convertible(PyObject* obj)
65 if (!PyTuple_CheckExact(obj))
return 0;
66 if (PyTuple_Size(obj) != 2)
return 0;
70 static void construct(PyObject* obj, boost::python::converter::rvalue_from_python_stage1_data* data)
72 boost::python::tuple tuple(boost::python::borrowed(obj));
73 void* storage = ((boost::python::converter::rvalue_from_python_storage<std::pair<T1, T2> >*) data)->storage.bytes;
74 new (storage) std::pair<T1, T2>(boost::python::extract<T1>(tuple[0]), boost::python::extract<T2>(tuple[1]));
75 data->convertible = storage;
80 template<
typename PairType>
82 export_pair(
const char* py_name)
84 typedef typename PairType::first_type T1;
85 typedef typename PairType::second_type T2;
86 boost::python::type_info info = boost::python::type_id<PairType>();
87 const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
88 if (reg == 0 || reg->m_to_python == 0) {
90 boost::python::to_python_converter<PairType, PairToPythonConverter<T1, T2> > toPython;
91 boost::python::converter::registry::push_back(
94 boost::python::type_id<PairType>());
104 #endif // __PYIPSDKBASE_PYTHONSTDPAIRUTILS_H__ Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: PythonStdPairUtils.h:61
Definition: PythonStdPairUtils.h:52