3 #include <pybind11/smart_holder.h>
4 #include <py_binding_tools/ros_msg_typecasters.h>
5 #include <moveit/task_constructor/properties.h>
6 #include <boost/any.hpp>
18 using to_python_converter_function = pybind11::object (*)(
const boost::any&);
19 using from_python_converter_function = boost::any (*)(
const pybind11::object&);
22 static bool insert(
const std::type_index& type_index,
const std::string& ros_msg_name,
23 to_python_converter_function to, from_python_converter_function from);
31 PropertyConverter() { insert(
typeid(T), rosMsgName<T>(), &toPython, &fromPython); }
34 static pybind11::object toPython(
const boost::any& value) {
return pybind11::cast(boost::any_cast<T>(value)); }
35 static boost::any fromPython(
const pybind11::object& po) {
return pybind11::cast<T>(po); }
37 template <
class Q = T>
38 typename std::enable_if<ros::message_traits::IsMessage<Q>::value, std::string>::type rosMsgName() {
39 return ros::message_traits::DataType<T>::value();
42 template <
class Q = T>
43 typename std::enable_if<!ros::message_traits::IsMessage<Q>::value, std::string>::type rosMsgName() {
48 namespace properties {
55 template <
typename type_,
typename... options>
56 class class_ :
public pybind11::classh<type_, options...>
58 using base_class_ = pybind11::classh<type_, options...>;
62 using base_class_::classh;
64 template <
typename PropertyType,
typename... Extra>
65 class_& property(
const char* name,
const Extra&... extra) {
67 auto getter = [name](type_&
self) -> PropertyType& {
69 return const_cast<PropertyType&
>(props.
get<PropertyType>(name));
71 auto setter = [name](type_&
self,
const PropertyType& value) {
73 props.
set(name, boost::any(value));
75 base_class_::def_property(name, getter, setter, pybind11::return_value_policy::reference_internal, extra...);
Definition: properties.h:16
utility class to register C++ / Python converters for a property of type T
Definition: properties.h:29
Definition: properties.h:257
const boost::any & get(const std::string &name) const
Get the value of a property. Throws undeclared if unknown name.
Definition: properties.cpp:254
void set(const std::string &name, const T &value)
set (and, if neccessary, declare) the value of a property
Definition: properties.h:304
Definition: properties.h:70