24 #include "openPMD/IO/AbstractIOHandler.hpp" 25 #include "openPMD/IO/AbstractIOHandlerImpl.hpp" 26 #include "openPMD/IO/Access.hpp" 27 #include "openPMD/IO/JSON/JSONFilePosition.hpp" 28 #include "openPMD/auxiliary/Filesystem.hpp" 29 #include "openPMD/config.hpp" 31 #include <nlohmann/json.hpp> 38 #include <unordered_map> 39 #include <unordered_set> 59 explicit File(std::string s) : fileState{std::make_shared<FileState>(s)}
66 explicit FileState(std::string s) : name{std::move(s)}
73 std::shared_ptr<FileState> fileState;
77 fileState->valid =
false;
82 return fileState->valid;
85 File &operator=(std::string s)
93 fileState = std::make_shared<FileState>(s);
98 bool operator==(
File const &f)
const 100 return this->fileState == f.fileState;
103 std::string &operator*()
const 105 return fileState->name;
108 std::string *operator->()
const 110 return &fileState->name;
113 explicit operator bool()
const 115 return fileState.operator bool();
126 typedef std::size_t result_type;
128 result_type operator()(argument_type
const &s)
const noexcept
130 return std::hash<shared_ptr<openPMD::File::FileState>>{}(s.fileState);
136 void to_json(nlohmann::json &j,
const std::complex<T> &p)
138 j = nlohmann::json{p.real(), p.imag()};
142 void from_json(
const nlohmann::json &j, std::complex<T> &p)
153 using json = nlohmann::json;
174 void availableChunks(
195 void deleteAttribute(
218 std::future<void> flush();
221 using FILEHANDLE = std::fstream;
225 std::unordered_map<Writable *, File> m_files;
227 std::unordered_map<File, std::shared_ptr<nlohmann::json>> m_jsonVals;
230 std::unordered_set<File> m_dirty;
237 std::shared_ptr<FILEHANDLE> getFilehandle(
243 std::string fullPath(
File);
245 std::string fullPath(std::string
const &);
249 static void parentDir(std::string &);
253 static std::string filepositionOf(
Writable *w);
259 template <
typename T,
typename Visitor>
260 static void syncMultidimensionalJson(
262 Offset
const &offset,
263 Extent
const &extent,
264 Extent
const &multiplicator,
267 size_t currentdim = 0);
273 static Extent getMultiplicators(Extent
const &extent);
275 static nlohmann::json initializeNDArray(Extent
const &extent);
277 static Extent getExtent(nlohmann::json &j);
280 static std::string removeSlashes(std::string);
282 template <
typename KeyT>
283 static bool hasKey(nlohmann::json &, KeyT &&key);
287 static void ensurePath(nlohmann::json *json, std::string path);
294 std::tuple<File, std::unordered_map<Writable *, File>::iterator,
bool>
295 getPossiblyExisting(std::string file);
299 std::shared_ptr<nlohmann::json> obtainJsonContents(
File);
302 nlohmann::json &obtainJsonContents(
Writable *writable);
306 void putJsonContents(
File,
bool unsetDirty =
true);
311 std::shared_ptr<JSONFilePosition>
312 setAndGetFilePosition(
Writable *, std::string extend);
317 std::shared_ptr<JSONFilePosition>
318 setAndGetFilePosition(
Writable *,
bool write =
true);
328 static bool isGroup(nlohmann::json::const_iterator it);
330 static bool isDataset(nlohmann::json
const &j);
333 template <
typename Param>
334 void verifyDataset(Param
const ¶meters, nlohmann::json &);
336 static nlohmann::json platformSpecifics();
340 template <
typename T>
342 nlohmann::json &json,
345 static constexpr
char const *errorMsg =
"JSON: writeDataset";
350 template <
typename T>
352 nlohmann::json &json,
355 static constexpr
char const *errorMsg =
"JSON: readDataset";
358 struct AttributeWriter
360 template <
typename T>
361 static void call(nlohmann::json &, Attribute::resource
const &);
363 static constexpr
char const *errorMsg =
"JSON: writeAttribute";
366 struct AttributeReader
368 template <
typename T>
371 static constexpr
char const *errorMsg =
"JSON: writeAttribute";
374 template <
typename T>
377 nlohmann::json operator()(
T const &);
380 template <
typename T>
381 struct CppToJSON<std::vector<T>>
383 nlohmann::json operator()(std::vector<T>
const &);
386 template <
typename T,
int n>
387 struct CppToJSON<std::array<T, n>>
389 nlohmann::json operator()(std::array<T, n>
const &);
392 template <
typename T,
typename Enable = T>
395 T operator()(nlohmann::json
const &);
398 template <
typename T>
399 struct JsonToCpp<std::vector<T>>
401 std::vector<T> operator()(nlohmann::json
const &);
404 template <
typename T,
int n>
405 struct JsonToCpp<std::array<T, n>>
407 std::array<T, n> operator()(nlohmann::json
const &);
410 template <
typename T>
413 typename std::enable_if<std::is_floating_point<T>::value>::type>
415 T operator()(nlohmann::json
const &);
Definition: JSONIOHandlerImpl.hpp:64
Access
File access mode to use during IO.
Definition: Access.hpp:29
Definition: IOTask.hpp:203
Definition: IOTask.hpp:673
Definition: IOTask.hpp:294
Definition: IOTask.hpp:407
Definition: JSONIOHandlerImpl.hpp:57
Definition: IOTask.hpp:148
Definition: JSONIOHandlerImpl.hpp:151
Definition: IOTask.hpp:175
Definition: IOTask.hpp:220
Definition: IOTask.hpp:522
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:179
Public definitions of openPMD-api.
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
Definition: IOTask.hpp:449
Definition: IOTask.hpp:591
Definition: IOTask.hpp:128
Definition: IOTask.hpp:634
Definition: IOTask.hpp:471
Definition: IOTask.hpp:386
Definition: IOTask.hpp:239
Definition: AbstractIOHandlerImpl.hpp:35
Definition: IOTask.hpp:541
Definition: IOTask.hpp:333
Definition: IOTask.hpp:569
Definition: IOTask.hpp:367
Definition: IOTask.hpp:275
Definition: IOTask.hpp:426
Definition: IOTask.hpp:313