eigenpy 3.12.0
Bindings between Numpy and Eigen using Boost.Python
Loading...
Searching...
No Matches
type_info.hpp
1
4
5#ifndef __eigenpy_type_info_hpp__
6#define __eigenpy_type_info_hpp__
7
8#include "eigenpy/fwd.hpp"
9
10#include <boost/type_index.hpp>
11#include <typeinfo>
12#include <typeindex>
13
14namespace eigenpy {
15
16template <typename T>
17boost::typeindex::type_index type_info(const T& value) {
18 return boost::typeindex::type_id_runtime(value);
19}
20
21template <typename T>
22void expose_boost_type_info() {
23 boost::python::def(
24 "type_info",
25 +[](const T& value) -> boost::typeindex::type_index {
26 return boost::typeindex::type_id_runtime(value);
27 },
28 bp::arg("value"),
29 "Returns information of the type of value as a "
30 "boost::typeindex::type_index (can work without RTTI).");
31 boost::python::def(
32 "boost_type_info",
33 +[](const T& value) -> boost::typeindex::type_index {
34 return boost::typeindex::type_id_runtime(value);
35 },
36 bp::arg("value"),
37 "Returns information of the type of value as a "
38 "boost::typeindex::type_index (can work without RTTI).");
39}
40
41template <typename T>
42void expose_std_type_info() {
43 boost::python::def(
44 "std_type_info",
45 +[](const T& value) -> std::type_index { return typeid(value); },
46 bp::arg("value"),
47 "Returns information of the type of value as a std::type_index.");
48}
49
53template <class C>
54struct TypeInfoVisitor : public bp::def_visitor<TypeInfoVisitor<C>> {
55 template <class PyClass>
56 void visit(PyClass& cl) const {
57 cl.def("type_info", &boost_type_info, bp::arg("self"),
58 "Queries information of the type of *this as a "
59 "boost::typeindex::type_index (can work without RTTI).");
60 cl.def("boost_type_info", &boost_type_info, bp::arg("self"),
61 "Queries information of the type of *this as a "
62 "boost::typeindex::type_index (can work without RTTI).");
63 cl.def("std_type_info", &std_type_info, bp::arg("self"),
64 "Queries information of the type of *this as a std::type_index.");
65 }
66
67 private:
68 static boost::typeindex::type_index boost_type_info(const C& self) {
69 return boost::typeindex::type_id_runtime(self);
70 }
71
72 static std::type_index std_type_info(const C& self) { return typeid(self); }
73};
74
75} // namespace eigenpy
76
77#endif // __eigenpy_type_info_hpp__
Add the Python method type_info to query information of a type.
Definition type_info.hpp:54