295 template <
typename PropertyType>
302 template <
typename PropertyType>
309 template <
typename PropertyType>
316 template <
typename PropertyType>
323 template <
typename PropertyType>
330 template <
typename PropertyType>
337 template <
typename PropertyType>
345 throw armarx::LocalException(
"Required property '" +
getPropertyName() +
346 "': default doesn't exist.");
352 template <
typename PropertyType>
359 template <
typename PropertyType>
362 const std::string& value)
364 std::vector<std::string> mapValues;
370 mapValues.push_back(it->second.first);
377 (
min != -std::numeric_limits<double>::max()
380 (
max != std::numeric_limits<double>::max()
391 template <
typename PropertyType>
401 else if constexpr (std::is_same_v<PropertyType, IceUtil::Time>)
404 double time_count = time.toMicroSecondsDouble();
405 std::string unit =
"µs";
407 if (time_count >= 1000)
412 if (time_count >= 1000)
417 if (time_count >= 60)
422 if (time_count >= 60)
427 if (time_count >= 24)
429 return time.toDateTime();
439 else if constexpr (std::is_same_v<PropertyType, bool>)
444 else if constexpr (std::is_floating_point_v<PropertyType>)
449 else if constexpr (std::is_integral_v<PropertyType>)
454 else if constexpr (std::is_same_v<PropertyType, std::string>)
472 return it->second.first;
478 return "Default value not mapped.";
483 return std::string();
486 template <
typename PropertyType>
491 return isRequired() ? getValueRequired(prefix, iceProperties)
492 : getValueOptional(prefix, iceProperties);
495 template <
typename PropertyType>
504 else if (
setter.has_value())
506 (*setter)(
getValue(prefix, iceProperties));
510 std::map<std::string, std::string>
515 template <
typename PropertyType>
517 PropertyDefinition<PropertyType>::initHook()
520 if constexpr (std::is_same_v<PropertyType, bool>)
522 setCaseInsensitive(
true);
531 else if constexpr (std::is_same_v<PropertyType, armarx::MessageTypeT>)
533 setCaseInsensitive(
true);
544 else if constexpr (std::is_same_v<PropertyType, std::map<std::string, std::string>>)
549 else if constexpr (std::is_same_v<PropertyType, std::vector<std::string>>)
554 else if constexpr (std::is_same_v<PropertyType, IceUtil::Time>)
556 setCaseInsensitive(
true);
565 template <
typename PropertyType>
567 PropertyDefinition<PropertyType>::getValueRequired(
const std::string& prefix,
570 using namespace armarx::exceptions;
572 checkRequirement(prefix, iceProperties);
574 const std::string keyValue = getPropertyValue(prefix, iceProperties);
575 const std::string
value = getRawPropertyValue(prefix, iceProperties);
577 if (matchRegex(value))
584 return getFactory()(
value);
586 catch (
const armarx::LocalException& e)
588 throw local::InvalidPropertyValueException(prefix + getPropertyName(), value)
591 catch (
const std::exception& e)
593 throw local::InvalidPropertyValueException(prefix + getPropertyName(), value)
594 <<
"Unknown exception while constructing type out of value: " << e.what();
598 throw local::InvalidPropertyValueException(prefix + getPropertyName(), value)
599 <<
"Unknown exception while constructing type out of value.";
606 if (!propertyValuesMap.empty())
608 auto valueIter = propertyValuesMap.find(keyValue);
609 if (valueIter != propertyValuesMap.end())
611 return processMappedValue(valueIter->second.second);
615 throw local::UnmappedValueException(prefix + getPropertyName(), value)
616 <<
"Mapped keys: " << simox::alg::get_keys(getValueMap());
621 if constexpr (std::is_same_v<PropertyType, bool>)
626 else if constexpr (std::is_arithmetic_v<PropertyType>)
630 PropertyType numericValue =
632 checkLimits(prefix, numericValue);
635 catch (
const std::bad_cast&)
637 throw local::InvalidPropertyValueException(prefix + getPropertyName(), value);
641 else if constexpr (std::is_same_v<PropertyType, std::string>)
643 return processMappedValue(value);
648 <<
"Mapped keys: " << simox::alg::get_keys(getValueMap());
652 throw local::InvalidPropertyValueException(prefix + getPropertyName(),
653 getRawPropertyValue(prefix, iceProperties));
656 template <
typename PropertyType>
658 PropertyDefinition<PropertyType>::getValueOptional(
const std::string& prefix,
661 using namespace armarx::exceptions;
663 if (!isSet(prefix, iceProperties))
665 return getDefaultValue();
669 return getValueRequired(prefix, iceProperties);
673 template <
typename PropertyType>
675 PropertyDefinition<PropertyType>::getPropertyValue(
const std::string& prefix,
678 std::string
value = icePropertyGet(iceProperties, prefix + getPropertyName());
680 if (isCaseInsensitive())
688 template <
typename PropertyType>
690 PropertyDefinition<PropertyType>::getRawPropertyValue(
const std::string& prefix,
693 return icePropertyGet(iceProperties, prefix + getPropertyName());
698 template <
typename PropertyType>
700 PropertyDefinition<PropertyType>::matchRegex(
const std::string& value)
const
702 if (!getMatchRegex().
empty())
710 template <
typename PropertyType>
712 PropertyDefinition<PropertyType>::checkRequirement(
const std::string& prefix,
715 using namespace armarx::exceptions;
719 if (!isSet(prefix, iceProperties))
721 throw local::MissingRequiredPropertyException(prefix + getPropertyName(),
727 template <
typename PropertyType>
735 template <
typename PropertyType>
736 template <
typename T>
738 PropertyDefinition<PropertyType>::processMappedValue(
const T& value)
743 template <
typename PropertyType>
745 PropertyDefinition<PropertyType>::processMappedValue(
const std::string& value)
747 std::string result = value;
748 if (expandEnvironmentVariables())
750 expandEnvironmentVariables(result, result);
754 removeQuotes(result, result);
759 template <
typename PropertyType>
776 size_t foundStart = output.find(
"${");
778 if (foundStart != std::string::npos)
781 size_t foundEnd = output.find(
"}", foundStart);
783 if (foundEnd != std::string::npos)
785 std::string envVar = output.substr(foundStart + 2, foundEnd - foundStart - 2);
786 std::string replacement;
787 char* envVarENV = getenv(envVar.c_str());
791 replacement = envVarENV;
795 std::cout <<
"WARNING: Could not expand environment variable: " << envVar
799 output.replace(foundStart, foundEnd - foundStart + 1, replacement);
803 std::cout <<
"ERROR: Found '${' but missing '}' in " << input << std::endl;
818 template <
typename PropertyType>
824 if (input.size() < 2)
829 if ((input[0] ==
'"' && input[input.size() - 1] ==
'"') ||
830 (input[0] ==
'\'' && input[input.size() - 1] ==
'\''))
832 output = input.substr(1, input.size() - 2);
836 template <
typename PropertyType>
838 PropertyDefinition<PropertyType>::checkLimits(
const std::string& prefix,
839 PropertyType numericValue)
const
846 if ((dirtyValue < getMin()) || (dirtyValue > getMax()))
849 prefix + getPropertyName(), getMin(), getMax(), dirtyValue);