8 #ifndef _mp7_python_converters_h_ 9 #define _mp7_python_converters_h_ 16 #include "boost/unordered_map.hpp" 17 #include "boost/python.hpp" 18 #include "boost/python/converter/rvalue_from_python_data.hpp" 27 struct Converter_pair_uint32_bool_from_tuple
33 boost::python::converter::registry::push_back ( &
convertible, &
construct, boost::python::type_id < std::pair<uint32_t, bool > >() );
40 static void construct ( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data*
data );
48 struct Converter_std_vector_from_list
54 boost::python::converter::registry::push_back ( &
convertible, &
construct, boost::python::type_id< std::vector<T> >() );
61 static void construct ( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data*
data );
65 struct Converter_std_vector_to_list
67 static PyObject*
convert (
const std::vector<T>&
v );
70 template <
class U,
class T>
71 struct Converter_std_map_to_dict
73 static PyObject*
convert (
const std::map<U, T>& m );
76 template <
class U,
class T>
77 struct Converter_boost_unorderedmap_to_dict
79 static PyObject*
convert (
const boost::unordered_map<U, T>& m );
82 template<
class T1,
class T2>
83 struct PairToTupleConverter
85 static PyObject*
convert (
const std::pair<T1, T2>& pair );
94 template<
class ExceptionType>
95 class ExceptionTranslator
98 ExceptionTranslator ( PyObject* exception_pyType );
101 void operator() (
const ExceptionType& e )
const;
108 template<
class ExceptionType>
122 template <
class U,
class T>
128 for (
typename std::map<U, T>::const_iterator it = m.begin(); it != m.end(); it++ )
130 theDict[it->first] = bpy::object ( it->second );
133 return bpy::incref ( theDict.ptr() );
139 template <
class U,
class T>
145 for (
typename boost::unordered_map<U, T>::const_iterator it = m.begin(); it != m.end(); it++ )
147 theDict[it->first] = bpy::object ( it->second );
150 return bpy::incref ( theDict.ptr() );
161 if ( !PyList_Check ( obj_ptr ) )
176 void* storage = ( ( bpy::converter::rvalue_from_python_storage< std::vector<T> >* ) data )->storage.bytes;
178 bpy::list py_list ( bpy::handle<> ( bpy::borrowed ( obj_ptr ) ) );
181 size_t nItems = bpy::len ( py_list );
182 std::vector<T>* vec_ptr =
new ( storage ) std::vector<T> ( nItems );
184 for (
size_t i = 0; i < nItems; i++ )
186 vec_ptr->at ( i ) = bpy::extract<T> ( py_list[i] );
190 data->convertible = storage;
203 for (
typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); it++ )
205 theList.append ( bpy::object ( *it ) );
208 return bpy::incref ( theList.ptr() );
215 template<
class T1,
class T2>
219 return bpy::incref ( bpy::make_tuple ( pair.first, pair.second ).ptr() );
227 template <
class ExceptionType>
229 exception_pyType_ ( exception_pyType )
233 template <
class ExceptionType>
237 bpy::object pyException ( bpy::handle<> ( bpy::borrowed (
exception_pyType_ ) ) );
238 pyException.attr (
"what" ) = e.what();
void wrap_exceptions()
Definition: converters_exceptions.cpp:116
PyObject* create_exception_class( const std::string& excName, PyObject* baseTypeObj = PyExc_Exception )
Definition: converters_exceptions.cpp:100
static PyObject* convert( const boost::unordered_map<U, T>& m )
Definition: converters_exceptions.hpp:140
v
Definition: mp7-test-ipbusaccess.py:58
static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data )
Definition: converters_exceptions.hpp:172
static PyObject* convert( const std::vector<T>& v )
Definition: converters_exceptions.hpp:198
void operator()( const ExceptionType& e ) const
Translation function called at the C-python boundary.
Definition: converters_exceptions.hpp:234
static PyObject* convert( const std::map<U, T>& m )
Definition: converters_exceptions.hpp:123
ExceptionTranslator( PyObject* exception_pyType )
Definition: converters_exceptions.hpp:228
void wrap_derived_exception( const std::string& exceptionName, PyObject* base_exception_pyType )
Definition: converters_exceptions.hpp:109
PyObject* exception_pyType_
Pointer to PyObject corresponding to C++ exception class ExceptionType.
Definition: converters_exceptions.hpp:104
void register_converters()
Definition: converters_exceptions.cpp:44
static PyObject* convert( const std::pair<T1, T2>& pair )
Definition: converters_exceptions.hpp:216
static void* convertible( PyObject* obj_ptr )
Definition: converters_exceptions.cpp:16
Definition: converters_exceptions.hpp:20
Converter_std_vector_from_list()
Definition: converters_exceptions.hpp:52
Definition: converters_exceptions.hpp:95
static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data )
Definition: converters_exceptions.cpp:28
dictionary data
Definition: test-datavalid.py:31
Converter_pair_uint32_bool_from_tuple()
Definition: converters_exceptions.hpp:31
static void* convertible( PyObject* obj_ptr )
Definition: converters_exceptions.hpp:159