Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
SavepointImpl.cpp
Go to the documentation of this file.
1 //===-- serialbox/core/SavepointImpl.cpp --------------------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
16 #include "serialbox/core/Logging.h"
17 #include <sstream>
18 
19 namespace serialbox {
20 
22  name_ = other.name_;
23  metaInfo_ = std::make_shared<MetainfoMapImpl>(*other.metaInfo_);
24  return (*this);
25 }
26 
27 json::json SavepointImpl::toJSON() const {
28  json::json jsonNode;
29  jsonNode["name"] = name_;
30  jsonNode["meta_info"] = metaInfo_->toJSON();
31  return jsonNode;
32 }
33 
34 void SavepointImpl::fromJSON(const json::json& jsonNode) {
35  if(!metaInfo_)
36  metaInfo_ = std::make_shared<MetainfoMapImpl>();
37 
38  name_.clear();
39  metaInfo_->clear();
40 
41  if(jsonNode.is_null() || jsonNode.empty())
42  throw Exception("node is empty");
43 
44  if(!jsonNode.count("name"))
45  throw Exception("no node 'name'");
46  name_ = jsonNode["name"];
47 
48  if(jsonNode.count("meta_info"))
49  metaInfo_->fromJSON(jsonNode["meta_info"]);
50 }
51 
52 std::string SavepointImpl::toString() const {
53  std::stringstream ss;
54  ss << *this;
55  return ss.str();
56 }
57 
58 std::ostream& operator<<(std::ostream& stream, const SavepointImpl& s) {
59  return (stream << s.name_ << " " << (*s.metaInfo_));
60 }
61 
62 } // namespace serialbox
json::json toJSON() const
Convert to JSON.
void fromJSON(const json::json &jsonNode)
Construct from JSON node.
std::string toString() const
Convert savepoint to string.
Namespace of the serialbox library.
Definition: Archive.h:25
SavepointImpl & operator=(const SavepointImpl &other)
Copy assignment.
Exception class which stores a human-readable error description.
Definition: Exception.h:30
Shared implementation of the Savepoint.
Definition: SavepointImpl.h:38
friend std::ostream & operator<<(std::ostream &stream, const SavepointImpl &s)
Convert to stream.