33 #include <Ice/Proxy.h>
34 #include <Ice/ProxyHandle.h>
45 class PropertyDefinitionBase;
71 template <
typename PropertyType>
75 const
std::
string& name,
82 template <
typename PropertyType>
86 const
std::
string& name,
93 template <
typename PropertyType>
96 const
std::
string& name,
102 template <typename PropertyType>
104 const
std::
string& default_name = "",
105 const
std::
string& property_name = "",
115 template <typename PropertyType>
117 const
std::
string& default_name = "",
118 const
std::
string& property_name = "",
127 template <typename PropertyType>
128 void topic(
std::
string default_name = "",
129 std::
string property_name = "",
132 template <typename PropertyType>
139 template <typename PropertyType>
142 PropertyType defaultValue,
174 template <typename EigenVectorType>
178 const
std::
string& delimiter = " ",
183 template <typename EigenVectorType>
190 return defineRequiredPropertyVector<EigenVectorType>(
191 name,
description, std::string(1, delimiter), constness);
194 template <
typename EigenVectorType>
200 return defineRequiredPropertyVector<EigenVectorType>(
235 template <
typename EigenVectorType>
238 EigenVectorType defaultValue,
240 const std::string& delimiter =
" ",
245 template <
typename EigenVectorType>
248 EigenVectorType defaultValue,
253 return defineOptionalPropertyVector<EigenVectorType>(
254 name, defaultValue,
description, std::string(1, delimiter), constness);
257 template <
typename EigenVectorType>
260 EigenVectorType defaultValue,
264 return defineOptionalPropertyVector<EigenVectorType>(
270 template <
typename PropertyType>
301 std::string
getValue(
const std::string& name);
310 template <
typename EigenVectorType>
312 template <
typename EigenVectorType>
320 template <
typename PropertyType>
321 std::string ice_class_name();
323 template <
typename PropertyType>
326 std::string default_name,
327 std::string property_name,
337 std::map<std::string, ProxyPropertyDefinitionBase*>
proxies;
371 template <
typename PropertyType>
373 PropertyDefinitionContainer::ice_class_name()
375 const std::string full_type_name = PropertyType::ice_staticId();
379 template <
typename PropertyType>
380 inline decltype(
auto)
381 PropertyDefinitionContainer::requiredOrOptional(
383 PropertyType& setter,
384 const
std::
string& name,
385 const
std::
string& description,
386 PropertyDefinitionBase::PropertyConstness constness)
388 using plugin = meta::properties::DefinePropertyPlugin<PropertyType>;
391 plugin::Define(*
this, isRequired, setter, name, description, constness);
395 PropertyDefinition<PropertyType>* def;
398 def =
new PropertyDefinition<PropertyType>(&setter, name, description, constness);
402 def =
new PropertyDefinition<PropertyType>(
403 &setter, name, setter, description, constness);
406 def->setTypeIdName(
typeid(PropertyType).name());
407 definitions[name] =
static_cast<PropertyDefinitionBase*
>(def);
412 template <
typename PropertyType>
415 const std::string& default_name,
416 const std::string& property_name,
417 const std::string& description)
422 template <
typename PropertyType>
425 const std::string& default_name,
426 const std::string& property_name,
427 const std::string& description)
432 template <
typename PropertyType>
435 std::string property_name,
436 std::string description)
438 const std::string class_name = ice_class_name<PropertyType>();
440 if (default_name.empty())
442 default_name = class_name;
444 if (property_name.empty())
446 property_name =
"tpc.sub." + class_name;
450 description =
"Name of the `" + class_name +
"` topic to subscribe to.";
456 def_name->setTypeIdName(
typeid(std::string).name());
461 template <
typename PropertyType>
465 std::string default_name,
466 std::string property_name,
467 std::string description)
471 const std::string class_name = ice_class_name<PropertyType>();
473 if (default_name.empty())
475 default_name = class_name;
477 if (property_name.empty())
482 property_name =
"cmp." + class_name;
485 property_name =
"tpc.pub." + class_name;
494 description =
"Ice object name of the `" + class_name +
"` component.";
497 description =
"Name of the `" + class_name +
"` topic to publish data to.";
503 PropertyDefinition<std::string>* def_name =
new PropertyDefinition<std::string>(
505 def_name->setTypeIdName(
typeid(std::string).name());
506 definitions[property_name] =
static_cast<PropertyDefinitionBase*
>(def_name);
509 ProxyPropertyDefinition<PropertyTypePrx>* def =
510 new ProxyPropertyDefinition<PropertyTypePrx>(&setter, proxy_type);
511 proxies[property_name] =
static_cast<ProxyPropertyDefinitionBase*
>(def);
514 template <
typename PropertyType>
515 PropertyDefinition<PropertyType>&
517 const std::string& name,
518 const std::string& description,
524 def->setTypeIdName(
typeid(PropertyType).name());
531 template <
typename PropertyType>
534 const std::string& name,
535 PropertyType defaultValue,
536 const std::string& description,
540 nullptr, name, defaultValue,
description, constness);
542 def->setTypeIdName(
typeid(PropertyType).name());
549 template <
typename EigenVectorType>
552 const std::string& name,
553 const std::string& description,
554 const std::string& delimiter,
558 description, EigenVectorType::SizeAtCompileTime, delimiter);
561 defineRequiredProperty<EigenVectorType>(name, appendedDescription, constness);
564 def.
setFactory([delimiter](std::string
string) -> EigenVectorType
565 {
return eigenVectorFactoryFunction<EigenVectorType>(
string, delimiter); });
571 template <
typename EigenVectorType>
574 const std::string& name,
575 EigenVectorType defaultValue,
576 const std::string& description,
577 const std::string& delimiter,
581 description, EigenVectorType::SizeAtCompileTime, delimiter);
584 name, defaultValue, appendedDescription, constness);
587 def.
setFactory([delimiter](std::string
string) -> EigenVectorType
588 {
return eigenVectorFactoryFunction<EigenVectorType>(
string, delimiter); });
590 def.
map(eigenVectorToString<EigenVectorType>(defaultValue, delimiter), defaultValue);
596 template <
typename PropertyType>
603 std::stringstream ss;
604 ss << name +
" property is not defined. Defined are ";
605 for (
typename DefinitionContainer::iterator it =
definitions.begin();
609 ss <<
"\n" << it->first;
611 throw armarx::LocalException(ss.str());
617 if (def->getTypeIdName().compare(
typeid(PropertyType).name()) != 0)
619 throw armarx::LocalException(
620 std::string(
"Calling getProperty<T>() for the property '") + name +
621 "' with wrong property type [note: " +
typeid(PropertyType).name() +
622 " instead of " + def->getTypeIdName() +
"]");
629 template <
typename EigenVectorType>
635 long size = EigenVectorType::SizeAtCompileTime;
636 bool isFixedSize = size >= 0;
638 const std::vector<std::string> stringScalars =
split(
string, delim,
true);
640 std::vector<Scalar> scalars;
643 if (stringScalars.size() !=
static_cast<std::size_t
>(size))
645 throw std::bad_cast();
647 scalars.reserve(size);
649 for (
const auto& scalarStr : stringScalars)
652 Scalar value = PropertyDefinition_lexicalCastTo<Scalar>(scalarStr);
653 scalars.push_back(
value);
656 EigenVectorType vector;
659 vector.resize(scalars.size());
662 for (std::size_t i = 0; i < scalars.size(); ++i)
664 vector(i) = scalars[i];
669 template <
typename EigenVectorType>
674 std::stringstream ss;
675 long size = vector.size();
678 for (
int i = 1; i < size; ++i)
680 ss << delim << vector(i);