Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
FieldMetainfoImpl.h
Go to the documentation of this file.
1 //===-- serialbox/core/FieldMetainfoImplImpl.h ------------------------------------------*- C++
2 //-*-===//
3 //
4 // S E R I A L B O X
5 //
6 // This file is distributed under terms of BSD license.
7 // See LICENSE.txt for more information
8 //
9 //===------------------------------------------------------------------------------------------===//
10 //
14 //===------------------------------------------------------------------------------------------===//
15 
16 #ifndef SERIALBOX_CORE_FIELDMAPMETAINFOIMPL_H
17 #define SERIALBOX_CORE_FIELDMAPMETAINFOIMPL_H
18 
19 #include "serialbox/core/Json.h"
21 #include <memory>
22 
23 namespace serialbox {
24 
27 
30 public:
33  : type_(TypeID::Invalid), dims_(), metaInfo_(std::make_shared<MetainfoMapImpl>()) {}
34 
36  FieldMetainfoImpl(TypeID type, const std::vector<int>& dims, const MetainfoMapImpl& metaInfo)
37  : type_(type), dims_(dims), metaInfo_(std::make_shared<MetainfoMapImpl>(metaInfo)) {}
38 
40  FieldMetainfoImpl(TypeID type, const std::vector<int>& dims)
41  : type_(type), dims_(dims), metaInfo_(std::make_shared<MetainfoMapImpl>()) {}
42 
44  explicit FieldMetainfoImpl(const json::json& jsonNode) : FieldMetainfoImpl() {
45  fromJSON(jsonNode);
46  }
47 
49  FieldMetainfoImpl(const FieldMetainfoImpl& other) { *this = other; }
50 
53 
56 
59 
61  void swap(FieldMetainfoImpl& other) noexcept;
62 
64  bool operator==(const FieldMetainfoImpl& right) const noexcept;
65 
67  bool operator!=(const FieldMetainfoImpl& right) const noexcept { return (!(*this == right)); }
68 
70  TypeID& type() noexcept { return type_; }
71  const TypeID& type() const noexcept { return type_; }
72 
74  std::vector<int>& dims() noexcept { return dims_; }
75  const std::vector<int>& dims() const noexcept { return dims_; }
76 
78  MetainfoMapImpl& metaInfo() noexcept { return *metaInfo_; }
79  const MetainfoMapImpl& metaInfo() const noexcept { return *metaInfo_; }
80 
82  json::json toJSON() const;
83 
87  void fromJSON(const json::json& jsonNode);
88 
90  std::string toString() const;
91 
93  friend std::ostream& operator<<(std::ostream& stream, const FieldMetainfoImpl& f);
94 
96  std::shared_ptr<MetainfoMapImpl>& metaInfoPtr() noexcept { return metaInfo_; }
97  const std::shared_ptr<MetainfoMapImpl>& metaInfoPtr() const noexcept { return metaInfo_; }
98 
99 private:
100  TypeID type_;
101  std::vector<int> dims_;
102  std::shared_ptr<MetainfoMapImpl> metaInfo_;
103 };
104 
106 
107 } // namespace serialbox
108 
109 #endif
std::string toString() const
Convert to string.
FieldMetainfoImpl(const json::json &jsonNode)
Construct from JSON.
Meta-information of a data field.
FieldMetainfoImpl(TypeID type, const std::vector< int > &dims, const MetainfoMapImpl &metaInfo)
Construct members externally.
FieldMetainfoImpl(const FieldMetainfoImpl &other)
Copy constructor.
Definition: json.hpp:10517
Namespace of the serialbox library.
Definition: Archive.h:25
TypeID
Type-id of types recognized by serialbox.
Definition: Type.h:55
TypeID & type() noexcept
Access TypeID.
friend std::ostream & operator<<(std::ostream &stream, const FieldMetainfoImpl &f)
Convert to stream.
bool operator==(const FieldMetainfoImpl &right) const noexcept
Test for equality.
void swap(FieldMetainfoImpl &other) noexcept
Swap with other.
Hash-map of meta-information of the form key = value pair or key = {value1, ..., valueN} ...
bool operator!=(const FieldMetainfoImpl &right) const noexcept
Test for inequality.
MetainfoMapImpl & metaInfo() noexcept
Access meta-info map.
void fromJSON(const json::json &jsonNode)
Construct from JSON node.
json::json toJSON() const
Convert to JSON.
FieldMetainfoImpl()
Default constructor.
FieldMetainfoImpl & operator=(const FieldMetainfoImpl &other)
Copy assignment.
std::shared_ptr< MetainfoMapImpl > & metaInfoPtr() noexcept
Get meta-info pointer.
FieldMetainfoImpl(TypeID type, const std::vector< int > &dims)
Construct members externally.
std::vector< int > & dims() noexcept
Access dimensions.