29 #ifndef CDPL_BASE_PROPERTYCONTAINER_HPP
30 #define CDPL_BASE_PROPERTYCONTAINER_HPP
33 #include <unordered_map>
77 typedef std::unordered_map<LookupKey, Any, LookupKey::HashFunc> PropertyMap;
105 template <
typename T>
106 void setProperty(
const LookupKey& key,
T&& val);
119 template <
typename T>
120 const T& getProperty(
const LookupKey& key)
const;
135 template <
typename T>
136 const T& getPropertyOrDefault(
const LookupKey& key,
const T& def_val)
const;
150 inline const Any& getProperty(
const LookupKey& key,
bool throw_ =
false)
const;
157 inline bool isPropertySet(
const LookupKey& key)
const;
251 inline bool isEmptyAny(
const Any& val)
const;
253 template <
typename T>
254 bool isEmptyAny(
const T& val)
const;
256 PropertyMap properties;
264 template <
typename T>
267 return getProperty(key,
true).template getData<T>();
270 template <
typename T>
273 const Any& val = getProperty(key,
false);
275 return (val.
isEmpty() ? def_val : val.template getData<T>());
280 static const Any NOT_FOUND;
284 if (it != properties.end())
293 template <
typename T>
296 if (isEmptyAny(val)) {
297 properties.erase(key);
301 properties[key] = std::forward<T>(val);
306 return (properties.find(key) != properties.end());
309 bool CDPL::Base::PropertyContainer::isEmptyAny(
const Any& val)
const
314 template <
typename T>
315 bool CDPL::Base::PropertyContainer::isEmptyAny(
const T&)
const
Definition of the class CDPL::Base::Any.
Definition of the preprocessor macro CDPL_BASE_API.
#define CDPL_BASE_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of exception classes.
Definition of the class CDPL::Base::LookupKey.
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
bool isEmpty() const noexcept
Tells whether the Any instance stores any data.
Definition: Any.hpp:182
Thrown to indicate that some requested data item could not be found.
Definition: Base/Exceptions.hpp:171
An unique lookup key for control-parameter and property values.
Definition: LookupKey.hpp:54
const std::string & getName() const
Returns the name of the LookupKey instance.
A class providing methods for the storage and lookup of object properties.
Definition: PropertyContainer.hpp:75
const T & getProperty(const LookupKey &key) const
Returns the value of the property specified by key as a const reference to an object of type T.
Definition: PropertyContainer.hpp:265
ConstPropertyIterator getPropertiesBegin() const
Returns a constant iterator pointing to the beginning of the property entries.
PropertyContainer()
Constructs an empty PropertyContainer instance.
Definition: PropertyContainer.hpp:227
bool removeProperty(const LookupKey &key)
Clears the value of the property specified by key.
const T & getPropertyOrDefault(const LookupKey &key, const T &def_val) const
Returns the value of the property specified by key as a const reference to an object of type T,...
Definition: PropertyContainer.hpp:271
const PropertyContainer & getProperties() const
Returns a const reference to itself.
Definition: PropertyContainer.hpp:320
PropertyMap::const_iterator ConstPropertyIterator
A constant iterator used to iterate over the property entries.
Definition: PropertyContainer.hpp:88
virtual ~PropertyContainer()
Virtual destructor.
PropertyContainer & operator=(const PropertyContainer &cntnr)
Assignment operator.
void addProperties(const PropertyContainer &cntnr)
Adds the property value entries in the PropertyContainer instance cntnr.
PropertyContainer(const PropertyContainer &cntnr)
Constructs a copy of the PropertyContainer instance cntnr.
std::size_t getNumProperties() const
Returns the number of property entries.
void clearProperties()
Clears all property values.
ConstPropertyIterator end() const
Returns a constant iterator pointing to the end of the property entries.
void swap(PropertyContainer &cntnr)
Exchanges the properties of this container with the properties of the container cntnr.
bool isPropertySet(const LookupKey &key) const
Tells whether or not a value has been assigned to the property specified by key.
Definition: PropertyContainer.hpp:304
ConstPropertyIterator getPropertiesEnd() const
Returns a constant iterator pointing to the end of the property entries.
PropertyMap::value_type PropertyEntry
A Base::LookupKey / Base::Any pair that stores the property value for a given property key.
Definition: PropertyContainer.hpp:83
ConstPropertyIterator begin() const
Returns a constant iterator pointing to the beginning of the property entries.
void copyProperties(const PropertyContainer &cntnr)
Replaces the current set of properties by a copy of the entries in cntnr.
void setProperty(const LookupKey &key, T &&val)
Sets the value of the property specified by key to val.
Definition: PropertyContainer.hpp:294
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
The namespace of the Chemical Data Processing Library.