Go to the documentation of this file.
41 #include <boost/any.hpp>
51 namespace task_constructor {
57 boost::any
fromName(
const PropertyMap& other,
const std::string& other_name);
75 const boost::any& default_value);
78 using type_info = boost::typeindex::type_info;
115 static boost::any
deserialize(
const std::string& type_name,
const std::string& wire);
152 explicit error(
const std::string& msg);
155 const char*
what() const noexcept
override {
return msg_.c_str(); }
160 explicit undeclared(
const std::string&
name,
const std::string& msg =
"undeclared");
165 explicit undefined(
const std::string&
name,
const std::string& msg =
"undefined");
167 class Property::type_error :
public Property::error
170 explicit type_error(
const std::string& current_type,
const std::string& declared_type);
175 template <
typename T,
typename = std::ostream&>
179 template <
typename T>
180 struct hasSerialize<T, decltype(
std::declval<std::ostream&>() << std::declval<T>())> : std::true_type
183 template <
typename T,
typename = std::istream&>
187 template <
typename T>
188 struct hasDeserialize<T, decltype(
std::declval<std::istream&>() >> std::declval<T&>())> : std::true_type
191 class PropertySerializerBase
197 static std::string
dummySerialize(
const boost::any& ) {
return ""; }
206 template <
typename T>
212 template <
class Q = T>
213 static typename std::enable_if<ros::message_traits::IsMessage<Q>::value, std::string>::type
typeName() {
217 template <
class Q = T>
218 static typename std::enable_if<!ros::message_traits::IsMessage<Q>::value, std::string>::type
typeName() {
224 template <
class Q = T>
225 static typename std::enable_if<hasSerialize<Q>::value, std::string>::type
serialize(
const boost::any& value) {
226 std::ostringstream oss;
227 oss << boost::any_cast<T>(value);
230 template <
class Q = T>
233 std::istringstream iss(wired);
240 template <
class Q = T>
241 static typename std::enable_if<!hasSerialize<Q>::value, std::string>::type
serialize(
const boost::any& value) {
244 template <
class Q = T>
262 const boost::any& default_value);
266 template <
typename T>
267 Property&
declare(
const std::string& name,
const std::string& description =
"") {
269 return declare(name,
typeid(T), description, boost::any());
272 template <
typename T>
273 Property&
declare(
const std::string& name,
const T& default_value,
const std::string& description =
"") {
275 return declare(name,
typeid(T), description, default_value);
291 using iterator = std::map<std::string, Property>::iterator;
292 using const_iterator = std::map<std::string, Property>::const_iterator;
303 template <
typename T>
304 void set(
const std::string& name,
const T& value) {
307 declare<T>(name, value,
"");
309 it->second.setValue(value);
313 inline void set(
const std::string& name,
const char* value) { set<std::string>(
name,
value); }
316 void setCurrent(
const std::string& name,
const boost::any& value);
319 const boost::any&
get(
const std::string& name)
const;
322 template <
typename T>
323 const T&
get(
const std::string& name)
const {
327 return boost::any_cast<const T&>(
value);
330 template <
typename T>
331 const T&
get(
const std::string& name,
const T& fallback)
const {
333 return (
value.empty()) ? fallback : boost::any_cast<const T&>(
value);
348 void PropertyMap::set<boost::any>(
const std::string& name,
const boost::any& value);
std::function< boost::any(const PropertyMap &)> InitializerFunction
function callback used to initialize property value from another PropertyMap
Property()
Construct a property holding a any value.
bool hasProperty(const std::string &name) const
check whether given property is declared
const char * what() const noexcept override
undeclared(const std::string &name, const std::string &msg="undeclared")
void performInitFrom(Property::SourceFlags source, const PropertyMap &other)
perform initialization of still undefined properties using configured initializers
std::map< std::string, Property >::const_iterator const_iterator
void setName(const std::string &name)
boost::typeindex::type_info type_info
undefined(const std::string &name, const std::string &msg="undefined")
type_error(const std::string ¤t_type, const std::string &declared_type)
static std::string dummySerialize(const boost::any &)
const std::string & name() const
static boost::any deserialize(const std::string &type_name, const std::string &wire)
boost::any(*)(const std::string &) DeserializeFunction
void configureInitFrom(Property::SourceFlags source, const std::set< std::string > &properties={})
allow initialization from given source for listed properties - always using the same name
void setCurrentValue(const boost::any &value)
static std::enable_if< hasSerialize< Q >::value &&hasDeserialize< Q >::value, boost::any >::type deserialize(const std::string &wired)
Property & declare(const std::string &name, const Property::type_info &type_info, const std::string &description, const boost::any &default_value)
implementation of declare methods
size_t countDefined(const std::vector< std::string > &list) const
count number of defined properties from given list
void set(const std::string &name, const T &value)
set (and, if neccessary, declare) the value of a property
error(const std::string &msg)
static boost::any dummyDeserialize(const std::string &)
std::string serialize() const
const type_info & type_info_
std::string(*)(const boost::any &) SerializeFunction
utility class to register serializer/deserializer functions for a property of type T
static const char * value()
std::map< std::string, Property > props_
const boost::any & get(const std::string &name) const
Get the value of a property. Throws undeclared if unknown name.
static std::enable_if< ros::message_traits::IsMessage< Q >::value, std::string >::type typeName()
SourceFlags initialized_from_
InitializerFunction initializer_
void reset()
reset to default value (which can be empty)
const boost::any & defaultValue() const
get default value
void setValue(const boost::any &value)
set current value and default value
const boost::any & value() const
get current value (or default if not defined)
void reset()
reset all properties to their defaults
static std::enable_if< hasSerialize< Q >::value, std::string >::type serialize(const boost::any &value)
bool defined() const
the current value defined or will the fallback be used?
std::string typeName() const
const std::string & description() const
get description text
void setDefaultValue(const boost::any &value)
SourceFlags source_flags_
used for external initialization
Property & configureInitFrom(SourceFlags source, const InitializerFunction &f)
configure initialization from source using an arbitrary function
void setDescription(const std::string &desc)
void exposeTo(PropertyMap &other, const std::set< std::string > &properties) const
declare all given properties also in other PropertyMap
std::string property_name_
void setCurrent(const std::string &name, const boost::any &value)
temporarily set the value of a property
boost::any fromName(const PropertyMap &other, const std::string &other_name)
initializer function, using given name from the passed property map
Property & property(const std::string &name)
get the property with given name, throws Property::undeclared for unknown name
std::map< std::string, Property >::iterator iterator
bool initsFrom(SourceFlags source) const
return true, if property initialized from given SourceId
static bool insert(const std::type_index &type_index, const std::string &type_name, SerializeFunction serialize, DeserializeFunction deserialize)
core
Author(s):
autogenerated on Sat May 3 2025 02:40:11