Hash-map of meta-information of the form key = value pair or key = {value1, ..., valueN}
More...
#include <MetainfoMapImpl.h>
Public Types | |
| using | map_type = std::unordered_map< std::string, MetainfoValueImpl > |
| Type of the underlying hash-map. | |
| using | value_type = map_type::value_type |
Type of an entry of the MetainfoMapImpl (std::pair<std::string, MetainfoValueImpl>) | |
| using | key_type = map_type::key_type |
Type of the key (std::string) | |
| using | mapped_type = map_type::mapped_type |
Type of the value (MetainfoMapImpl::Value) | |
| using | size_type = map_type::size_type |
An unsigned integral type (std::size_t) | |
| using | iterator = map_type::iterator |
A forward iterator to value_type | |
| using | const_iterator = map_type::const_iterator |
A forward iterator to const value_type | |
Public Member Functions | |
| MetainfoMapImpl () | |
| Default constructor (empty map) | |
| MetainfoMapImpl (const json::json &jsonNode) | |
| Construct from json. | |
| MetainfoMapImpl (std::initializer_list< value_type > list) | |
| Construct from initalizer-list. | |
| MetainfoMapImpl (const MetainfoMapImpl &)=default | |
| Copy constructor. | |
| MetainfoMapImpl (MetainfoMapImpl &&)=default | |
| Move constructor. | |
| MetainfoMapImpl & | operator= (const MetainfoMapImpl &)=default |
| Copy assignment. | |
| MetainfoMapImpl & | operator= (MetainfoMapImpl &&)=default |
| Move assignment. | |
| template<class StringType > | |
| bool | hasKey (StringType &&key) const noexcept |
| Check if key exists in the map. More... | |
| std::vector< std::string > | keys () const |
| Get vector of strings of all available keys. More... | |
| std::vector< TypeID > | types () const |
| Get vector of all available keys. More... | |
| template<class StringType > | |
| iterator | find (StringType &&key) noexcept |
Search the container for an element with a key equivalent to key and return an iterator to it if found, otherwise it returns an iterator to MetainfoMapImpl::end. More... | |
| template<class StringType > | |
| const_iterator | find (StringType &&key) const noexcept |
| template<class KeyType , class ValueType > | |
| bool | insert (KeyType &&key, ValueType &&value) noexcept |
| Insert a new element in the map. More... | |
| template<class ValueType , class KeyType > | |
| ValueType | as (KeyType &&key) const |
Convert value of element with key key to type T More... | |
| iterator | erase (const_iterator position) |
| Removes from the MetainfoMapImpl either a single element or a range of elements [first,last) | |
| size_type | erase (const key_type &key) |
| iterator | erase (const_iterator first, const_iterator last) |
| mapped_type & | operator[] (const key_type &key) noexcept |
| Return a reference to mapped value given by key. More... | |
| mapped_type & | operator[] (key_type &&key) noexcept |
| mapped_type & | at (const key_type &key) |
| Return a reference to mapped value given by key. More... | |
| const mapped_type & | at (const key_type &key) const |
| std::size_t | size () const noexcept |
| Returns the number of elements in the MetainfoMapImpl. | |
| bool | empty () const noexcept |
| Returns a bool value indicating whether the MetainfoMapImpl is empty, i.e. whether its size is 0. | |
| void | clear () noexcept |
| All the elements in the MetainfoMapImpl are dropped: their destructors are called, and they are removed from the container, leaving it with a size of 0. | |
| iterator | begin () noexcept |
| Returns an iterator pointing to the first element in the MetainfoMapImpl. | |
| const_iterator | begin () const noexcept |
| iterator | end () noexcept |
| Returns an iterator pointing to the past-the-end element in the MetainfoMapImpl. | |
| const_iterator | end () const noexcept |
| void | swap (MetainfoMapImpl &other) noexcept |
| Swap with other. | |
| bool | operator== (const MetainfoMapImpl &right) const noexcept |
| Test for equality. | |
| bool | operator!= (const MetainfoMapImpl &right) const noexcept |
| Test for inequality. | |
| json::json | toJSON () const |
| Convert to JSON. | |
| void | fromJSON (const json::json &jsonNode) |
| Construct from JSON node. More... | |
Friends | |
| std::ostream & | operator<< (std::ostream &stream, const MetainfoMapImpl &s) |
| Convert to stream. | |
Hash-map of meta-information of the form key = value pair or key = {value1, ..., valueN}
They keys are strings (std::string), while the values can be booleans, integers (32 and 64 bit), floating point numbers (32 and 64 bit) or strings.
Definition at line 38 of file MetainfoMapImpl.h.
|
inline |
Convert value of element with key key to type T
If the type T is different than the internally stored type, the function does its best to convert the value to T in a meaningful way.
| key | Key of the new element |
T| Exception | Key does not exist or conversion results in truncation of the value |
Definition at line 149 of file MetainfoMapImpl.h.
| MetainfoMapImpl::mapped_type & serialbox::MetainfoMapImpl::at | ( | const key_type & | key | ) |
Return a reference to mapped value given by key.
| Exception | No mapped value with given key exists |
Definition at line 68 of file MetainfoMapImpl.cpp.
|
inlinenoexcept |
Search the container for an element with a key equivalent to key and return an iterator to it if found, otherwise it returns an iterator to MetainfoMapImpl::end.
| key | Key to be searched for |
Definition at line 114 of file MetainfoMapImpl.h.
| void serialbox::MetainfoMapImpl::fromJSON | ( | const json::json & | jsonNode | ) |
Construct from JSON node.
| Exception | JSON node is ill-formed |
Definition at line 159 of file MetainfoMapImpl.cpp.
|
inlinenoexcept |
Check if key exists in the map.
| key | Key to be searched for |
Definition at line 88 of file MetainfoMapImpl.h.
|
inlinenoexcept |
Insert a new element in the map.
The element is inserted only if its key is not equivalent to the key of any other element already in the map (keys in a MetainfoMapImpl are unique).
| key | Key of the new element |
| value | Object to be copied to (or moved as) the value of the new element |
Definition at line 132 of file MetainfoMapImpl.h.
| std::vector< std::string > serialbox::MetainfoMapImpl::keys | ( | ) | const |
Get vector of strings of all available keys.
To get the corresponding TypeIDs, use MetainfoMapImpl::types().
Definition at line 52 of file MetainfoMapImpl.cpp.
|
inlinenoexcept |
Return a reference to mapped value given by key.
| Exception | Key does not exist |
Definition at line 162 of file MetainfoMapImpl.h.
| std::vector< TypeID > serialbox::MetainfoMapImpl::types | ( | ) | const |
Get vector of all available keys.
To get the corresponding keys, use MetainfoMapImpl::keys().
Definition at line 60 of file MetainfoMapImpl.cpp.