openPMD-api
 
Loading...
Searching...
No Matches
Writable.hpp
1/* Copyright 2017-2025 Fabian Koller, Axel Huebl, Franz Poeschel, Luca Fedeli
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/IO/AbstractIOHandler.hpp"
24
25#include <memory>
26#include <string>
27#include <vector>
28
29// expose private and protected members for invasive testing
30#ifndef OPENPMD_private
31#define OPENPMD_private private:
32#endif
33
34namespace openPMD
35{
36namespace test
37{
38 struct TestHelper;
39} // namespace test
43template <typename FilePositionType>
45template <typename>
46class Span;
47class Series;
48
49namespace internal
50{
52 class AttributableData;
53 class SeriesData;
54} // namespace internal
55namespace detail
56{
57 class ADIOS2File;
58}
59
60namespace debug
61{
62 void printDirty(Series const &);
63}
64
75class Writable final
76{
78 friend class internal::AttributableData;
79 friend class internal::SeriesData;
80 friend class Attributable;
81 template <typename T_elem>
82 friend class BaseRecord;
83 template <typename T_elem>
84 friend class BaseRecordInterface;
85 template <typename T, typename T_key, typename T_container>
86 friend class Container;
87 friend class Iteration;
88 friend class Mesh;
89 friend class ParticleSpecies;
90 friend class Series;
91 friend class Record;
92 friend class RecordComponent;
93 friend class AbstractIOHandlerImpl;
94 friend class ADIOS2IOHandlerImpl;
95 friend class detail::ADIOS2File;
96 friend class HDF5IOHandlerImpl;
97 friend class ParallelHDF5IOHandlerImpl;
98 template <typename>
99 friend class AbstractIOHandlerImplCommon;
100 friend class JSONIOHandlerImpl;
101 friend struct test::TestHelper;
102 friend std::string concrete_h5_file_position(Writable *);
103 friend std::string concrete_bp1_file_position(Writable *);
104 template <typename>
105 friend class Span;
106 friend void debug::printDirty(Series const &);
107 friend struct Parameter<Operation::CREATE_DATASET>;
108 friend struct Parameter<Operation::OPEN_DATASET>;
109
110private:
111 Writable(internal::AttributableData *);
112
113public:
114 ~Writable();
115
116 Writable(Writable const &other) = delete;
117 Writable(Writable &&other) = delete;
118 Writable &operator=(Writable const &other) = delete;
119 Writable &operator=(Writable &&other) = delete;
120
128 template <bool flush_entire_series>
129 void seriesFlush(std::string backendConfig = "{}");
130
131 // clang-format off
132OPENPMD_private
133 // clang-format on
134
135 template <bool flush_entire_series>
136 void seriesFlush(internal::FlushParams const &);
137 /*
138 * These members need to be shared pointers since distinct instances of
139 * Writable may share them.
140 */
141 std::shared_ptr<AbstractFilePosition> abstractFilePosition = nullptr;
142 /*
143 * shared_ptr since the IOHandler is shared by multiple Writable instances.
144 * optional to make it possible to release the IOHandler, without first
145 * having to destroy every single Writable.
146 * unique_ptr since AbstractIOHandler is an abstract class.
147 */
148 std::shared_ptr<std::optional<std::unique_ptr<AbstractIOHandler>>>
149 IOHandler = nullptr;
150 /*
151 * Link to the containing Attributable.
152 * If multiple Attributables share the same Writable, then the creating one.
153 * (See SharedAttributableData)
154 */
155 internal::AttributableData *attributable = nullptr;
156 Writable *parent = nullptr;
157
162 bool dirtySelf = true;
175 bool dirtyRecursive = true;
180 std::string ownKeyWithinParent;
196 bool written = false;
197};
198} // namespace openPMD
Definition AbstractFilePosition.hpp:26
Interface for communicating between logical and physically persistent data.
Definition AbstractIOHandler.hpp:206
Definition AbstractIOHandlerImplCommon.hpp:40
Implementation for the root level of the openPMD hierarchy.
Definition Series.hpp:288
Subset of C++20 std::span class template.
Definition Span.hpp:38
void seriesFlush(std::string backendConfig="{}")
Flush the corresponding Series object.
Definition Writable.cpp:55
Definition ADIOS2File.hpp:143
Definition Attributable.hpp:107
Data members for Series.
Definition Series.hpp:90
Definition Attributable.hpp:62
Public definitions of openPMD-api.
Definition Date.cpp:29
Definition ADIOS2FilePosition.hpp:31
Typesafe description of all required arguments for a specified Operation.
Definition IOTask.hpp:148