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

Hash-map to query the meta-information of the registered fields. More...

#include <FieldMap.h>

Public Types

using map_type = std::unordered_map< std::string, std::shared_ptr< FieldMetainfoImpl > >
 Type of the underlying hash-map.
 
using value_type = map_type::value_type
 Type of an entry of the MetainfoMapImpl (std::pair<std::string, std::shared_ptr<FieldMetainfoImpl>>)
 
using key_type = map_type::key_type
 Type of the key (std::string) i.e name of the fields.
 
using mapped_type = map_type::mapped_type
 Type of the value (std::shared_ptr<FieldMetainfoImpl>)
 
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

 FieldMap ()
 Default constructor (empty table)
 
 FieldMap (const json::json jsonNode)
 Construct from json.
 
 FieldMap (const FieldMap &)=default
 Copy constructor [deleted].
 
 FieldMap (FieldMap &&)=default
 Move constructor.
 
FieldMapoperator= (const FieldMap &)=default
 Copy assignment.
 
FieldMapoperator= (FieldMap &&)=default
 Move assignment.
 
template<class StringType >
bool hasField (StringType &&name) const noexcept
 Check if field with name name exists in the FieldMap. More...
 
template<class StringType >
iterator findField (StringType &&name) noexcept
 Search the FieldMap for a field with name name and returns an iterator to it if found, otherwise returns an iterator to FieldMap::end. More...
 
template<class StringType >
const_iterator findField (StringType &&name) const noexcept
 
template<class StringType >
FieldMetainfoImplgetFieldMetainfoImplOf (StringType &&name)
 Get FieldMetainfoImpl of field name More...
 
template<class StringType >
const FieldMetainfoImplgetFieldMetainfoImplOf (StringType &&name) const
 
template<class StringType >
std::shared_ptr< FieldMetainfoImpl > & getFieldMetainfoImplPtrOf (StringType &&name)
 Get pointer to FieldMetainfoImpl of field name More...
 
template<class StringType >
const std::shared_ptr< FieldMetainfoImpl > & getFieldMetainfoImplPtrOf (StringType &&name) const
 
template<class StringType >
MetainfoMapImplgetMetainfoOf (StringType &&name)
 Get Metainfo of field with name name More...
 
template<class StringType >
const MetainfoMapImplgetMetainfoOf (StringType &&name) const
 
template<class StringType >
std::vector< int > & getDimsOf (StringType &&name)
 Get Dimensions of field with name name More...
 
template<class StringType >
const std::vector< int > & getDimsOf (StringType &&name) const
 
template<class StringType >
TypeID getTypeOf (StringType &&name) const
 Get Type of field with name name More...
 
template<class StringType , typename... Args>
bool insert (StringType &&key, Args &&... args)
 Insert a new field in the map. More...
 
std::size_t size () const noexcept
 Returns the number of elements in the FieldMap.
 
bool empty () const noexcept
 Returns a bool value indicating whether the FieldMap is empty.
 
void clear () noexcept
 All the elements in the FieldMap 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 FieldMap.
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 Returns an iterator pointing to the past-the-end element in the FieldMap.
 
const_iterator end () const noexcept
 
void swap (FieldMap &other) noexcept
 Swap with other.
 
bool operator== (const FieldMap &right) const noexcept
 Test for equality.
 
bool operator!= (const FieldMap &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 FieldMap &s)
 Convert to stream.
 

Detailed Description

Hash-map to query the meta-information of the registered fields.

Definition at line 28 of file FieldMap.h.

Member Function Documentation

◆ findField()

template<class StringType >
iterator serialbox::FieldMap::findField ( StringType &&  name)
inlinenoexcept

Search the FieldMap for a field with name name and returns an iterator to it if found, otherwise returns an iterator to FieldMap::end.

Parameters
nameName of the field
Returns
Iterator to field if found, otherwise an iterator to FieldMap::end

Definition at line 85 of file FieldMap.h.

◆ fromJSON()

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

Construct from JSON node.

Exceptions
ExceptionJSON node is ill-formed

Definition at line 31 of file FieldMap.cpp.

◆ getDimsOf()

template<class StringType >
std::vector<int>& serialbox::FieldMap::getDimsOf ( StringType &&  name)
inline

Get Dimensions of field with name name

Parameters
nameName of the field
Exceptions
ExceptionField with name name does not exist in FieldMap

Definition at line 147 of file FieldMap.h.

◆ getFieldMetainfoImplOf()

template<class StringType >
FieldMetainfoImpl& serialbox::FieldMap::getFieldMetainfoImplOf ( StringType &&  name)
inline

Get FieldMetainfoImpl of field name

Parameters
nameName of the field
Exceptions
ExceptionField name does not exist in FieldMap

Definition at line 99 of file FieldMap.h.

◆ getFieldMetainfoImplPtrOf()

template<class StringType >
std::shared_ptr<FieldMetainfoImpl>& serialbox::FieldMap::getFieldMetainfoImplPtrOf ( StringType &&  name)
inline

Get pointer to FieldMetainfoImpl of field name

Parameters
nameName of the field
Exceptions
ExceptionField name does not exist in FieldMap

Definition at line 113 of file FieldMap.h.

◆ getMetainfoOf()

template<class StringType >
MetainfoMapImpl& serialbox::FieldMap::getMetainfoOf ( StringType &&  name)
inline

Get Metainfo of field with name name

Parameters
nameName of the field
Exceptions
ExceptionField with name name does not exist in FieldMap

Definition at line 133 of file FieldMap.h.

◆ getTypeOf()

template<class StringType >
TypeID serialbox::FieldMap::getTypeOf ( StringType &&  name) const
inline

Get Type of field with name name

Parameters
nameName of the field
Exceptions
ExceptionField with name name does not exist in FieldMap

Definition at line 167 of file FieldMap.h.

◆ hasField()

template<class StringType >
bool serialbox::FieldMap::hasField ( StringType &&  name) const
inlinenoexcept

Check if field with name name exists in the FieldMap.

Parameters
nameName of the field
Returns
True iff the field is present

Definition at line 75 of file FieldMap.h.

◆ insert()

template<class StringType , typename... Args>
bool serialbox::FieldMap::insert ( StringType &&  key,
Args &&...  args 
)
inline

Insert a new field in the map.

The field is inserted only if its name is not equivalent to the name of any other field already in the map (fields in a FieldMap are unique).

Parameters
nameName of the the new field
ArgsArguments forwarded to the constructor of FieldMetainfoImpl
Returns
Value indicating whether the field was successfully inserted or not

Definition at line 183 of file FieldMap.h.


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