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

Hash-map of meta-information of the form key = value pair or key = {value1, ..., valueN} More...

#include <MetainfoMap.h>

Public Types

using map_type = MetainfoMapImpl::map_type
 Type of the underlying hash-map.
 
using value_type = map_type::value_type
 Type of an entry of the MetainfoMapImpl (std::pair<std::string, meta_info_value>)
 
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

 meta_info_map ()
 Default constructor (empty map)
 
 meta_info_map (std::initializer_list< value_type > list)
 Construct from initalizer-list. More...
 
 meta_info_map (const meta_info_map &)=default
 Copy constructor. More...
 
 meta_info_map (meta_info_map &&)=default
 Move constructor.
 
meta_info_mapoperator= (const meta_info_map &)=default
 Copy assignment. More...
 
meta_info_mapoperator= (meta_info_map &&)=default
 Move assignment.
 
meta_info_mapoperator= (std::initializer_list< value_type > list)
 Construct from initalizer-list. More...
 
meta_info_map clone () const
 Clone the current meta_info_map object by performing a deep copy. More...
 
 meta_info_map (const std::shared_ptr< MetainfoMapImpl > &map)
 Construct with MetainfoMapImpl (internal use)
 
template<class StringType >
bool has_key (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 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 to type T More...
 
std::size_t size () const noexcept
 Returns the number of elements in the meta_info_map.
 
bool empty () const noexcept
 Returns a bool value indicating whether the meta_info_map is empty, i.e. whether its size is 0.
 
void clear () noexcept
 All the elements in the meta_info_map 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 meta_info_map.
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 Returns an iterator pointing to the past-the-end element in the meta_info_map.
 
const_iterator end () const noexcept
 
void swap (meta_info_map &other) noexcept
 Swap with other.
 
bool operator== (const meta_info_map &right) const noexcept
 Test for equality.
 
bool operator!= (const meta_info_map &right) const noexcept
 Test for inequality.
 
const std::shared_ptr< MetainfoMapImpl > & impl () const
 Get implementation pointer.
 
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 meta_info_map::end. More...
 
template<class StringType >
const_iterator find (StringType &&key) const noexcept
 
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.
 
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
 

Friends

std::ostream & operator<< (std::ostream &stream, const meta_info_map &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 34 of file MetainfoMap.h.

Constructor & Destructor Documentation

◆ meta_info_map() [1/2]

serialbox::gridtools::meta_info_map::meta_info_map ( std::initializer_list< value_type list)
inline

Construct from initalizer-list.

Example:

meta_info_map m({{"key1", meta_info_value(4.0)}, {"key2", meta_info_value(2))}});

Definition at line 66 of file MetainfoMap.h.

◆ meta_info_map() [2/2]

serialbox::gridtools::meta_info_map::meta_info_map ( const meta_info_map )
default

Copy constructor.

This performs a shallow copy, meaning the objects share the same underlying MetainfoMapImpl. To deep copy the object call meta_info_map::clone().

Example

meta_info_map m1 = {{"key1", meta_info_value(4.0)}, {"key2", meta_info_value(2))}};
m1.clear();
assert(m2.empty()); // m1 and m2 share the same MetainfoMapImpl, hence m2 is empty as
well
See also
meta_info_map::clone()

Member Function Documentation

◆ as()

template<class ValueType , class KeyType >
ValueType serialbox::gridtools::meta_info_map::as ( KeyType &&  key) const
inline

Convert value of element with 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

Definition at line 214 of file MetainfoMap.h.

◆ at()

mapped_type& serialbox::gridtools::meta_info_map::at ( const key_type key)
inline

Return a reference to mapped value given by key.

Exceptions
exceptionNo mapped value with given key exists

Definition at line 238 of file MetainfoMap.h.

◆ clone()

meta_info_map serialbox::gridtools::meta_info_map::clone ( ) const
inline

Clone the current meta_info_map object by performing a deep copy.

Example: To deep copy a meta_info_map

meta_info_map m1 = {{"key1", double(4)}, {"key2", int(2)}};
meta_info_map m2 = m1.clone();
m1.clear();
assert(!m2.empty()); // m1 and m2 do NOT share the same MetainfoMapImpl, hence m2 is not

Definition at line 135 of file MetainfoMap.h.

◆ find()

template<class StringType >
iterator serialbox::gridtools::meta_info_map::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 meta_info_map::end.

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

Definition at line 180 of file MetainfoMap.h.

◆ has_key()

template<class StringType >
bool serialbox::gridtools::meta_info_map::has_key ( 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 148 of file MetainfoMap.h.

◆ insert()

template<class KeyType , class ValueType >
bool serialbox::gridtools::meta_info_map::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 199 of file MetainfoMap.h.

◆ keys()

std::vector<std::string> serialbox::gridtools::meta_info_map::keys ( ) const
inline

Get vector of strings of all available keys.

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

Returns
vector of strings of all keys
See also
meta_info_map::types

Definition at line 160 of file MetainfoMap.h.

◆ operator=() [1/2]

meta_info_map& serialbox::gridtools::meta_info_map::operator= ( const meta_info_map )
default

Copy assignment.

This performs a shallow copy, meaning the objects share the same underlying MetainfoMapImpl. To deep copy the object call meta_info_map::clone().

Example

meta_info_map m1 = {{"key1", meta_info_value(4.0)}, {"key2", meta_info_value(2))}};
meta_info_map m2 = m1;
m1.clear();
assert(m2.empty()); // m1 and m2 share the same MetainfoMapImpl, hence m2 is empty as
well
See also
meta_info_map::clone

◆ operator=() [2/2]

meta_info_map& serialbox::gridtools::meta_info_map::operator= ( std::initializer_list< value_type list)
inline

Construct from initalizer-list.

Example:

meta_info_map m1 = {{"key1", meta_info_value(4.0)}, {"key2", meta_info_value(2))}};

Definition at line 119 of file MetainfoMap.h.

◆ types()

std::vector<TypeID> serialbox::gridtools::meta_info_map::types ( ) const
inline

Get vector of all available keys.

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

Returns
vector of TypeIDs of all elements
See also
meta_info_map::keys

Definition at line 169 of file MetainfoMap.h.


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