16 #ifndef SERIALBOX_CORE_SAVEPOINTVECTOR_H 17 #define SERIALBOX_CORE_SAVEPOINTVECTOR_H 23 #include <unordered_map> 36 using index_type = std::unordered_map<SavepointImpl, int>;
49 using iterator = savepoint_vector_type::iterator;
105 bool hasField(
int idx,
const std::string& field) noexcept;
126 bool empty() const noexcept {
return index_.empty(); }
129 std::size_t
size() const noexcept {
return savepoints_.size(); }
133 void clear() noexcept;
151 std::shared_ptr<SavepointImpl>&
back() noexcept {
return savepoints_.back(); }
152 const std::shared_ptr<SavepointImpl>&
back()
const noexcept {
return savepoints_.back(); }
159 json::json
toJSON()
const;
164 void fromJSON(
const json::json& jsonNode);
std::vector< fields_per_savepoint_type > fields_per_savepoint_vector_type
Vector of map of fields per savepoint.
void fromJSON(const json::json &jsonNode)
Construct from JSON node.
bool hasField(const SavepointImpl &savepoint, const std::string &field) noexcept
Check if savepoint has field field
SavepointVector(const json::json &jsonNode)
Construct from JSON.
FieldID getFieldID(const SavepointImpl &savepoint, const std::string &field) const
Get the FielID of field field at savepoint savepoint
std::vector< std::shared_ptr< SavepointImpl > > savepoint_vector_type
Vector of savepoints.
bool empty() const noexcept
Returns a bool value indicating whether the savepoint vector is empty.
int find(const SavepointImpl &savepoint) const noexcept
Find savepoint.
SavepointVector()
Default constructor (empty)
SavepointVector & operator=(const SavepointVector &)=default
Copy assignment.
const fields_per_savepoint_type & fieldsOf(const SavepointImpl &savepoint) const
Access fields of savepoint.
Namespace of the serialbox library.
SavepointImpl & operator[](int idx) noexcept
Get savepoint.
Uniquely identifiy a field.
const savepoint_vector_type & savepoints() const noexcept
Access the savepoints.
json::json toJSON() const
Convert to JSON.
std::unordered_map< std::string, unsigned int > fields_per_savepoint_type
Map of fields per savepoint.
void swap(SavepointVector &other) noexcept
Swap with other.
savepoint_vector_type::const_iterator const_iterator
A random access iterator to const std::shared_ptr<Savepoint>
The SavepointVector manages the registered savepoints and their mapping to the stored fields...
int insert(const SavepointImpl &savepoint) noexcept
Insert savepoint in savepoint vector.
std::shared_ptr< SavepointImpl > & back() noexcept
Returns a reference to the last element in the savepoint vector.
std::size_t size() const noexcept
Returns the number of savepoints in the vector.
bool exists(const SavepointImpl &savepoint) const noexcept
Check if savepoint exists.
iterator end() noexcept
Returns an iterator pointing to the past-the-end savepoint in the vector.
bool addField(const SavepointImpl &savepoint, const FieldID &fieldID) noexcept
Add a field to the savepoint.
friend std::ostream & operator<<(std::ostream &stream, const SavepointVector &s)
Convert to stream.
iterator begin() noexcept
Returns an iterator pointing to the first savepoint in the vector.
Shared implementation of the Savepoint.
void clear() noexcept
All the elements Savepoints are dropped: their destructors are called, and they are removed from the ...
savepoint_vector_type::iterator iterator
A random access iterator to std::shared_ptr<Savepoint>