35#include <Ice/ProxyHandle.h>
72 template <
typename PropertyType>
76 const std::string& name,
83 template <
typename PropertyType>
87 const std::string& name,
94 template <
typename PropertyType>
97 const PropertyType& getter,
98 std::function<
void(
const PropertyType&)> setter,
99 const std::string& name,
106 template <
typename PropertyType>
108 PropertyType& setter,
109 const std::string& name,
114 template <
typename PropertyType>
116 const PropertyType& getter,
117 std::function<
void(
const PropertyType&)> setter,
118 const std::string& name,
124 template <
typename PropertyType>
126 const std::string& default_name =
"",
127 const std::string& property_name =
"",
137 template <
typename PropertyType>
139 const std::string& default_name =
"",
140 const std::string& property_name =
"",
149 template <
typename PropertyType>
150 void topic(std::string default_name =
"",
151 std::string property_name =
"",
154 template <
typename PropertyType>
161 template <
typename PropertyType>
164 PropertyType defaultValue,
196 template <
typename EigenVectorType>
200 const std::string& delimiter =
" ",
205 template <
typename EigenVectorType>
213 name,
description, std::string(1, delimiter), constness);
216 template <
typename EigenVectorType>
257 template <
typename EigenVectorType>
260 EigenVectorType defaultValue,
262 const std::string& delimiter =
" ",
267 template <
typename EigenVectorType>
270 EigenVectorType defaultValue,
276 name, defaultValue,
description, std::string(1, delimiter), constness);
279 template <
typename EigenVectorType>
282 EigenVectorType defaultValue,
292 template <
typename PropertyType>
323 std::string
getValue(
const std::string& name);
332 template <
typename EigenVectorType>
334 template <
typename EigenVectorType>
342 template <
typename PropertyType>
343 std::string ice_class_name();
345 template <
typename PropertyType>
348 std::string default_name,
349 std::string property_name,
359 std::map<std::string, ProxyPropertyDefinitionBase*>
proxies;
393 template <
typename PropertyType>
395 PropertyDefinitionContainer::ice_class_name()
397 const std::string full_type_name = PropertyType::ice_staticId();
401 template <
typename PropertyType>
402 inline decltype(
auto)
405 PropertyType& setter,
406 const std::string& name,
411 if constexpr (plugin::value)
413 plugin::Define(*
this, isRequired, setter, name,
description, constness);
428 def->setTypeIdName(
typeid(PropertyType).name());
434 template <
typename PropertyType>
435 inline decltype(
auto)
438 const PropertyType& getter,
439 std::function<
void(
const PropertyType&)> setter,
440 const std::string& name,
445 if constexpr (plugin::value)
447 plugin::Define(*
this, isRequired, getter, setter, name,
description, constness);
455 def->setTypeIdName(
typeid(PropertyType).name());
461 template <
typename PropertyType>
464 const std::string& default_name,
465 const std::string& property_name,
471 template <
typename PropertyType>
474 const std::string& default_name,
475 const std::string& property_name,
481 template <
typename PropertyType>
484 std::string property_name,
487 const std::string class_name = ice_class_name<PropertyType>();
489 if (default_name.empty())
491 default_name = class_name;
493 if (property_name.empty())
495 property_name =
"tpc.sub." + class_name;
499 description =
"Name of the `" + class_name +
"` topic to subscribe to.";
505 def_name->setTypeIdName(
typeid(std::string).name());
510 template <
typename PropertyType>
514 std::string default_name,
515 std::string property_name,
516 std::string description)
520 const std::string class_name = ice_class_name<PropertyType>();
522 if (default_name.empty())
524 default_name = class_name;
526 if (property_name.empty())
531 property_name =
"cmp." + class_name;
534 property_name =
"tpc.pub." + class_name;
543 description =
"Ice object name of the `" + class_name +
"` component.";
546 description =
"Name of the `" + class_name +
"` topic to publish data to.";
552 PropertyDefinition<std::string>* def_name =
new PropertyDefinition<std::string>(
554 def_name->setTypeIdName(
typeid(std::string).name());
555 definitions[property_name] =
static_cast<PropertyDefinitionBase*
>(def_name);
558 ProxyPropertyDefinition<PropertyTypePrx>* def =
559 new ProxyPropertyDefinition<PropertyTypePrx>(&setter, proxy_type);
560 proxies[property_name] =
static_cast<ProxyPropertyDefinitionBase*
>(def);
563 template <
typename PropertyType>
566 const std::string& name,
573 def->setTypeIdName(
typeid(PropertyType).name());
580 template <
typename PropertyType>
583 const std::string& name,
584 PropertyType defaultValue,
589 nullptr, name, defaultValue,
description, constness);
591 def->setTypeIdName(
typeid(PropertyType).name());
598 template <
typename EigenVectorType>
601 const std::string& name,
603 const std::string& delimiter,
607 description, EigenVectorType::SizeAtCompileTime, delimiter);
613 def.
setFactory([delimiter](std::string
string) -> EigenVectorType
620 template <
typename EigenVectorType>
623 const std::string& name,
624 EigenVectorType defaultValue,
626 const std::string& delimiter,
630 description, EigenVectorType::SizeAtCompileTime, delimiter);
633 name, defaultValue, appendedDescription, constness);
636 def.
setFactory([delimiter](std::string
string) -> EigenVectorType
645 template <
typename PropertyType>
652 std::stringstream ss;
653 ss << name +
" property is not defined. Defined are ";
654 for (
typename DefinitionContainer::iterator it =
definitions.begin();
658 ss <<
"\n" << it->first;
660 throw armarx::LocalException(ss.str());
666 if (def->getTypeIdName().compare(
typeid(PropertyType).name()) != 0)
668 throw armarx::LocalException(
669 std::string(
"Calling getProperty<T>() for the property '") + name +
670 "' with wrong property type [note: " +
typeid(PropertyType).name() +
671 " instead of " + def->getTypeIdName() +
"]");
678 template <
typename EigenVectorType>
682 using Scalar =
typename EigenVectorType::Scalar;
684 long size = EigenVectorType::SizeAtCompileTime;
685 bool isFixedSize = size >= 0;
687 const std::vector<std::string> stringScalars =
split(
string, delim,
true);
689 std::vector<Scalar> scalars;
692 if (stringScalars.size() !=
static_cast<std::size_t
>(size))
694 throw std::bad_cast();
696 scalars.reserve(size);
698 for (
const auto& scalarStr : stringScalars)
702 scalars.push_back(value);
705 EigenVectorType vector;
708 vector.resize(scalars.size());
711 for (std::size_t i = 0; i < scalars.size(); ++i)
713 vector(i) = scalars[i];
718 template <
typename EigenVectorType>
723 std::stringstream ss;
724 long size = vector.size();
727 for (
int i = 1; i < size; ++i)
729 ss << delim << vector(i);
Common interface of any property definition.
PropertyDefinition< EigenVectorType > & defineOptionalPropertyVector(const std::string &name, EigenVectorType defaultValue, const std::string &description="", const std::string &delimiter=" ", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Define a required property for an Eigen vector type.
PropertyDefinition< EigenVectorType > & defineRequiredPropertyVector(const std::string &name, const std::string &description="", const std::string &delimiter=" ", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Define a required property for an Eigen vector type.
void component(IceInternal::ProxyHandle< PropertyType > &setter, const std::string &default_name="", const std::string &property_name="", const std::string &description="")
static std::string eigenVectorToString(const EigenVectorType &vector, std::string delim)
PropertyDefinitionContainer(const std::string &prefix)
std::string description
Property User description.
bool isPropertySet(const std::string &name)
void setDescription(const std::string &description)
Sets the detailed description of the property user.
PropertyDefinition< PropertyType > & getDefintion(const std::string &name)
std::map< std::string, PropertyDefinitionBase * > DefinitionContainer
static std::string eigenVectorPropertyDescription(const std::string &description, long size, std::string delim)
std::map< std::string, ProxyPropertyDefinitionBase * > proxies
std::vector< std::string > getSubscribedTopicDefinitions()
~PropertyDefinitionContainer() override
decltype(auto) optional(const PropertyType &getter, std::function< void(const PropertyType &)> setter, const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
std::vector< std::string > subscribedTopics
DefinitionContainer definitions
Property definitions container.
Ice::PropertiesPtr properties
void writeProxyValues(IceManagerPtr)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
void setProperties(Ice::PropertiesPtr properties)
decltype(auto) optional(PropertyType &setter, const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
decltype(auto) requiredOrOptional(bool isRequired, PropertyType &setter, const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
void topic(IceInternal::ProxyHandle< PropertyType > &setter, const std::string &default_name="", const std::string &property_name="", const std::string &description="")
Define a property to set the name of a topic which is subscribed to.
PropertyDefinition< EigenVectorType > & defineOptionalPropertyVector(const std::string &name, EigenVectorType defaultValue, const std::string &description, char delimiter, PropertyDefinitionBase::PropertyConstness constness)
static EigenVectorType eigenVectorFactoryFunction(std::string string, std::string delim)
Parses string to an Eigen vector of type EigenVectorType.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
std::map< std::string, std::string > getPropertyValues(const std::string &prefix="") const
PropertyDefinition< EigenVectorType > & defineOptionalPropertyVector(const std::string &name, EigenVectorType defaultValue, const std::string &description, char delimiter)
PropertyDefinition< PropertyType > & defineRequiredProperty(const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
void setPrefix(std::string prefix)
bool hasDefinition(const std::string &name) const
PropertyDefinitionBase * getDefinitionBase(const std::string &name)
std::string getValue(const std::string &name)
PropertyDefinition< EigenVectorType > & defineRequiredPropertyVector(const std::string &name, const std::string &description, char delimiter)
Ice::PropertiesPtr getProperties()
decltype(auto) required(PropertyType &setter, const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
std::string toString(PropertyDefinitionFormatter &formatter)
std::map< std::string, ProxyPropertyDefinitionBase * > getProxyDefinitions()
std::string briefDescription
PropertyUser brief description.
std::string getDescription() const
Returns the detailed description of the property user.
PropertyDefinition< EigenVectorType > & defineRequiredPropertyVector(const std::string &name, const std::string &description, char delimiter, PropertyDefinitionBase::PropertyConstness constness)
PropertyDefinition defines a property that will be available within the PropertyUser.
PropertyDefinition< PropertyType > & setCaseInsensitive(bool isCaseInsensitive)
Sets whether the property value matching is case insensitive.
PropertyDefinition< PropertyType > & map(const std::string &valueString, PropertyType value)
Maps a string value onto a value of the specified template type.
PropertyDefinition< PropertyType > & setFactory(const PropertyFactoryFunction &func)
Sets the factory function that creates the specified template type from the actual string value.
::IceInternal::Handle<::Ice::Properties > PropertiesPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
T PropertyDefinition_lexicalCastTo(std::string const &input)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceUtil::Handle< IceManager > IceManagerPtr
IceManager smart pointer.
std::string PropertyDefinitionContainer_ice_class_name(std::string const &full_type_name)