21#include <unordered_map>
70 template<typename T, std::enable_if_t<std::is_unsigned<T>::value && !std::is_same<T, bool>::value,
bool> =
true>
79 template<typename T, std::enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value,
bool> =
true>
88 template<typename T, std::enable_if_t<std::is_floating_point<T>::value,
bool> =
true>
97 template<typename T, std::enable_if_t<std::is_same<T, bool>::value,
bool> =
true>
145 for (
const auto& current_right : config_right)
147 result_configuration.insert_or_assign(current_right.first, current_right.second);
149 return result_configuration;
156T propertyValueAs(
const std::string& )
158 static_assert(
sizeof(T) == -1,
159 "please use the specializations for bool, int64_t, uint64_t, double and std::string.");
163inline bool propertyValueAs<bool>(
const std::string& property_value)
165 if (property_value ==
"true")
169 else if (property_value ==
"false")
175 return (std::stoll(property_value, 0, 0) != 0);
180inline uint64_t propertyValueAs<uint64_t>(
const std::string& property_value)
182 return std::stoull(property_value, 0, 0);
186inline int64_t propertyValueAs<int64_t>(
const std::string& property_value)
188 return std::stoll(property_value, 0, 0);
192inline uint32_t propertyValueAs<uint32_t>(
const std::string& property_value)
194 return std::stoul(property_value, 0, 0);
198inline int32_t propertyValueAs<int32_t>(
const std::string& property_value)
200 return std::stol(property_value, 0, 0);
204inline double propertyValueAs<double>(
const std::string& property_value)
206 return std::stod(property_value);
210inline std::string propertyValueAs<std::string>(
const std::string& property_value)
212 return property_value;
215struct ReservedProperties
217 static constexpr auto reserved_prefix =
"#__";
218 static constexpr auto version =
"#__version";
219 static constexpr auto display_name =
"#__display_name";
220 static constexpr auto description =
"#__description";
222 static constexpr auto range_min =
"#__range_min";
223 static constexpr auto range_max =
"#__range_max";
225 static constexpr auto value_list_count =
"#__value_list_count";
226 static constexpr auto value_list_value =
"#__value_list_value_";
227 static constexpr auto value_list_name =
"#__value_list_name_";
228 static constexpr auto value_list_restricted =
"#__value_list_restricted";
230 static constexpr auto default_filename_extension =
"#__default_filename_extension";
248 auto const& property_value = configuration.at(property_name);
249 if constexpr (std::is_arithmetic<T>::value)
251 if (property_value.type ==
"bool")
253 return (property_value.value ==
"true") ? 1 : 0;
256 return detail::propertyValueAs<T>(property_value.value);
260 std::throw_with_nested(std::runtime_error(
"cannot get property value of '" + property_name));
279 const auto& found = configuration.find(property_name);
280 if (found != configuration.end())
282 if constexpr (std::is_arithmetic<T>::value)
284 if (found->second.type ==
"bool")
286 return (found->second.value ==
"true") ? 1 : 0;
289 return detail::propertyValueAs<T>(found->second.value);
293 return default_value;
298 std::throw_with_nested(std::runtime_error(
"cannot get property value of '" + property_name));
312 const std::string& property_name,
313 bool top_level_reserved_properties =
false)
315 const auto prefix = property_name +
"/";
317 for (
const auto& property : configuration)
319 if (property.first.find(prefix) == 0)
321 const auto name =
property.first.substr(prefix.size());
322 if (top_level_reserved_properties || name.find(detail::ReservedProperties::reserved_prefix) != 0)
324 sub_configuration.try_emplace(name, property.second);
328 return sub_configuration;
343 configuration.insert_or_assign(property_name,
PropertyValue(property_value));
347 std::throw_with_nested(std::runtime_error(
"cannot set property value of '" + property_name));
358 setPropertyValue(configuration, detail::ReservedProperties::version, version);
368 setPropertyValue(configuration, detail::ReservedProperties::description, description);
378 const std::string& property_name,
379 const std::string& description)
381 setPropertyValue(configuration, property_name +
"/" + detail::ReservedProperties::description, description);
391 const std::string& property_name,
392 const std::string& display_name)
394 setPropertyValue(configuration, property_name +
"/" + detail::ReservedProperties::display_name, display_name);
408 setPropertyValue<T>(configuration, property_name +
"/" + detail::ReservedProperties::range_min, min);
409 setPropertyValue<T>(configuration, property_name +
"/" + detail::ReservedProperties::range_max, max);
422 const std::string& property_name,
423 const std::vector<std::pair<T, std::string>>& value_list,
424 bool restrict_to_values =
true)
427 static_cast<unsigned int>(value_list.size()));
428 setPropertyValue<bool>(configuration, property_name +
"/" + detail::ReservedProperties::value_list_restricted,
432 for (
const auto& value : value_list)
435 property_name +
"/" + detail::ReservedProperties::value_list_value + std::to_string(index),
438 property_name +
"/" + detail::ReservedProperties::value_list_name + std::to_string(index),
459 return _configuration;
468 _configuration = _configuration + configuration;
480template<
typename T = std::
string>
551#define FILE_PLUGIN_META_INFORMATION(version, description) \
553 adtf_file::Configuration configuration; \
554 setFilePluginVersion(configuration, version); \
555 setFilePluginDescription(configuration, description); \
556 setConfiguration(configuration); \
Definition configuration.h:448
virtual ~Configurable()=default
DTOR.
virtual void setConfiguration(const Configuration &configuration)
Definition configuration.h:466
virtual const Configuration & getConfiguration() const
Definition configuration.h:457
PropertyBuilder(std::string name, T default_value)
Sets a property with name and default value. Hierarchically grouped properties are created with the '...
Definition configuration.h:491
PropertyBuilder & setMinMax(const T &min, const T &max)
Sets a minimum/maximum range for the property value.
Definition configuration.h:538
PropertyBuilder & setValueList(const std::vector< std::pair< T, std::string > > &value_list, bool restrict_to_values)
Sets a value list for the property.
Definition configuration.h:526
PropertyBuilder & setDescription(const std::string &description)
Sets a description for the property.
Definition configuration.h:501
PropertyBuilder & setDisplayName(const std::string &display_name)
Sets a display name for the property. Please note that '/' is used for hierarchical grouping of prope...
Definition configuration.h:513
namespace for ADTF File library
Definition adtf2_adtf_core_media_sample_deserializer.h:25
void setPropertyValueRange(Configuration &configuration, const std::string &property_name, const T &min, const T &max)
Definition configuration.h:406
Configuration operator+(const Configuration &config_left, const Configuration &config_right)
Add operator for configurations.
Definition configuration.h:142
void setPropertyValueList(Configuration &configuration, const std::string &property_name, const std::vector< std::pair< T, std::string > > &value_list, bool restrict_to_values=true)
Definition configuration.h:421
void setFilePluginVersion(Configuration &configuration, const std::string &version)
Definition configuration.h:356
bool operator==(const PropertyValue &left, const PropertyValue &right)
compare operator for PropertyValue
Definition configuration.h:123
void setPropertyDisplayName(Configuration &configuration, const std::string &property_name, const std::string &display_name)
Definition configuration.h:390
void setPropertyValue(Configuration &configuration, const std::string &property_name, const T &property_value)
Definition configuration.h:339
void setPropertyDescription(Configuration &configuration, const std::string &property_name, const std::string &description)
Definition configuration.h:377
T getPropertyValue(const Configuration &configuration, const std::string &property_name)
Definition configuration.h:244
Configuration getSubConfiguration(const Configuration &configuration, const std::string &property_name, bool top_level_reserved_properties=false)
Get a sub-tree of a configuration property.
Definition configuration.h:311
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:132
void setFilePluginDescription(Configuration &configuration, const std::string &description)
Definition configuration.h:366
PropertyValue variant class.
Definition configuration.h:31
PropertyValue(std::string_view string_value)
CTOR for string value and "string" type.
Definition configuration.h:106
PropertyValue & operator=(const PropertyValue &)=default
copy assignment
PropertyValue(std::string value, std::string type)
CTOR.
Definition configuration.h:62
PropertyValue()=default
CTOR.
PropertyValue & operator=(PropertyValue &&)=default
move assignment
PropertyValue(PropertyValue &&)=default
move CTOR
std::string type
Type as string.
Definition configuration.h:112
PropertyValue(const PropertyValue &)=default
copy CTOR
PropertyValue(T value)
CTOR for unsigned integer value (uint8-uint64) and "unsigned" type.
Definition configuration.h:71
std::string value
Value as string.
Definition configuration.h:110