Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
FieldMetainfo.h
Go to the documentation of this file.
1 //===-- serialbox/core/frontend/gridtools/FieldMetainfoImpl.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_FRONTEND_GRIDTOOLS_FIELD_META_INFO_H
17 #define SERIALBOX_CORE_FRONTEND_GRIDTOOLS_FIELD_META_INFO_H
18 
24 #include <memory>
25 
26 namespace serialbox {
27 
28 namespace gridtools {
29 
34 public:
36  field_meta_info() : field_meta_info_impl_(std::make_shared<FieldMetainfoImpl>()){};
37 
45  field_meta_info(type_id type, const std::vector<int>& dims, const meta_info_map& meta_info)
46  : field_meta_info_impl_(std::make_shared<FieldMetainfoImpl>(type, dims, *meta_info.impl())) {}
47 
54  field_meta_info(type_id type, const std::vector<int>& dims)
55  : field_meta_info_impl_(std::make_shared<FieldMetainfoImpl>(type, dims)) {}
56 
60  template <class StorageType,
61  class = typename std::enable_if<!std::is_same<typename std::decay<StorageType>::type,
62  field_meta_info>::value>::type>
63  field_meta_info(const StorageType& storage) {
64 
66  field_meta_info_impl_ =
67  std::make_shared<FieldMetainfoImpl>(typeID, internal::get_dims(storage));
68  }
69 
86  field_meta_info(const field_meta_info& other) = default;
87 
89  field_meta_info(field_meta_info&&) = default;
90 
107  field_meta_info& operator=(const field_meta_info& other) = default;
108 
111 
123  return field_meta_info(std::make_shared<FieldMetainfoImpl>(*field_meta_info_impl_));
124  }
125 
127  explicit field_meta_info(const std::shared_ptr<FieldMetainfoImpl>& field_meta_info_ptr) {
128  field_meta_info_impl_ = field_meta_info_ptr;
129  }
130 
132  void swap(field_meta_info& other) noexcept {
133  field_meta_info_impl_->swap(*other.field_meta_info_impl_);
134  };
135 
137  bool operator==(const field_meta_info& right) const noexcept {
138  return (*field_meta_info_impl_ == *right.field_meta_info_impl_);
139  }
140 
142  bool operator!=(const field_meta_info& right) const noexcept { return (!(*this == right)); }
143 
146  type_id& type() noexcept { return field_meta_info_impl_->type(); }
147  const type_id& type() const noexcept { return field_meta_info_impl_->type(); }
149 
152  std::vector<int>& dims() noexcept { return field_meta_info_impl_->dims(); }
153  const std::vector<int>& dims() const noexcept { return field_meta_info_impl_->dims(); }
155 
157  meta_info_map meta_info() const noexcept {
158  return meta_info_map(field_meta_info_impl_->metaInfoPtr());
159  }
160 
162  friend std::ostream& operator<<(std::ostream& stream, const field_meta_info& f) {
163  return (stream << *f.field_meta_info_impl_);
164  }
165 
167  const std::shared_ptr<FieldMetainfoImpl>& impl() const { return field_meta_info_impl_; }
168 
169 private:
170  std::shared_ptr<FieldMetainfoImpl> field_meta_info_impl_;
171 };
172 
173 } // namespace gridtools
174 
175 } // namespace serialbox
176 
177 #endif
field_meta_info(const std::shared_ptr< FieldMetainfoImpl > &field_meta_info_ptr)
Construct with FieldMetainfoImpl (internal use)
type_id & type() noexcept
Access type_id.
field_meta_info(type_id type, const std::vector< int > &dims, const meta_info_map &meta_info)
Construct field meta-information.
Definition: FieldMetainfo.h:45
bool operator!=(const field_meta_info &right) const noexcept
Test for inequality.
bool operator==(const field_meta_info &right) const noexcept
Test for equality.
field_meta_info(const StorageType &storage)
Construct field meta-information with a gridtools storage.
Definition: FieldMetainfo.h:63
Meta-information of a data field.
void swap(field_meta_info &other) noexcept
Swap with other.
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
const std::shared_ptr< FieldMetainfoImpl > & impl() const
Get implementation pointer.
Meta-information of a data field.
Definition: FieldMetainfo.h:33
std::vector< int > & dims() noexcept
Access dimensions.
Hash-map of meta-information of the form key = value pair or key = {value1, ..., valueN} ...
Definition: MetainfoMap.h:34
meta_info_map meta_info() const noexcept
Access meta-info map.
field_meta_info()
Default constructor.
Definition: FieldMetainfo.h:36
Namespace of the gridtools frontend.
field_meta_info(type_id type, const std::vector< int > &dims)
Construct field meta-information.
Definition: FieldMetainfo.h:54
friend std::ostream & operator<<(std::ostream &stream, const field_meta_info &f)
Convert to stream.
field_meta_info & operator=(const field_meta_info &other)=default
Copy assignment.
Convert C++ type T to TypeID.
Definition: Type.h:130
field_meta_info clone() const
Clone the current field_meta_info object by performing a deep copy.