|
| 1 | +/// |
| 2 | +/// Copyright 2024 INRIA |
| 3 | +/// |
| 4 | + |
| 5 | +#include <typeinfo> |
| 6 | +#include <typeindex> |
| 7 | + |
| 8 | +#include <boost/python.hpp> |
| 9 | +#include <boost/type_index.hpp> |
| 10 | + |
| 11 | +#include "eigenpy/registration.hpp" |
| 12 | + |
| 13 | +namespace bp = boost::python; |
| 14 | + |
| 15 | +namespace eigenpy { |
| 16 | + |
| 17 | +void exposeStdTypeIndex() { |
| 18 | + typedef std::type_index Self; |
| 19 | + if (register_symbolic_link_to_registered_type<Self>()) return; |
| 20 | + |
| 21 | + bp::class_<Self>( |
| 22 | + "std_type_index", |
| 23 | + "The class type_index holds implementation-specific information about a " |
| 24 | + "type, including the name of the type and means to compare two types for " |
| 25 | + "equality or collating order.", |
| 26 | + bp::no_init) |
| 27 | + .def(bp::self == bp::self) |
| 28 | + .def(bp::self >= bp::self) |
| 29 | + .def(bp::self > bp::self) |
| 30 | + .def(bp::self < bp::self) |
| 31 | + .def(bp::self <= bp::self) |
| 32 | + .def("hash_code", &Self::hash_code, bp::arg("self"), |
| 33 | + "Returns an unspecified value (here denoted by hash code) such that " |
| 34 | + "for all std::type_info objects referring to the same type, their " |
| 35 | + "hash code is the same.") |
| 36 | + .def("name", &Self::name, bp::arg("self"), |
| 37 | + "Returns an implementation defined null-terminated character string " |
| 38 | + "containing the name of the type. No guarantees are given; in " |
| 39 | + "particular, the returned string can be identical for several types " |
| 40 | + "and change between invocations of the same program.") |
| 41 | + .def( |
| 42 | + "pretty_name", |
| 43 | + +[](const Self &value) -> std::string { |
| 44 | + return boost::core::demangle(value.name()); |
| 45 | + }, |
| 46 | + bp::arg("self"), "Human readible name."); |
| 47 | +} |
| 48 | + |
| 49 | +void exposeBoostTypeIndex() { |
| 50 | + typedef boost::typeindex::type_index Self; |
| 51 | + if (register_symbolic_link_to_registered_type<Self>()) return; |
| 52 | + |
| 53 | + bp::class_<Self>( |
| 54 | + "boost_type_index", |
| 55 | + "The class type_index holds implementation-specific information about a " |
| 56 | + "type, including the name of the type and means to compare two types for " |
| 57 | + "equality or collating order.", |
| 58 | + bp::no_init) |
| 59 | + .def(bp::self == bp::self) |
| 60 | + .def(bp::self >= bp::self) |
| 61 | + .def(bp::self > bp::self) |
| 62 | + .def(bp::self < bp::self) |
| 63 | + .def(bp::self <= bp::self) |
| 64 | + .def("hash_code", &Self::hash_code, bp::arg("self"), |
| 65 | + "Returns an unspecified value (here denoted by hash code) such that " |
| 66 | + "for all std::type_info objects referring to the same type, their " |
| 67 | + "hash code is the same.") |
| 68 | + .def("name", &Self::name, bp::arg("self"), |
| 69 | + "Returns an implementation defined null-terminated character string " |
| 70 | + "containing the name of the type. No guarantees are given; in " |
| 71 | + "particular, the returned string can be identical for several types " |
| 72 | + "and change between invocations of the same program.") |
| 73 | + .def("pretty_name", &Self::pretty_name, bp::arg("self"), |
| 74 | + "Human readible name."); |
| 75 | +} |
| 76 | + |
| 77 | +void exposeTypeInfo() { |
| 78 | + exposeStdTypeIndex(); |
| 79 | + exposeBoostTypeIndex(); |
| 80 | +} |
| 81 | +} // namespace eigenpy |
0 commit comments