Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
serialbox::MetainfoMapImpl Class Reference

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.
 
MetainfoMapImploperator= (const MetainfoMapImpl &)=default
 Copy assignment.
 
MetainfoMapImploperator= (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< TypeIDtypes () 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_typeoperator[] (const key_type &key) noexcept
 Return a reference to mapped value given by key. More...
 
mapped_typeoperator[] (key_type &&key) noexcept
 
mapped_typeat (const key_type &key)
 Return a reference to mapped value given by key. More...
 
const mapped_typeat (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.
 

Detailed Description

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.

Member Function Documentation

◆ as()

template<class ValueType , class KeyType >
ValueType serialbox::MetainfoMapImpl::as ( KeyType &&  key) const
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.

Parameters
keyKey of the new element
Returns
Copy of the value of the element as type T
Exceptions
ExceptionKey does not exist or conversion results in truncation of the value
See also
MetainfoValueImpl::as

Definition at line 149 of file MetainfoMapImpl.h.

◆ at()

MetainfoMapImpl::mapped_type & serialbox::MetainfoMapImpl::at ( const key_type key)

Return a reference to mapped value given by key.

Exceptions
ExceptionNo mapped value with given key exists

Definition at line 68 of file MetainfoMapImpl.cpp.

◆ find()

template<class StringType >
iterator serialbox::MetainfoMapImpl::find ( StringType &&  key)
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.

Parameters
keyKey to be searched for
Returns
An iterator to the element, if an element with specified key is found, or MetainfoMapImpl::end otherwise

Definition at line 114 of file MetainfoMapImpl.h.

◆ fromJSON()

void serialbox::MetainfoMapImpl::fromJSON ( const json::json &  jsonNode)

Construct from JSON node.

Exceptions
ExceptionJSON node is ill-formed

Definition at line 159 of file MetainfoMapImpl.cpp.

◆ hasKey()

template<class StringType >
bool serialbox::MetainfoMapImpl::hasKey ( StringType &&  key) const
inlinenoexcept

Check if key exists in the map.

Parameters
keyKey to be searched for
Returns
True iff the key is present

Definition at line 88 of file MetainfoMapImpl.h.

◆ insert()

template<class KeyType , class ValueType >
bool serialbox::MetainfoMapImpl::insert ( KeyType &&  key,
ValueType &&  value 
)
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).

Parameters
keyKey of the new element
valueObject to be copied to (or moved as) the value of the new element
Returns
Value indicating whether the element was successfully inserted or not

Definition at line 132 of file MetainfoMapImpl.h.

◆ keys()

std::vector< std::string > serialbox::MetainfoMapImpl::keys ( ) const

Get vector of strings of all available keys.

To get the corresponding TypeIDs, use MetainfoMapImpl::types().

Returns
vector of strings of all keys

Definition at line 52 of file MetainfoMapImpl.cpp.

◆ operator[]()

mapped_type& serialbox::MetainfoMapImpl::operator[] ( const key_type key)
inlinenoexcept

Return a reference to mapped value given by key.

Exceptions
ExceptionKey does not exist

Definition at line 162 of file MetainfoMapImpl.h.

◆ types()

std::vector< TypeID > serialbox::MetainfoMapImpl::types ( ) const

Get vector of all available keys.

To get the corresponding keys, use MetainfoMapImpl::keys().

Returns
vector of TypeIDs of all elements

Definition at line 60 of file MetainfoMapImpl.cpp.


The documentation for this class was generated from the following files: