openPMD-api
BaseRecordComponent.hpp
1 /* Copyright 2017-2020 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< typename T_elem >
37  friend
38  class BaseRecord;
39 
40  template<
41  typename T,
42  typename T_key,
43  typename T_container
44  >
45  friend
46  class Container;
47 
48 public:
49  ~BaseRecordComponent() override = default;
50 
51  double unitSI() const;
52 
53  BaseRecordComponent& resetDatatype(Datatype);
54 
55  Datatype getDatatype() const;
56 
57 OPENPMD_protected:
59 
60  std::shared_ptr< Dataset > m_dataset;
61  std::shared_ptr< bool > m_isConstant;
62 }; // BaseRecordComponent
63 
64 namespace detail
65 {
74 template< typename T_RecordComponent >
76 {
77  template< typename T >
78  void
79  operator()( T_RecordComponent & rc )
80  {
81  rc.makeConstant( T() );
82  }
83 
84  template< unsigned n, typename... Args >
85  void
86  operator()( Args &&... )
87  {
88  throw std::runtime_error(
89  "makeEmpty: Datatype not supported by openPMD." );
90  }
91 };
92 } // namespace detail
93 } // namespace openPMD
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:38
Definition: Container.cpp:51
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:75
Definition: BaseRecord.hpp:36
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:70
Definition: BaseRecordComponent.hpp:34
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:65