openPMD-api
Record.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/RecordComponent.hpp"
24 #include "openPMD/backend/BaseRecord.hpp"
25 
26 #include <map>
27 #include <string>
28 #include <type_traits>
29 
30 namespace openPMD
31 {
32 class Record : public BaseRecord<RecordComponent>
33 {
34  friend class Container<Record>;
35  friend class Iteration;
36  friend class ParticleSpecies;
37 
38 public:
39  Record(Record const &) = default;
40  Record &operator=(Record const &) = default;
41  ~Record() override = default;
42 
43  Record &setUnitDimension(std::map<UnitDimension, double> const &);
44 
45  template <typename T>
46  T timeOffset() const;
47  template <typename T>
48  Record &setTimeOffset(T);
49 
50 private:
51  Record();
52 
53  void
54  flush_impl(std::string const &, internal::FlushParams const &) override;
55  void read() override;
56 }; // Record
57 
58 template <typename T>
59 inline T Record::timeOffset() const
60 {
61  return readFloatingpoint<T>("timeOffset");
62 }
63 
64 template <typename T>
65 inline Record &Record::setTimeOffset(T to)
66 {
67  static_assert(
68  std::is_floating_point<T>::value,
69  "Type of attribute must be floating point");
70 
71  setAttribute("timeOffset", to);
72  return *this;
73 }
74 } // namespace openPMD
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:126
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:402
Public definitions of openPMD-api.
Definition: Record.hpp:32
Definition: BaseRecord.hpp:58
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:84
Definition: ParticleSpecies.hpp:33
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131