Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Savepoint.h
Go to the documentation of this file.
1 //===-- serialbox/core/frontend/gridtools/Savepoint.h -------------------------------*- 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 
15 #ifndef SERIALBOX_CORE_FRONTEND_GRIDTOOLS_SAVEPOINT_H
16 #define SERIALBOX_CORE_FRONTEND_GRIDTOOLS_SAVEPOINT_H
17 
21 #include <memory>
22 
23 namespace serialbox {
24 
25 namespace gridtools {
26 
34 class savepoint {
35 public:
43  explicit savepoint(const std::string& name)
44  : savepointImpl_(std::make_shared<SavepointImpl>(name)){};
45 
50  savepoint(const std::string& name, meta_info_map meta_info)
51  : savepointImpl_(std::make_shared<SavepointImpl>(name, *meta_info.impl())){};
52 
69  savepoint(const savepoint& other) = default;
70 
72  savepoint(savepoint&&) = default;
73 
90  savepoint& operator=(const savepoint& other) = default;
91 
93  savepoint& operator=(savepoint&&) = default;
94 
106  savepoint clone() const { return savepoint(std::make_shared<SavepointImpl>(*savepointImpl_)); }
107 
109  explicit savepoint(const std::shared_ptr<SavepointImpl>& savepoint_impl) {
110  savepointImpl_ = savepoint_impl;
111  }
112 
120  template <class StringType, class ValueType>
121  void add_meta_info(StringType&& key, ValueType&& value) {
122  savepointImpl_->addMetainfo(std::forward<StringType>(key), std::forward<ValueType>(value));
123  }
124 
126  bool operator==(const savepoint& right) const {
127  return (*savepointImpl_ == *right.savepointImpl_);
128  }
129 
131  bool operator!=(const savepoint& right) const { return (!(*this == right)); }
132 
134  void swap(savepoint& other) noexcept { savepointImpl_->swap(*other.savepointImpl_); }
135 
137  const std::string& name() const noexcept { return savepointImpl_->name(); }
138 
140  meta_info_map meta_info() const noexcept { return meta_info_map(savepointImpl_->metaInfoPtr()); }
141 
144  bool empty() const noexcept { return savepointImpl_->empty(); }
145 
147  std::string to_string() const { return savepointImpl_->toString(); };
148 
150  friend std::ostream& operator<<(std::ostream& stream, const savepoint& s) {
151  return (stream << *s.savepointImpl_);
152  }
153 
155  const std::shared_ptr<SavepointImpl>& impl() const { return savepointImpl_; }
156 
157 private:
158  std::shared_ptr<SavepointImpl> savepointImpl_;
159 };
160 
161 } // namespace gridtools
162 
163 } // namespace serialbox
164 
165 #endif
const std::shared_ptr< SavepointImpl > & impl() const
Get implementation pointer.
Definition: Savepoint.h:155
const std::string & name() const noexcept
Access name.
Definition: Savepoint.h:137
bool empty() const noexcept
Returns a bool value indicating whether the savepoint is empty (i.e has no meta-information attached)...
Definition: Savepoint.h:144
Definition: json.hpp:10517
void add_meta_info(StringType &&key, ValueType &&value)
Add a new key = value or key = {value1, ..., valueN} pair to the meta-information of the savepoint...
Definition: Savepoint.h:121
bool operator==(const savepoint &right) const
Test for equality.
Definition: Savepoint.h:126
Namespace of the serialbox library.
Definition: Archive.h:25
void swap(savepoint &other) noexcept
Swap with other.
Definition: Savepoint.h:134
savepoint(const std::string &name, meta_info_map meta_info)
Construct savepoint with name and metaInfo
Definition: Savepoint.h:50
Hash-map of meta-information of the form key = value pair or key = {value1, ..., valueN} ...
Definition: MetainfoMap.h:34
savepoint clone() const
Clone the current savepoint object by performing a deep copy.
Definition: Savepoint.h:106
bool operator!=(const savepoint &right) const
Test for inequality.
Definition: Savepoint.h:131
savepoint & operator=(const savepoint &other)=default
Copy assignment.
savepoint(const std::string &name)
Construct a savepoint.
Definition: Savepoint.h:43
friend std::ostream & operator<<(std::ostream &stream, const savepoint &s)
Convert to stream.
Definition: Savepoint.h:150
Namespace of the gridtools frontend.
std::string to_string() const
Convert savepoint to string.
Definition: Savepoint.h:147
Savepoint implemenation of the gridtools frontend.
Definition: Savepoint.h:34
savepoint(const std::shared_ptr< SavepointImpl > &savepoint_impl)
Construct with SavepointImpl (internal use)
Definition: Savepoint.h:109
Shared implementation of the Savepoint.
Definition: SavepointImpl.h:38
meta_info_map meta_info() const noexcept
Access meta-info.
Definition: Savepoint.h:140