29 #ifndef CPP_INTROSPECTION_ACCESSOR_H 30 #define CPP_INTROSPECTION_ACCESSOR_H 36 #include <boost/type_traits.hpp> 37 #include <boost/utility/enable_if.hpp> 38 #include <boost/mpl/if.hpp> 61 fields_.reserve(message.
size());
63 FieldPtr access = (*field)->access(*
this);
64 fields_.push_back(access);
65 fields_by_name_[access->getName()] = access;
83 FieldWPtr field(
const std::string& name)
const {
return fields_by_name_.at(name); }
93 template <
typename FieldType>
98 typedef typename boost::mpl::if_<boost::is_const<T>,
const typename FieldType::field_type,
typename FieldType::field_type>
::type field_type;
99 typedef typename boost::mpl::if_<boost::is_const<T>,
const typename FieldType::value_type,
typename FieldType::value_type>
::type value_type;
102 FieldAccess(
const FieldType& field,
const Accessor& accessor) : FieldType(field), accessor_(accessor), expanded_(size()) {}
107 using FieldType::reference;
118 boost::any
get(std::size_t i)
const {
return boost::any(reference(i)); }
119 void setAny(
const boost::any& value, std::size_t i)
const { reference(i) = boost::any_cast<
typename FieldType::value_type>(value); }
122 if (i >= expanded_.size()) expanded_.resize(size());
123 if (i >= expanded_.size())
return MessagePtr();
124 if (expanded_[i])
return expanded_[i];
128 ROS_WARN_NAMED(
"cpp_introspection",
"failed to expand field %s of type %s (unknown type)", FieldType::getName(), FieldType::getDataType());
131 expanded_[i] = message->introspect(&reference(i));
143 struct null_deleter {
void operator()(
void const *)
const { } };
146 template <
typename T>
152 template <
typename T>
160 template <
typename T>
166 template <
typename T>
176 #endif // CPP_INTROSPECTION_ACCESSOR_H void resize(std::size_t new_size) const
boost::mpl::if_< boost::is_const< T >, const typename FieldType::value_type, typename FieldType::value_type >::type value_type
std::vector< MessagePtr > V_Message
std::vector< FieldPtr > V_Field
virtual const char * getName() const =0
VoidPtr deserialize(ros::serialization::IStream &stream, const VoidPtr &) const
boost::weak_ptr< Field const > FieldWPtr
std::map< std::string, FieldWPtr > M_Field
#define ROS_WARN_NAMED(name,...)
static std::size_t value()
virtual std::size_t serializationLength(const VoidConstPtr &instance=VoidConstPtr()) const =0
virtual PackagePtr package() const =0
virtual MessagePtr introspect() const
const char * getPackageName() const
field_type & reference() const
const V_Field & fields() const
boost::is_const< T >::type is_const
const_iterator end() const
const Accessor & accessor_
ros::SerializedMessage serialize(const VoidConstPtr &) const
FieldAccess(const FieldType &field, const Accessor &accessor)
std::size_t serializationLength(const VoidConstPtr &) const
boost::shared_ptr< void > VoidPtr
TypePtr type(const std::string &name)
MessagePtr messageByTypeId(const std::type_info &type_info)
boost::remove_const< T >::type MessageType
MessagePtr introspect(T &instance)
V_Field::const_iterator const_iterator
boost::shared_ptr< T > instance_
static void resize(T &x, size_t new_size, const T &initial=T())
boost::shared_ptr< Field const > FieldPtr
virtual void serialize(ros::serialization::OStream &stream, const VoidConstPtr &instance=VoidConstPtr()) const =0
boost::shared_ptr< void const > VoidConstPtr
const_iterator begin() const
const char * getName() const
Accessor(const Message &message, const boost::shared_ptr< T > &instance)
static std::size_t capacity()
void setAny(const boost::any &value, std::size_t i) const
void serialize(ros::serialization::OStream &stream, const VoidConstPtr &) const
FieldWPtr field(const std::string &name) const
static FieldPtr access(const FieldType &field, AccessorBase &accessor)
virtual const V_FieldName & getFieldNames() const =0
std::size_t capacity() const
MessagePtr expand(std::size_t i) const
boost::mpl::if_< boost::is_const< T >, const typename FieldType::field_type, typename FieldType::field_type >::type field_type
const V_FieldName & getFieldNames() const
VoidConstPtr getConstInstance() const
boost::shared_ptr< Message const > MessagePtr
virtual const char * getPackageName() const =0
virtual VoidPtr deserialize(ros::serialization::IStream &stream, const VoidPtr &instance=VoidPtr()) const =0
PackagePtr package() const
value_type & reference(std::size_t i) const
VoidPtr getInstance() const
std::vector< const char * > V_FieldName
const Accessor & accessor() const