1 #ifndef FALAISE_PROPERTY_SET_H 2 #define FALAISE_PROPERTY_SET_H 8 #include "boost/mpl/contains.hpp" 9 #include "boost/mpl/vector.hpp" 18 using std::logic_error::logic_error;
23 using std::logic_error::logic_error;
29 using std::logic_error::logic_error;
205 std::vector<std::string>
get_names()
const;
213 bool has_key(std::string
const& key)
const;
271 template <
typename T>
272 T
get(std::string
const& key)
const;
282 template <
typename T>
283 T
get(std::string
const& key, T
const& default_value)
const;
298 template <
typename T>
299 void put(std::string
const& key, T
const& value);
311 template <
typename T>
320 bool erase(std::string
const& key);
327 std::vector<bool>, std::vector<std::string>>;
328 template <
typename T>
330 typedef typename boost::mpl::contains<types_, T>::type type;
333 template <
typename T>
335 typedef std::true_type type;
342 template <
typename T>
343 using can_hold_t_ =
typename can_hold_<T>::type;
350 template <
typename T>
351 bool is_type_(std::string
const& key)
const;
354 bool is_type_impl_(std::string
const& key,
int)
const;
357 bool is_type_impl_(std::string
const& key,
double)
const;
360 bool is_type_impl_(std::string
const& key,
bool)
const;
363 bool is_type_impl_(std::string
const& key, std::string)
const;
372 bool is_type_impl_(std::string
const& key, std::vector<int>)
const;
376 bool is_type_impl_(std::string
const& key, std::vector<double>)
const;
379 bool is_type_impl_(std::string
const& key, std::vector<bool>)
const;
382 bool is_type_impl_(std::string
const& key, std::vector<std::string>)
const;
388 template <
typename T>
389 void put_impl_(std::string
const& key, T
const& value);
395 template <
typename T>
396 void get_impl_(std::string
const& key, T& result)
const;
399 template <
typename T>
403 template <
typename T>
414 template <
typename T>
419 if (!is_type_<T>(key)) {
424 get_impl_(key, result);
439 template <
typename T>
441 T result{default_value};
443 if (!is_type_<T>(key)) {
446 get_impl_(key, result);
455 return default_value;
457 return get<property_set>(key);
460 template <
typename T>
462 static_assert(can_hold_t_<T>::value,
"property_set cannot hold values of type T");
467 put_impl_(key, value);
478 for (
auto& subkey : (value.ps_).keys()) {
479 ps_.
store(key+
"."+subkey, (value.ps_).get(subkey));
483 template <
typename T>
499 template <
typename T>
500 bool property_set::is_type_(std::string
const& key)
const {
501 static_assert(can_hold_t_<T>::value,
"property_set cannot hold values of type T");
503 return is_type_impl_(key, T{});
510 template <
typename T>
511 void property_set::put_impl_(std::string
const& key, T
const& value) {
512 ps_.
store(key, value);
523 inline void property_set::put_impl_(std::string
const& key,
530 template <
typename T>
537 template <
typename T>
538 void property_set::get_impl_(std::string
const& key, T& result)
const {
539 ps_.
fetch(key, result);
550 inline void property_set::get_impl_(std::string
const& key,
554 double rescaledValue =
560 template <
typename T>
564 double rescaledValue =
579 #endif // FALAISE_PROPERTY_SET_H bool is_empty() const
Returns true if no key-value pairs are held.
bool has_key(std::string const &key) const
Returns true if the property_set stores a pair with the supplied key.
T get(std::string const &key) const
Return the value of type T held at supplied key.
Definition: property_set.h:415
bool is_key_to_property(std::string const &key) const
Returns true if the key's value is a property/atom.
Definition: property_set.h:28
Exception thrown when requesting a key that is not in the property_set.
Definition: property_set.h:17
void put_or_replace(std::string const &key, T const &value)
Insert key-value pair in property_set, replacing value if key exists.
Definition: property_set.h:484
Class representing a value and physical unit.
Definition: quantity.h:90
std::string const & unit() const
Return datatools::units tag for the quantity's unit.
Definition: quantity.h:149
void make_property_set(const std::string &filename, property_set &ps)
Construct a property_set from an input datatools::properties file.
Class representing a filesystem path as held by a property_set.
Definition: path.h:62
bool is_key_to_sequence(std::string const &key) const
Returns true if the keys's value is sequence.
Definition: metadata_utils.h:35
std::string to_string() const
Returns a string representation of the property_set.
bool is_key_to_property_set(std::string const &key) const
Returns true if the key's value is a property_set.
Exception thrown when trying to put to a key already in the property_set.
Definition: property_set.h:22
Template class for a physical value with a strict dimension.
Definition: quantity.h:185
Class holding a set of key-value properties.
Definition: property_set.h:189
void put(std::string const &key, T const &value)
Insert key-value pair in property_set.
Definition: property_set.h:461
property_set()=default
Default constructor.
Types for configuration validation of physical quantities.
bool erase(std::string const &key)
Erase the name-value pair stored at key.
std::vector< std::string > get_names() const
Returns a vector of all keys in the property_set.