openPMD-api
Snapshots.hpp
1 /* Copyright 2024 Franz Poeschel
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/snapshots/ContainerTraits.hpp"
25 #include <memory>
26 #include <optional>
27 #include <utility>
28 
29 namespace openPMD
30 {
49 class Snapshots : public Attributable
50 {
51 private:
52  friend class Series;
53 
54  std::shared_ptr<AbstractSnapshotsContainer> m_snapshots;
55 
56  Snapshots(
57  std::shared_ptr<AbstractSnapshotsContainer> snapshots,
58  Attributable &iterations);
59 
60  inline auto get() const -> AbstractSnapshotsContainer const &;
61  inline auto get() -> AbstractSnapshotsContainer &;
62 
63 public:
64  using key_type = AbstractSnapshotsContainer::key_type;
65  using value_type = AbstractSnapshotsContainer::value_type;
69  // since AbstractSnapshotsContainer abstracts away the specific mode of
70  // iteration, these are the same type
74  using size_type = AbstractSnapshotsContainer::size_type;
75 
83  auto currentIteration() -> std::optional<value_type *>;
84  auto currentIteration() const -> std::optional<value_type const *>;
85 
86  auto begin() -> iterator;
87  auto end() -> iterator;
90  auto begin() const -> const_iterator;
93  auto end() const -> const_iterator;
97  auto rbegin() -> reverse_iterator;
101  auto rend() -> reverse_iterator;
105  auto rbegin() const -> const_reverse_iterator;
109  auto rend() const -> const_reverse_iterator;
110 
114  auto empty() const -> bool;
119  auto size() const -> size_t;
120 
123  auto at(key_type const &key) const -> mapped_type const &;
126  auto at(key_type const &key) -> mapped_type &;
127 
128  auto operator[](key_type const &key) -> mapped_type &;
129 
132  auto clear() -> void;
133 
134  // insert
135  // swap
136 
142  auto find(key_type const &key) -> iterator;
150  auto find(key_type const &key) const -> const_iterator;
151 
154  auto count(key_type const &key) const -> size_t;
155 
158  auto contains(key_type const &key) const -> bool;
159 
160  auto erase(key_type const &key) -> size_type;
161  auto erase(iterator) -> iterator;
162 
163  /* Does not really emplace since we need to forward to abstract
164  * implementations and can hence not work with templates. */
165  template <typename... Args>
166  auto emplace(Args &&...args) -> std::pair<iterator, bool>
167  {
168  return m_snapshots->emplace({args...});
169  }
170 
171  auto snapshotWorkflow() const -> SnapshotWorkflow;
172 };
173 
174 // backwards compatibility
175 using WriteIterations = Snapshots;
176 } // namespace openPMD
Definition: ContainerTraits.hpp:118
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:222
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:146
Counterpart to Snapshots class: Iterator type that can wrap different implementations internally.
Definition: ContainerTraits.hpp:43
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:288
Entry point for accessing Snapshots/Iterations.
Definition: Snapshots.hpp:50
auto size() const -> size_t
Not implemented in synchronous workflow due to unclear semantics (past Iterations should not be consi...
Definition: Snapshots.cpp:95
auto count(key_type const &key) const -> size_t
Implemented in terms of contains(), see there.
Definition: Snapshots.cpp:127
auto contains(key_type const &key) const -> bool
Not implmented in synchronous workflow.
Definition: Snapshots.cpp:132
auto at(key_type const &key) const -> mapped_type const &
Select an Iteration within the current IO step.
Definition: Snapshots.cpp:100
auto find(key_type const &key) -> iterator
Not implmented in synchronous workflow.
Definition: Snapshots.cpp:118
auto rbegin() -> reverse_iterator
Not implemented for synchronous workflow: Reverse iteration not possible.
Definition: Snapshots.cpp:73
auto rend() -> reverse_iterator
Not implemented for synchronous workflow: Reverse iteration not possible.
Definition: Snapshots.cpp:77
auto clear() -> void
Not implmented in synchronous workflow.
Definition: Snapshots.cpp:113
auto empty() const -> bool
In synchronous workflow, this tells if there are remaining Iterations or not.
Definition: Snapshots.cpp:91
auto currentIteration() -> std::optional< value_type * >
The currently active Iteration.
Definition: Snapshots.cpp:48
Public definitions of openPMD-api.
Definition: Date.cpp:29
SnapshotWorkflow
Enum used as a label for distinguishing the different Snapshots implementations.
Definition: ContainerTraits.hpp:109