![]() |
Belle II Software
release-05-02-19
|
Python object converter utilities namespace. More...
Classes | |
| class | convertToPythonObjectVisitor |
| Helper function object to unpack a value from a variant to a python object. More... | |
| struct | SizeT |
| Helper construct for TMP that provides an index at compile time to recurse through type lists. More... | |
| struct | Type |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< bool > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< boost::optional< T > > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< boost::variant< Types... > > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< double > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< float > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< int > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< std::map< A, B > > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< std::set< T > > |
| Convert a templeate arugment into a string for corresponding Python type. More... | |
| struct | Type< std::shared_ptr< Path > > |
| Some modules take a path as argument so let's add this as well. More... | |
| struct | Type< std::string > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< std::tuple< Types... > > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< std::vector< T > > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< unsigned int > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | Type< unsigned long int > |
| Converts a template argument into a string for corresponding Python type. More... | |
| struct | VariadicType |
| Recursively convert multiple types to type names (used for tuples). More... | |
| struct | VariadicType< T > |
| Recursively convert multiple types to type names (used for tuples). More... | |
Functions | |
| bool | checkPythonObject (const boost::python::object &pyObject, bool) |
| check if the python object can be converted to the given type. More... | |
| bool | checkPythonObject (const boost::python::object &pyObject, float) |
| check if the python object can be converted to the given type. More... | |
| bool | checkPythonObject (const boost::python::object &pyObject, double) |
| check if the python object can be converted to the given type. More... | |
| bool | checkPythonObject (const boost::python::object &pyObject, int) |
| check if the python object can be converted to the given an integral number More... | |
| bool | checkPythonObject (const boost::python::object &pyObject, unsigned int) |
| check if the python object can be converted to the given an integral number More... | |
| bool | checkPythonObject (const boost::python::object &pyObject, unsigned long int) |
| check if the python object can be converted to the given an integral number More... | |
| bool | checkPythonObject (const boost::python::object &pyObject, const std::string &) |
| check if the python object can be converted to the given a string More... | |
| template<typename Key , typename Value > | |
| bool | checkPythonObject (const boost::python::object &pyObject, const std::map< Key, Value > &) |
| Check if the python object is a mapping of the correct key and value types. | |
| template<typename Value > | |
| bool | checkPythonObject (const boost::python::object &pyObject, const std::vector< Value > &) |
| check if the python object can be converted to the given std::vector type More... | |
| template<typename Value > | |
| bool | checkPythonObject (const boost::python::object &pyObject, const std::set< Value > &) |
| check if the python object can be converted to the given std::set type | |
| template<typename... Types> | |
| bool | checkPythonObject (const boost::python::object &pyObject, const std::tuple< Types... > &) |
| check if the python object can be converted to the given std::tuple type More... | |
| template<typename... Types> | |
| bool | checkPythonObject (const boost::python::object &pyObject, const boost::variant< Types... > &) |
| check if the python object can be converted to the given boost::variant type | |
| template<typename Type > | |
| bool | checkPythonObject (const boost::python::object &pyObject, const boost::optional< Type > &) |
| check if the python object can be converted to the given boost::optional<T> type More... | |
| template<typename Scalar > | |
| Scalar | convertPythonObject (const boost::python::object &pyObject, Scalar) |
| Convert from Python to given type. More... | |
| template<typename Key , typename Value > | |
| std::map< Key, Value > | convertPythonObject (const boost::python::object &pyObject, const std::map< Key, Value > &) |
| Convert from Python to given type. More... | |
| template<typename Value > | |
| std::vector< Value > | convertPythonObject (const boost::python::object &pyObject, const std::vector< Value > &) |
| Convert from Python to given type. More... | |
| template<typename Value > | |
| std::set< Value > | convertPythonObject (const boost::python::object &pyObject, const std::set< Value > &) |
| Convert from Python to given type. More... | |
| template<typename... Types> | |
| std::tuple< Types... > | convertPythonObject (const boost::python::object &pyObject, const std::tuple< Types... > &) |
| Convert from Python to given type. More... | |
| template<typename... Types> | |
| boost::variant< Types... > | convertPythonObject (const boost::python::object &pyObject, const boost::variant< Types... > &) |
| Convert from Python to given type. More... | |
| template<typename Type > | |
| boost::optional< Type > | convertPythonObject (const boost::python::object &pyObject, const boost::optional< Type > &) |
| Convert from Python to the given boost::optional type. More... | |
| template<typename Scalar > | |
| boost::python::object | convertToPythonObject (const Scalar &value) |
| ------------— From C++ TO Python Converter ---------------------— More... | |
| template<typename Value > | |
| boost::python::list | convertToPythonObject (const std::vector< Value > &vector) |
| Writes content of a std::vector to a python list. More... | |
| template<typename Value > | |
| boost::python::object | convertToPythonObject (const std::set< Value > &set) |
| Convert std::set to a python object. More... | |
| template<typename Key , typename Value > | |
| boost::python::dict | convertToPythonObject (const std::map< Key, Value > &map) |
| Writes content of a std::map to a python dict. More... | |
| template<typename... Types> | |
| boost::python::tuple | convertToPythonObject (const std::tuple< Types... > &tuple) |
| Writes content of a std::tuple to a python tuple. More... | |
| template<typename... Types> | |
| boost::python::object | convertToPythonObject (const boost::variant< Types... > &variant) |
| Writes content of a boost::variant to a python object. More... | |
| template<typename Type > | |
| boost::python::object | convertToPythonObject (const boost::optional< Type > &optional) |
| Convert from the given boost::optional type to Python. More... | |
| template<class Functor > | |
| bool | iteratePythonObject (const boost::python::object &pyObject, Functor function) |
| Helper function to loop over a python object that implements the iterator concept and call a functor with each element as argument. More... | |
| template<typename... Types, std::size_t ... Is> | |
| bool | CheckTuple (const std::tuple< Types... > &tuple, const boost::python::tuple &pyTuple, std::index_sequence< Is... >) |
| Check if all tuple elements match. | |
| template<typename VariantType > | |
| bool | CheckVariant (const VariantType &, const boost::python::object &, SizeT< 0 >) |
| Recursion sentinal for the case that all former type checks failed for the variant. | |
| template<typename... Types, size_t N> | |
| bool | CheckVariant (const boost::variant< Types... > &variant, const boost::python::object &pyObject, SizeT< N >) |
| Recursion through the variant types checking the python object for the type at position N - 1. | |
| template<typename... Types> | |
| bool | checkPythonObject (const boost::python::object &pyObject, const boost::variant< Types... > variant) |
| Check if the python object is a tuple of objects of the correct types. | |
Python object converter utilities namespace.
Provides templates for converting python objects to c++ objects and the other way round.
This is done by using the type of the value provided by the module as a template parameter. Hence the compiler can infer which converter should be used. Note: We are only interested in the type of the value, the actual value isn't used at all!
|
inline |
check if the python object can be converted to the given type.
------------— Check python objects for exact type match ---------------------—
Check if the python object is a boolean
Definition at line 203 of file PyObjConvUtils.h.
| bool checkPythonObject | ( | const boost::python::object & | pyObject, |
| const boost::optional< Type > & | |||
| ) |
check if the python object can be converted to the given boost::optional<T> type
Check if a python object can be converted to boost::optional.
Definition at line 347 of file PyObjConvUtils.h.
|
inline |
check if the python object can be converted to the given a string
Check if the python object is a string.
Definition at line 238 of file PyObjConvUtils.h.
| bool checkPythonObject | ( | const boost::python::object & | pyObject, |
| const std::tuple< Types... > & | tuple | ||
| ) |
check if the python object can be converted to the given std::tuple type
Check if the python object is a tuple of objects of the correct types.
Definition at line 307 of file PyObjConvUtils.h.
| bool checkPythonObject | ( | const boost::python::object & | pyObject, |
| const std::vector< Value > & | |||
| ) |
check if the python object can be converted to the given std::vector type
Check if the python object is a list of objects of the correct value type.
Definition at line 280 of file PyObjConvUtils.h.
|
inline |
check if the python object can be converted to the given type.
Check if the python object is a float number.
Definition at line 232 of file PyObjConvUtils.h.
|
inline |
check if the python object can be converted to the given type.
Check if the python object is a float number.
Definition at line 226 of file PyObjConvUtils.h.
|
inline |
check if the python object can be converted to the given an integral number
Check if the python object is an integral number.
Definition at line 209 of file PyObjConvUtils.h.
|
inline |
check if the python object can be converted to the given an integral number
Check if the python object is an integral number.
Definition at line 214 of file PyObjConvUtils.h.
|
inline |
check if the python object can be converted to the given an integral number
Check if the python object is an integral number.
Definition at line 220 of file PyObjConvUtils.h.
| boost::optional< Type > convertPythonObject | ( | const boost::python::object & | pyObject, |
| const boost::optional< Type > & | |||
| ) |
Convert from Python to the given boost::optional type.
Convert a python object to boost::optional.
Definition at line 691 of file PyObjConvUtils.h.
| boost::variant< Types... > convertPythonObject | ( | const boost::python::object & | pyObject, |
| const boost::variant< Types... > & | |||
| ) |
Convert from Python to given type.
Reads boost::variant from a python object.
| pyObject | Python object which stores the value. |
Definition at line 677 of file PyObjConvUtils.h.
| std::map< Key, Value > convertPythonObject | ( | const boost::python::object & | pyObject, |
| const std::map< Key, Value > & | |||
| ) |
Convert from Python to given type.
Reads std::map from a python object.
| pyObject | Python object which stores the map. |
Definition at line 572 of file PyObjConvUtils.h.
| std::set< Value > convertPythonObject | ( | const boost::python::object & | pyObject, |
| const std::set< Value > & | |||
| ) |
Convert from Python to given type.
Convert a python set to a std::set.
Definition at line 550 of file PyObjConvUtils.h.
| std::tuple< Types... > convertPythonObject | ( | const boost::python::object & | pyObject, |
| const std::tuple< Types... > & | |||
| ) |
Convert from Python to given type.
Reads std::tuple from a python object.
| pyObject | Python object which stores the map. |
Definition at line 628 of file PyObjConvUtils.h.
| std::vector< Value > convertPythonObject | ( | const boost::python::object & | pyObject, |
| const std::vector< Value > & | |||
| ) |
Convert from Python to given type.
Reads std::vector from a python object.
If the python object isn't a list, a std::vector with the given object as single entry is returned.
| pyObject | Python object which stores the vector. |
Definition at line 533 of file PyObjConvUtils.h.
| Scalar convertPythonObject | ( | const boost::python::object & | pyObject, |
| const | Scalar | ||
| ) |
Convert from Python to given type.
------------— From Python TO C++ Converter ---------------------—
Reads a scalar type (int, double, string, bool) from a python object.
| pyObject | Python object which stores the scalar type. |
Definition at line 510 of file PyObjConvUtils.h.
| boost::python::object convertToPythonObject | ( | const boost::optional< Type > & | optional | ) |
Convert from the given boost::optional type to Python.
Convert a boost::optional to python.
| optional | the optional object to convert |
Definition at line 490 of file PyObjConvUtils.h.
| boost::python::object convertToPythonObject | ( | const boost::variant< Types... > & | variant | ) |
Writes content of a boost::variant to a python object.
| variant | The variant whose content should be stored in a python object. |
Definition at line 477 of file PyObjConvUtils.h.
| boost::python::object convertToPythonObject | ( | const Scalar & | value | ) |
------------— From C++ TO Python Converter ---------------------—
Writes a scalar type (int, double, string, bool) to a python object.
| value | The scalar who should be converted to a python object. |
Definition at line 363 of file PyObjConvUtils.h.
| boost::python::dict convertToPythonObject | ( | const std::map< Key, Value > & | map | ) |
Writes content of a std::map to a python dict.
| map | The map whose items should be stored to a python dict. |
Definition at line 405 of file PyObjConvUtils.h.
| boost::python::object convertToPythonObject | ( | const std::set< Value > & | set | ) |
Convert std::set to a python object.
Write the content of a std::set to a python set.
| set | the set that should be converted |
Definition at line 389 of file PyObjConvUtils.h.
| boost::python::tuple convertToPythonObject | ( | const std::tuple< Types... > & | tuple | ) |
Writes content of a std::tuple to a python tuple.
| tuple | The tuple whose items should be stored to a python tuple. |
Definition at line 449 of file PyObjConvUtils.h.
| boost::python::list convertToPythonObject | ( | const std::vector< Value > & | vector | ) |
Writes content of a std::vector to a python list.
| vector | The vector whose items should be stored to a python list. |
Definition at line 375 of file PyObjConvUtils.h.
|
inline |
TMP (Template Meta Programming ) The given python list is filled, and later converted into a python tuple (in convertToPythonObject).
To fill the python list from the C++ std::tuple we need again TMP methods. The variadic template std::tuple is copied by the recursive defined template function GetTuple, the overloaded argument (type SizeT<>) of the function serves as a counter for the recursion depth.
Definition at line 423 of file PyObjConvUtils.h.
| bool Belle2::PyObjConvUtils::iteratePythonObject | ( | const boost::python::object & | pyObject, |
| Functor | function | ||
| ) |
Helper function to loop over a python object that implements the iterator concept and call a functor with each element as argument.
| pyObject | the python object to iterate over @function any functor object which accepts a boost::python::object as its only argument and returns true if the iteration should be continued |
Definition at line 266 of file PyObjConvUtils.h.
|
inline |
TMP (Template Meta Programming ) The given python tuple is written into the given c++ tuple.
To fill the C++ std::tuple we need again TMP methods. The variadic template std::tuple is filled by the recursive defined template function SetTuple, the overloaded argument (type SizeT<>) of the function serves as a counter for the recursion depth.
Definition at line 596 of file PyObjConvUtils.h.
|
inline |
TMP (Template Meta Programming ) The given python object is written into the given c++ boost variant.
To fill the C++ boost::variant we need again TMP methods. The variadic template boost::variant is filled by the recursive defined template function SetVariant, the overloaded argument (type SizeT<>) of the function serves as a counter for the recursion depth.
Definition at line 645 of file PyObjConvUtils.h.