15 #ifndef SERIALBOX_CORE_SAVEPOINTIMPL_H 16 #define SERIALBOX_CORE_SAVEPOINTIMPL_H 41 template <
class StringType,
42 class =
typename std::enable_if<!std::is_same<StringType, json::json>::value>::type>
47 template <
class StringType,
class MetainfoType>
73 template <
class StringType,
class ValueType>
75 if(!metaInfo_->insert(std::forward<StringType>(key), std::forward<ValueType>(value)))
76 throw Exception(
"cannot add element with key '%s' to metaInfo: element already exists", key);
85 template <
class T,
class StringType>
88 return metaInfo_->at(key).template as<T>();
90 throw Exception(
"cannot get element with key '%s' from metaInfo: %s", key, e.what());
96 return (name_ == right.name_) && (*metaInfo_ == *right.metaInfo_);
104 name_.swap(other.name_);
105 metaInfo_->swap(*other.metaInfo_);
109 const std::string&
name() const noexcept {
return name_; }
117 bool empty() const noexcept {
return metaInfo_->empty(); }
120 json::json
toJSON()
const;
125 void fromJSON(
const json::json& jsonNode);
134 std::shared_ptr<MetainfoMapImpl>&
metaInfoPtr() noexcept {
return metaInfo_; }
135 const std::shared_ptr<MetainfoMapImpl>&
metaInfoPtr()
const noexcept {
return metaInfo_; }
139 std::shared_ptr<MetainfoMapImpl> metaInfo_;
156 return std::hash<std::string>()(s.
name());
json::json toJSON() const
Convert to JSON.
SavepointImpl(const json::json &jsonNode)
Construct from JSON.
void swap(SavepointImpl &other) noexcept
Swap with other.
T getMetainfoAs(StringType &&key) const
Query metaInfo for key key and retrieve value as type T
void fromJSON(const json::json &jsonNode)
Construct from JSON node.
std::string toString() const
Convert savepoint to string.
bool empty() const noexcept
Returns a bool value indicating whether the savepoint is empty (i.e has no meta-information attached)...
SavepointImpl(StringType &&name, MetainfoType &&metaInfo)
Construct savepoint with name and metaInfo
void addMetainfo(StringType &&key, ValueType &&value)
Add a new key = value pair to the metaInfo of the Savepoint.
bool operator==(const SavepointImpl &right) const
Test for equality.
SavepointImpl(const SavepointImpl &other)
Copy constructor.
Namespace of the serialbox library.
bool operator!=(const SavepointImpl &right) const
Test for inequality.
const std::string & name() const noexcept
Access name.
SavepointImpl & operator=(const SavepointImpl &other)
Copy assignment.
SavepointImpl(const StringType &name)
Construct an empty savepoint (wihtout metaInfo i.e this->empty() == true)
std::shared_ptr< MetainfoMapImpl > & metaInfoPtr() noexcept
Get meta-info pointer.
MetainfoMapImpl & metaInfo() noexcept
Access meta-info.
Exception class which stores a human-readable error description.
Shared implementation of the Savepoint.
friend std::ostream & operator<<(std::ostream &stream, const SavepointImpl &s)
Convert to stream.