35 #include <Ice/Proxy.h>
36 #include <Ice/ProxyHandle.h>
45 class PropertyDefinitionBase;
57 typedef std::map<std::string, PropertyDefinitionBase*>
73 template <
typename PropertyType>
76 const
std::
string& name,
83 template <
typename PropertyType>
86 const
std::
string& name,
93 template <
typename PropertyType>
97 const
std::
string& name,
102 template <typename PropertyType>
106 const
std::
string& default_name = "",
107 const
std::
string& property_name = "",
117 template <typename PropertyType>
121 const
std::
string& default_name = "",
122 const
std::
string& property_name = "",
131 template <typename PropertyType>
134 std::
string default_name = "",
135 std::
string property_name = "",
138 template <typename PropertyType>
140 const
std::
string& name,
144 template <typename PropertyType>
146 const
std::
string& name,
147 PropertyType defaultValue,
178 template <typename EigenVectorType>
180 const
std::
string& name,
182 const
std::
string& delimiter = " ",
186 template <typename EigenVectorType>
191 return defineRequiredPropertyVector<EigenVectorType>(name,
description, std::string(1, delimiter), constness);
193 template <
typename EigenVectorType>
195 const std::string& name,
const std::string&
description,
char delimiter)
231 template <
typename EigenVectorType>
233 const std::string& name,
234 EigenVectorType defaultValue,
236 const std::string& delimiter =
" ",
240 template <
typename EigenVectorType>
242 const std::string& name, EigenVectorType defaultValue,
const std::string&
description,
char delimiter,
245 return defineOptionalPropertyVector<EigenVectorType>(name, defaultValue,
description, std::string(1, delimiter), constness);
247 template <
typename EigenVectorType>
249 const std::string& name, EigenVectorType defaultValue,
const std::string&
description,
char delimiter)
257 template <
typename PropertyType>
286 std::string
getValue(
const std::string& name);
295 template <
typename EigenVectorType>
297 template <
typename EigenVectorType>
301 const std::string&
description,
long size, std::string delim);
305 template <
typename PropertyType>
309 template <
typename PropertyType>
314 std::string default_name,
315 std::string property_name,
325 std::map<std::string, ProxyPropertyDefinitionBase*>
proxies;
361 template <
typename PropertyType>
363 PropertyDefinitionContainer::ice_class_name()
365 const std::string full_type_name = PropertyType::ice_staticId();
369 template <
typename PropertyType>
370 inline decltype(
auto)
371 PropertyDefinitionContainer::requiredOrOptional(
373 PropertyType& setter,
374 const
std::
string& name,
375 const
std::
string& description,
376 PropertyDefinitionBase::PropertyConstness constness)
378 using plugin = meta::properties::DefinePropertyPlugin<PropertyType>;
381 plugin::Define(*
this, isRequired, setter, name, description, constness);
385 PropertyDefinition<PropertyType>* def;
388 def =
new PropertyDefinition<PropertyType>(&setter, name, description, constness);
392 def =
new PropertyDefinition<PropertyType>(&setter, name, setter, description, constness);
395 def->setTypeIdName(
typeid(PropertyType).name());
396 definitions[name] =
static_cast<PropertyDefinitionBase*
>(def);
402 template <
typename PropertyType>
406 const std::string& default_name,
407 const std::string& property_name,
408 const std::string& description)
414 template <
typename PropertyType>
418 const std::string& default_name,
419 const std::string& property_name,
420 const std::string& description)
426 template <
typename PropertyType>
429 std::string default_name,
430 std::string property_name,
431 std::string description)
433 const std::string class_name = ice_class_name<PropertyType>();
435 if (default_name.empty())
437 default_name = class_name;
439 if (property_name.empty())
441 property_name =
"tpc.sub." + class_name;
445 description =
"Name of the `" + class_name +
"` topic to subscribe to.";
452 def_name->setTypeIdName(
typeid(std::string).name());
458 template <
typename PropertyType>
460 PropertyDefinitionContainer::proxy(
463 std::string default_name,
464 std::string property_name,
465 std::string description)
469 const std::string class_name = ice_class_name<PropertyType>();
471 if (default_name.empty())
473 default_name = class_name;
475 if (property_name.empty())
480 property_name =
"cmp." + class_name;
483 property_name =
"tpc.pub." + class_name;
492 description =
"Ice object name of the `" + class_name +
"` component.";
495 description =
"Name of the `" + class_name +
"` topic to publish data to.";
501 PropertyDefinition<std::string>* def_name =
502 new PropertyDefinition<std::string>(
nullptr, property_name, default_name,
description,
504 def_name->setTypeIdName(
typeid(std::string).name());
505 definitions[property_name] =
static_cast<PropertyDefinitionBase*
>(def_name);
508 ProxyPropertyDefinition<PropertyTypePrx>* def =
509 new ProxyPropertyDefinition<PropertyTypePrx>(&setter, proxy_type);
510 proxies[property_name] =
static_cast<ProxyPropertyDefinitionBase*
>(def);
514 template <
typename PropertyType>
515 PropertyDefinition<PropertyType>&
517 const std::string& description,
523 def->setTypeIdName(
typeid(PropertyType).name());
531 template <
typename PropertyType>
534 const std::string& name,
535 PropertyType defaultValue,
536 const std::string& description,
545 def->setTypeIdName(
typeid(PropertyType).name());
553 template <
typename EigenVectorType>
556 const std::string& name,
557 const std::string& description,
558 const std::string& delimiter,
561 std::string appendedDescription =
566 name, appendedDescription, constness);
569 def.
setFactory([delimiter](std::string
string) -> EigenVectorType
571 return eigenVectorFactoryFunction<EigenVectorType>(
string, delimiter);
579 template<
typename EigenVectorType>
582 const std::string& name,
583 EigenVectorType defaultValue,
584 const std::string& description,
585 const std::string& delimiter,
588 std::string appendedDescription =
593 name, defaultValue, appendedDescription, constness);
596 def.
setFactory([delimiter](std::string
string) -> EigenVectorType
598 return eigenVectorFactoryFunction<EigenVectorType>(
string, delimiter);
601 def.
map(eigenVectorToString<EigenVectorType>(defaultValue, delimiter), defaultValue);
608 template <
typename PropertyType>
615 std::stringstream ss;
616 ss << name +
" property is not defined. Defined are ";
619 ss <<
"\n" << it->first;
621 throw armarx::LocalException(ss.str());
627 if (def->getTypeIdName().compare(
typeid(PropertyType).name()) != 0)
629 throw armarx::LocalException(
630 std::string(
"Calling getProperty<T>() for the property '")
632 +
"' with wrong property type [note: "
633 +
typeid(PropertyType).name()
635 + def->getTypeIdName()
644 template<
typename EigenVectorType>
646 std::string
string, std::string delim)
650 long size = EigenVectorType::SizeAtCompileTime;
651 bool isFixedSize = size >= 0;
653 const std::vector<std::string> stringScalars =
split(
string, delim,
true);
655 std::vector<Scalar> scalars;
658 if (stringScalars.size() !=
static_cast<std::size_t
>(size))
660 throw std::bad_cast();
662 scalars.reserve(size);
664 for (
const auto& scalarStr : stringScalars)
667 Scalar value = PropertyDefinition_lexicalCastTo<Scalar>(scalarStr);
668 scalars.push_back(
value);
671 EigenVectorType vector;
674 vector.resize(scalars.size());
677 for (std::size_t i = 0; i < scalars.size(); ++i)
679 vector(i) = scalars[i];
685 template<
typename EigenVectorType>
687 const EigenVectorType& vector, std::string delim)
689 std::stringstream ss;
690 long size = vector.size();
693 for (
int i = 1; i < size; ++i)
695 ss << delim << vector(i);