21 #include <unordered_map>
23 #include <string_view>
72 std::enable_if_t<std::is_unsigned<T>::value && !std::is_same<T, bool>::value,
bool> =
true>
83 std::enable_if_t<std::is_integral<T>::value&& std::is_signed<T>::value,
bool> =
true>
94 std::enable_if_t<std::is_floating_point<T>::value,
bool> =
true>
104 template <
typename T,
105 std::enable_if_t<std::is_same<T, bool>::value,
bool> =
true>
156 for (
const auto& current_right : config_right) {
157 result_configuration.insert_or_assign(current_right.first, current_right.second);
159 return result_configuration;
165 template <
typename T>
166 T propertyValueAs(
const std::string& property_value)
168 static_assert(
sizeof(T) == -1,
169 "please use the specializations for bool, int64_t, uint64_t, double and std::string.");
173 inline bool propertyValueAs<bool>(
const std::string& property_value)
175 if (property_value ==
"true")
179 else if (property_value ==
"false")
185 return (std::stoll(property_value, 0, 0) != 0);
190 inline uint64_t propertyValueAs<uint64_t>(
const std::string& property_value)
192 return std::stoull(property_value, 0, 0);
196 inline int64_t propertyValueAs<int64_t>(
const std::string& property_value)
198 return std::stoll(property_value, 0, 0);
202 inline uint32_t propertyValueAs<uint32_t>(
const std::string& property_value)
204 return std::stoul(property_value, 0, 0);
208 inline int32_t propertyValueAs<int32_t>(
const std::string& property_value)
210 return std::stol(property_value, 0, 0);
214 inline double propertyValueAs<double>(
const std::string& property_value)
216 return std::stod(property_value);
220 inline std::string propertyValueAs<std::string>(
const std::string& property_value)
222 return property_value;
236 template <
typename T>
241 auto const& property_value = configuration.at(property_name);
242 if constexpr(std::is_arithmetic<T>::value) {
243 if (property_value.type ==
"bool") {
244 return (property_value.value ==
"true") ? 1 : 0;
247 return detail::propertyValueAs<T>(property_value.value);
251 std::throw_with_nested(std::runtime_error(
"cannot set property value of '" + property_name));
265 template <
typename T>
270 const auto& found = configuration.find(property_name);
271 if (found != configuration.end()) {
272 if constexpr(std::is_arithmetic<T>::value) {
273 if (found->second.type ==
"bool") {
274 return (found->second.value ==
"true") ? 1 : 0;
277 return detail::propertyValueAs<T>(found->second.value);
280 return default_value;
285 std::throw_with_nested(std::runtime_error(
"cannot set property value of '" + property_name));
297 template <
typename T>
302 configuration.insert_or_assign(property_name,
PropertyValue(property_value));
306 std::throw_with_nested(std::runtime_error(
"cannot set property value of '" + property_name));
325 return _configuration;
334 _configuration = _configuration + configuration;
Definition: configuration.h:314
virtual ~Configurable()=default
DTOR.
virtual const Configuration & getConfiguration() const
Definition: configuration.h:323
virtual void setConfiguration(const Configuration &configuration)
Definition: configuration.h:332
namespace for ADTF File library
Definition: adtf2_adtf_core_media_sample_deserializer.h:25
Configuration operator+(const Configuration &config_left, const Configuration &config_right)
Add operator for configurations.
Definition: configuration.h:153
bool operator==(const PropertyValue &left, const PropertyValue &right)
compare operator for PropertyValue
Definition: configuration.h:133
void setPropertyValue(Configuration &configuration, const std::string &property_name, const T &property_value)
Definition: configuration.h:298
T getPropertyValue(const Configuration &configuration, const std::string &property_name)
Definition: configuration.h:237
std::unordered_map< std::string, PropertyValue > Configuration
Configuration class as set of key - property value pairs This configuration is used to adjust the rea...
Definition: configuration.h:143
PropertyValue variant class.
Definition: configuration.h:32
PropertyValue & operator=(PropertyValue &&)=default
move assignment
PropertyValue(std::string_view string_value)
CTOR for string value and "string" type.
Definition: configuration.h:115
PropertyValue(std::string value, std::string type)
CTOR.
Definition: configuration.h:63
PropertyValue()=default
CTOR.
PropertyValue(PropertyValue &&)=default
move CTOR
std::string type
Type as string.
Definition: configuration.h:122
PropertyValue(const PropertyValue &)=default
copy CTOR
PropertyValue & operator=(const PropertyValue &)=default
copy assignment
PropertyValue(T value)
CTOR for unsigned integer value (uint8-uint64) and "unsigned" type.
Definition: configuration.h:73
std::string value
Value as string.
Definition: configuration.h:120