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/backend/Attributable.hpp"
24 #include "openPMD/Dataset.hpp"
25 
26 // expose private and protected members for invasive testing
27 #ifndef OPENPMD_protected
28 # define OPENPMD_protected protected
29 #endif
30 
31 
32 namespace openPMD
33 {
35 {
36  template<
37  typename T,
38  typename T_key,
39  typename T_container
40  >
41  friend
42  class Container;
43 
44 public:
45  ~BaseRecordComponent() = default;
46 
47  double unitSI() const;
48 
49  BaseRecordComponent& resetDatatype(Datatype);
50 
51  Datatype getDatatype() const;
52 
60  bool constant() const;
61 
79  ChunkTable
81 
82  OPENPMD_protected : BaseRecordComponent();
83 
84  std::shared_ptr< Dataset > m_dataset;
85  std::shared_ptr< bool > m_isConstant;
86 }; // BaseRecordComponent
87 
88 namespace detail
89 {
98 template< typename T_RecordComponent >
100 {
101  template< typename T >
102  void
103  operator()( T_RecordComponent & rc )
104  {
105  rc.makeConstant( T() );
106  }
107 
108  template< unsigned n, typename... Args >
109  void
110  operator()( Args &&... )
111  {
112  throw std::runtime_error(
113  "makeEmpty: Datatype not supported by openPMD." );
114  }
115 };
116 } // namespace detail
117 } // namespace openPMD
openPMD::Datatype
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
openPMD::LegacyAttributable
Definition: Attributable.hpp:401
openPMD::UnitDimension::T
@ T
time
openPMD
Public definitions of openPMD-api.
Definition: Date.cpp:29
openPMD::Container
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:106
openPMD::detail::DefaultValue
Functor template to be used in combination with switchType::operator() to set a default value for con...
Definition: BaseRecordComponent.hpp:99
openPMD::BaseRecordComponent
Definition: BaseRecordComponent.hpp:34
openPMD::BaseRecordComponent::availableChunks
ChunkTable availableChunks()
Get data chunks that are available to be loaded from the backend.
Definition: BaseRecordComponent.cpp:60
openPMD::BaseRecordComponent::constant
bool constant() const
Returns true if this is a constant record component.
Definition: BaseRecordComponent.cpp:54