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/backend/Attributable.hpp"
25 
26 // expose private and protected members for invasive testing
27 #ifndef OPENPMD_protected
28 #define OPENPMD_protected protected
29 #endif
30 
31 namespace openPMD
32 {
34 {
35  template <typename T, typename T_key, typename T_container>
36  friend class Container;
37 
38 public:
39  ~BaseRecordComponent() = default;
40 
41  double unitSI() const;
42 
43  BaseRecordComponent &resetDatatype(Datatype);
44 
45  Datatype getDatatype() const;
46 
54  bool constant() const;
55 
73  ChunkTable availableChunks();
74 
75  OPENPMD_protected : BaseRecordComponent();
76 
77  std::shared_ptr<Dataset> m_dataset;
78  std::shared_ptr<bool> m_isConstant;
79 }; // BaseRecordComponent
80 
81 namespace detail
82 {
91  template <typename T_RecordComponent>
92  struct DefaultValue
93  {
94  template <typename T>
95  void operator()(T_RecordComponent &rc)
96  {
97  rc.makeConstant(T());
98  }
99 
100  template <unsigned n, typename... Args>
101  void operator()(Args &&...)
102  {
103  throw std::runtime_error(
104  "makeEmpty: Datatype not supported by openPMD.");
105  }
106  };
107 } // namespace detail
108 } // namespace openPMD
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: Container.cpp:50
Public definitions of openPMD-api.
Definition: Date.cpp:28
Functor template to be used in combination with switchType::operator() to set a default value for con...
Definition: BaseRecordComponent.hpp:92
ChunkTable availableChunks()
Get data chunks that are available to be loaded from the backend.
Definition: BaseRecordComponent.cpp:57
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:105
bool constant() const
Returns true if this is a constant record component.
Definition: BaseRecordComponent.cpp:52
Definition: Attributable.hpp:444
Definition: BaseRecordComponent.hpp:33