openPMD-api
BaseRecordComponent.hpp
1 /* Copyright 2017-2021 Fabian Koller
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * openPMD-api is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 #pragma once
22 
23 #include "openPMD/Dataset.hpp"
24 #include "openPMD/Error.hpp"
25 #include "openPMD/backend/Attributable.hpp"
26 
27 // expose private and protected members for invasive testing
28 #ifndef OPENPMD_protected
29 #define OPENPMD_protected protected:
30 #endif
31 
32 namespace openPMD
33 {
34 namespace internal
35 {
37  {
38  public:
42  Dataset m_dataset{Datatype::UNDEFINED, {}};
49  bool m_isConstant = false;
50 
53 
55  operator=(BaseRecordComponentData const &) = delete;
56  BaseRecordComponentData &operator=(BaseRecordComponentData &&) = delete;
57 
58  BaseRecordComponentData() = default;
59  };
60 } // namespace internal
61 
63 {
64  template <typename T, typename T_key, typename T_container>
65  friend class Container;
66 
67 public:
68  double unitSI() const;
69 
70  BaseRecordComponent &resetDatatype(Datatype);
71 
72  Datatype getDatatype() const;
73 
81  bool constant() const;
82 
100  ChunkTable availableChunks();
101 
102 protected:
103  std::shared_ptr<internal::BaseRecordComponentData>
104  m_baseRecordComponentData{new internal::BaseRecordComponentData()};
105 
106  inline internal::BaseRecordComponentData const &get() const
107  {
108  return *m_baseRecordComponentData;
109  }
110 
112  {
113  return *m_baseRecordComponentData;
114  }
115 
116  inline void setData(std::shared_ptr<internal::BaseRecordComponentData> data)
117  {
118  m_baseRecordComponentData = std::move(data);
119  Attributable::setData(m_baseRecordComponentData);
120  }
121 
122  BaseRecordComponent(std::shared_ptr<internal::BaseRecordComponentData>);
123 
124 private:
126 }; // BaseRecordComponent
127 
128 namespace detail
129 {
138  template <typename T_RecordComponent>
140  {
141  template <typename T>
142  static void call(T_RecordComponent &rc)
143  {
144  rc.makeConstant(T());
145  }
146 
147  template <unsigned n, typename... Args>
148  static void call(Args &&...)
149  {
150  throw std::runtime_error(
151  "makeEmpty: Datatype not supported by openPMD.");
152  }
153  };
154 } // namespace detail
155 } // namespace openPMD
Dataset m_dataset
The type and extent of the dataset defined by this component.
Definition: BaseRecordComponent.hpp:42
Definition: Dataset.hpp:35
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: Container.cpp:51
bool m_isConstant
True if this is defined as a constant record component as specified in the openPMD standard...
Definition: BaseRecordComponent.hpp:49
Public definitions of openPMD-api.
Functor template to be used in combination with switchType::operator() to set a default value for con...
Definition: BaseRecordComponent.hpp:139
Definition: Attributable.hpp:56
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131
Definition: BaseRecordComponent.hpp:36
Definition: BaseRecordComponent.hpp:62
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:93