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

The SavepointVector manages the registered savepoints and their mapping to the stored fields. More...

#include <SavepointVector.h>

Public Types

using savepoint_vector_type = std::vector< std::shared_ptr< SavepointImpl > >
 Vector of savepoints.
 
using fields_per_savepoint_type = std::unordered_map< std::string, unsigned int >
 Map of fields per savepoint.
 
using fields_per_savepoint_vector_type = std::vector< fields_per_savepoint_type >
 Vector of map of fields per savepoint.
 
using iterator = savepoint_vector_type::iterator
 A random access iterator to std::shared_ptr<Savepoint>
 
using const_iterator = savepoint_vector_type::const_iterator
 A random access iterator to const std::shared_ptr<Savepoint>
 

Public Member Functions

 SavepointVector ()
 Default constructor (empty)
 
 SavepointVector (const SavepointVector &)=default
 Copy constructor.
 
 SavepointVector (SavepointVector &&)=default
 Move constructor.
 
 SavepointVector (const json::json &jsonNode)
 Construct from JSON.
 
SavepointVectoroperator= (const SavepointVector &)=default
 Copy assignment.
 
SavepointVectoroperator= (SavepointVector &&)=default
 Move assignment.
 
bool exists (const SavepointImpl &savepoint) const noexcept
 Check if savepoint exists. More...
 
int find (const SavepointImpl &savepoint) const noexcept
 Find savepoint. More...
 
int insert (const SavepointImpl &savepoint) noexcept
 Insert savepoint in savepoint vector. More...
 
bool addField (const SavepointImpl &savepoint, const FieldID &fieldID) noexcept
 Add a field to the savepoint. More...
 
bool addField (int idx, const FieldID &fieldID) noexcept
 Add a field to the savepoint given a valid savepoint index idx More...
 
bool hasField (const SavepointImpl &savepoint, const std::string &field) noexcept
 Check if savepoint has field field More...
 
bool hasField (int idx, const std::string &field) noexcept
 Check if savepoint has field field given a valid savepoint index idx More...
 
FieldID getFieldID (const SavepointImpl &savepoint, const std::string &field) const
 Get the FielID of field field at savepoint savepoint More...
 
FieldID getFieldID (int idx, const std::string &field) const
 Get the FielID of field field given a valid savepoint index idx More...
 
const fields_per_savepoint_typefieldsOf (const SavepointImpl &savepoint) const
 Access fields of savepoint. More...
 
const fields_per_savepoint_typefieldsOf (int idx) const noexcept
 Access fields of savepoint given a valid savepoint index idx
 
bool empty () const noexcept
 Returns a bool value indicating whether the savepoint vector is empty.
 
std::size_t size () const noexcept
 Returns the number of savepoints in the vector.
 
void clear () noexcept
 All the elements Savepoints are dropped: their destructors are called, and they are removed from the container, leaving it with a size of 0.
 
void swap (SavepointVector &other) noexcept
 Swap with other.
 
iterator begin () noexcept
 Returns an iterator pointing to the first savepoint in the vector.
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 Returns an iterator pointing to the past-the-end savepoint in the vector.
 
const_iterator end () const noexcept
 
SavepointImploperator[] (int idx) noexcept
 Get savepoint.
 
const SavepointImploperator[] (int idx) const noexcept
 
std::shared_ptr< SavepointImpl > & back () noexcept
 Returns a reference to the last element in the savepoint vector.
 
const std::shared_ptr< SavepointImpl > & back () const noexcept
 
const savepoint_vector_typesavepoints () const noexcept
 Access the savepoints.
 
savepoint_vector_typesavepoints () noexcept
 
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 SavepointVector &s)
 Convert to stream.
 

Detailed Description

The SavepointVector manages the registered savepoints and their mapping to the stored fields.

The savepoints are ordered in the sequence they were registred.

Definition at line 35 of file SavepointVector.h.

Member Function Documentation

◆ addField() [1/2]

bool serialbox::SavepointVector::addField ( const SavepointImpl savepoint,
const FieldID fieldID 
)
noexcept

Add a field to the savepoint.

Returns
True iff the field was successfully addeed to the savepoint

Definition at line 31 of file SavepointVector.cpp.

◆ addField() [2/2]

bool serialbox::SavepointVector::addField ( int  idx,
const FieldID fieldID 
)
noexcept

Add a field to the savepoint given a valid savepoint index idx

Returns
True iff the field was successfully addeed to the savepoint

Definition at line 38 of file SavepointVector.cpp.

◆ exists()

bool serialbox::SavepointVector::exists ( const SavepointImpl savepoint) const
noexcept

Check if savepoint exists.

Returns
True iff the savepoint exists

Definition at line 74 of file SavepointVector.cpp.

◆ fieldsOf()

const SavepointVector::fields_per_savepoint_type & serialbox::SavepointVector::fieldsOf ( const SavepointImpl savepoint) const

Access fields of savepoint.

Exceptions
ExceptionSavepoint does not exists

Definition at line 89 of file SavepointVector.cpp.

◆ find()

int serialbox::SavepointVector::find ( const SavepointImpl savepoint) const
noexcept

Find savepoint.

Returns
Index of savepoint in the savepoint-vector or -1 if savepoint does not exist

Definition at line 78 of file SavepointVector.cpp.

◆ fromJSON()

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

Construct from JSON node.

Exceptions
ExceptionJSON node is ill-formed

Definition at line 125 of file SavepointVector.cpp.

◆ getFieldID() [1/2]

FieldID serialbox::SavepointVector::getFieldID ( const SavepointImpl savepoint,
const std::string &  field 
) const

Get the FielID of field field at savepoint savepoint

Exceptions
ExceptionSavepoint or field at savepoint do not exist

Definition at line 60 of file SavepointVector.cpp.

◆ getFieldID() [2/2]

FieldID serialbox::SavepointVector::getFieldID ( int  idx,
const std::string &  field 
) const

Get the FielID of field field given a valid savepoint index idx

Exceptions
ExceptionSavepoint or field at savepoint do not exist

Definition at line 53 of file SavepointVector.cpp.

◆ hasField() [1/2]

bool serialbox::SavepointVector::hasField ( const SavepointImpl savepoint,
const std::string &  field 
)
noexcept

Check if savepoint has field field

Returns
True iff the field field exists at savepoint

Definition at line 42 of file SavepointVector.cpp.

◆ hasField() [2/2]

bool serialbox::SavepointVector::hasField ( int  idx,
const std::string &  field 
)
noexcept

Check if savepoint has field field given a valid savepoint index idx

Returns
True iff the field field exists at savepoint

Definition at line 49 of file SavepointVector.cpp.

◆ insert()

int serialbox::SavepointVector::insert ( const SavepointImpl savepoint)
noexcept

Insert savepoint in savepoint vector.

Returns
Index of the newly inserted savepoint or -1 if savepoint already exists

Definition at line 21 of file SavepointVector.cpp.


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