Element
template <typename KeyType, typename AttributesType = bool> class Element
@brief Class representing leaf elements in a Hash which may have attributes
Types
| Name | Description |
|---|---|
| SetClassIdAttribute | Helper struct adding a classId attribute for classes inheriting (but not being) Hash. |
| SetClassIdAttribute |
Types that are neither Hashes nor derived from Hashes are not touched. |
| SetClassIdAttribute |
Hashes are not touched. |
Operators
| Name | Description |
|---|---|
| operator== | Compare two elements for equality: Checks if the elements have the same key other : Return : |
| operator!= | Compare two elements for inequality: Checks if the elements have the same key other : Return : |
Functions
| Name | Description |
|---|---|
| Element | Construct an empty Hash element |
| Element | Construct a Hash element from a std::any value key : identifies the element value : of the element |
| Element | Construct a Hash element from a std::any value key : identifies the element value : of the element |
| Element | Construct a Hash element from an arbitrary value type key : identifies the element value : of the element |
| Element | Construct a Hash element from an arbitrary value type key : identifies the element value : of the element |
| getKey | Return the key identifying this Element Return : |
| setValue | Set a value of arbitrary type to this Element value : |
| setValue | Set a value of arbitrary type to this Element value : |
| setValue | Set the value to a std::shared_ptr of ValueType value : |
| setValue | For downward compatibility we allow insertion of shared_ptr |
| setValue | Overload for setting char pointers (c-strings). |
| setValue | Overload for setting char pointers (c-strings). |
| setValue | Overload for setting wide char pointers (c-strings). |
| setValue | Overload for setting wide char pointers (c-strings). |
| setValue | Set a std::any value to the Element value : |
| setValue | Set a std::any value to the Element value : |
| setValue | Set the value of another element to this Element, key and attributes are unchanged. |
| setValue | Set the value of another element to this Element, key and attributes are unchanged. |
| getValue | Return the first successful cast to one of the ValueTypes (DestValueType, SourceValueType or one of the SourceValueTypes). |
| getValue | Return the value cast to ValueType. |
| getValue | Return the value cast to ValueType. |
| getValueAsAny | Return the value as std::any. Does not throw Return : |
| getValueAsAny | Return the value as std::any. Does not throw Return : |
| getValueAs | Return the value cast to ValueType. |
| getValueAs | Return the value cast to ValueType. |
| getValueAsShortString | Return the value cast to string. |
| setAttribute | Set an attribute to this Element, identified by key key : value : |
| setAttribute | Set an attribute to this Element, identified by key key : value : |
| getAttribute | Return the attribute cast to ValueType. |
| getAttribute | Return the attribute cast to ValueType. |
| getAttribute | Return the attribute cast to ValueType. |
| getAttribute | Return the attribute cast to ValueType. |
| getAttributeAsAny | Return the value as std::any. Does not throw key : identifying the attribute Return : |
| getAttributeAsAny | Return the value as std::any. Does not throw key : identifying the attribute Return : |
| getAttributeAs | Return the attribute cast to ValueType. |
| getAttributeAs | Return the attribute cast to ValueType. |
| getAttributeNode | Return an attribute as a Node, e.g. an Elementkey : Return : |
| getAttributeNode | Return an attribute as a Node, e.g. an Elementkey : Return : |
| hasAttribute | Check if Element has an attribute identified by key key : Return : true if the attribute exists, false if not |
| setAttributes | Batch set attributes to this element attributes : |
| setAttributes | Batch set attributes to this element attributes : to move from |
| getAttributes | Batch get attributes of this element Return : |
| getAttributes | Batch get attributes of this element Return : |
| is | Check if element is of type T Return : true if element is type T |
| getType | Return the type of this element as a Karabo reference type Return : |
| type | Return the std::type_info struct for this element' type Return : |
| setType | Set the type of this Element to a different type. |
Operator Details
operator!=
bool operator!=(const Element<KeyType, AttributesType>& other) const
Compare two elements for inequality: Checks if the elements have the same key
other
:
Return :
operator==
bool operator==(const Element<KeyType, AttributesType>& other) const
Compare two elements for equality: Checks if the elements have the same key
other
:
Return :
Function Details
Element
Element()
Construct an empty Hash element
Element(const KeyType& key, const std::any& value)
Construct a Hash element from a std::any value
key
: identifies the element
value
: of the element
Element(const KeyType& key, std::any&& value)
Construct a Hash element from a std::any value
key
: identifies the element
value
: of the element
template <class ValueType> Element(const KeyType& key, const ValueType& value)
Construct a Hash element from an arbitrary value type
key
: identifies the element
value
: of the element
template <class ValueType> Element(const KeyType& key, ValueType&& value)
Construct a Hash element from an arbitrary value type
key
: identifies the element
value
: of the element
getAttribute
template <class T> inline T& getAttribute(const std::string& key)
Return the attribute cast to ValueType. Strict casting is applied, i.e. the T needs to be of the exact type of inserted vale (or implicitly castable)
key
: identifying the attribute
Return :
template <class T> inline void getAttribute(const std::string& key, T& value) const
Return the attribute cast to ValueType. Strict casting is applied, i.e. the T needs to be of the exact type of inserted vale (or implicitly castable)
key
: identifying the attribute
value
: reference to insert value in
Return :
template <class T> inline const T& getAttribute(const std::string& key) const
Return the attribute cast to ValueType. Strict casting is applied, i.e. the T needs to be of the exact type of inserted vale (or implicitly castable)
key
: identifying the attribute
Return :
template <class T> inline void getAttribute(const std::string& key, const T& value) const
Return the attribute cast to ValueType. Strict casting is applied, i.e. the T needs to be of the exact type of inserted vale (or implicitly castable)
key
: identifying the attribute
value
: reference to insert value in
Return :
getAttributeAs
template <class T> inline T getAttributeAs(const std::string& key) const
Return the attribute cast to ValueType. Casting is performed via string literal casts, i.e. less strict. param key identifying the attribute
Return :
template <typename T, template <typename Elem, typename = std::allocator<Elem> > class Cont> inline Cont<T> getAttributeAs(const std::string& key) const
Return the attribute cast to ValueType. Casting is performed via string literal casts, i.e. less strict. Overload for vector-type values param key identifying the attribute
Return :
getAttributeAsAny
inline const std::any& getAttributeAsAny(const std::string& key) const
Return the value as std::any. Does not throw
key
: identifying the attribute
Return :
inline std::any& getAttributeAsAny(const std::string& key)
Return the value as std::any. Does not throw
key
: identifying the attribute
Return :
getAttributeNode
Element<KeyType>& getAttributeNode(const std::string& key)
Return an attribute as a Node, e.g. an Element
key
:
Return :
const Element<KeyType>& getAttributeNode(const std::string& key) const
Return an attribute as a Node, e.g. an Element
key
:
Return :
getAttributes
inline const AttributesType& getAttributes() const
Batch get attributes of this element
Return :
inline AttributesType& getAttributes()
Batch get attributes of this element
Return :
getKey
const KeyType& getKey() const
Return the key identifying this Element
Return :
getType
Types::ReferenceType getType() const
Return the type of this element as a Karabo reference type
Return :
getValue
template <class DestValueType, class SourceValueType, class... SourceValueTypes> inline DestValueType getValue() const
Return the first successful cast to one of the ValueTypes (DestValueType, SourceValueType or one of the SourceValueTypes). Strict casting is applied, i.e. at least one of the ValueTypes needs to be of the exact type of inserted value (or implicitly castable)
Return : DestValueType by "copy". Candidate for Return Value Optimization through copy elision.
template <class ValueType> inline const ValueType& getValue() const
Return the value cast to ValueType. Strict casting is applied, i.e. the ValueType needs to be of the exact type of inserted value (or implicitly castable)
Return :
template <class ValueType> inline ValueType& getValue()
Return the value cast to ValueType. Strict casting is applied, i.e. the ValueType needs to be of the exact type of inserted value (or implicitly castable)
Return :
getValueAs
template <typename ValueType> ValueType getValueAs() const
Return the value cast to ValueType. Casting is performed via string literal casts, i.e. less strict.
Return :
template <typename T, template <typename Elem, typename = std::allocator<Elem> > class Cont> Cont<T> getValueAs() const
Return the value cast to ValueType. Casting is performed via string literal casts, i.e. less strict. Overload for vector-type values
Return :
getValueAsAny
std::any& getValueAsAny()
Return the value as std::any. Does not throw
Return :
const std::any& getValueAsAny() const
Return the value as std::any. Does not throw
Return :
getValueAsShortString
std::string getValueAsShortString(size_t maxNumVectorElements) const
Return the value cast to string.
The only difference to getValueAs
maxNumVectorElements
: maximum number of vector elements taken into account
Return :
hasAttribute
inline bool hasAttribute(const std::string& key) const
Check if Element has an attribute identified by key
key
:
Return : true if the attribute exists, false if not
is
template <typename T> inline bool is() const
Check if element is of type T
Return : true if element is type T
setAttribute
template <class T> inline void setAttribute(const std::string& key, const T& value)
Set an attribute to this Element, identified by key
key
:
value
:
template <class T> inline void setAttribute(const std::string& key, T&& value)
Set an attribute to this Element, identified by key
key
:
value
:
setAttributes
inline void setAttributes(const AttributesType& attributes)
Batch set attributes to this element
attributes
:
inline void setAttributes(AttributesType&& attributes)
Batch set attributes to this element
attributes
: to move from
setType
void setType(const Types::ReferenceType& tgtType)
Set the type of this Element to a different type. Requires that non-strict casting, as for getValueAs is possible. Otherwise throws and exception
tgtType
: type to set the element to
setValue
template <class ValueType> inline void setValue(const ValueType& value)
Set a value of arbitrary type to this Element
value
:
template <class ValueType> inline void setValue(ValueType&& value)
Set a value of arbitrary type to this Element
value
:
template <class ValueType> inline void setValue(const std::shared_ptr<ValueType>& value)
Set the value to a std::shared_ptr of ValueType
value
:
void setValue(const std::shared_ptr<Hash>& value)
For downward compatibility we allow insertion of
shared_ptr
void setValue(const char* value)
Overload for setting char pointers (c-strings). Internally, the element will hold a std::string.
value
:
void setValue(char* value)
Overload for setting char pointers (c-strings). Internally, the element will hold a std::string.
value
:
void setValue(const wchar_t* value)
Overload for setting wide char pointers (c-strings). Internally, the element will hold a std::wstring.
value
:
void setValue(wchar_t* value)
Overload for setting wide char pointers (c-strings). Internally, the element will hold a std::wstring.
value
:
void setValue(const std::any& value)
Set a std::any value to the Element
value
:
void setValue(std::any&& value)
Set a std::any value to the Element
value
:
void setValue(const Element<KeyType, AttributesType>& other)
Set the value of another element to this Element, key and attributes are unchanged.
Kept for backward compatibility, better use setValue(other.getValueAsAny()) instead.
other
:
void setValue(Element<KeyType, AttributesType>&& other)
Set the value of another element to this Element, key and attributes are unchanged.
Kept for backward compatibility, better use setValue(std::move(other.getValueAsAny())) instead.
other
:
type
const std::type_info& type() const
Return the std::type_info struct for this element' type
Return :