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;
172 void availableChunks(
193 void deleteAttribute(
213 std::future<void> flush();
216 using FILEHANDLE = std::fstream;
220 std::unordered_map<Writable *, File> m_files;
222 std::unordered_map<File, std::shared_ptr<nlohmann::json>> m_jsonVals;
225 std::unordered_set<File> m_dirty;
232 std::shared_ptr<FILEHANDLE> getFilehandle(
238 std::string fullPath(
File);
240 std::string fullPath(std::string
const &);
244 static void parentDir(std::string &);
248 static std::string filepositionOf(
Writable *w);
254 template <
typename T,
typename Visitor>
255 static void syncMultidimensionalJson(
257 Offset
const &offset,
258 Extent
const &extent,
259 Extent
const &multiplicator,
262 size_t currentdim = 0);
268 static Extent getMultiplicators(Extent
const &extent);
270 static nlohmann::json initializeNDArray(Extent
const &extent);
272 static Extent getExtent(nlohmann::json &j);
275 static std::string removeSlashes(std::string);
277 template <
typename KeyT>
278 static bool hasKey(nlohmann::json &, KeyT &&key);
282 static void ensurePath(nlohmann::json *json, std::string path);
289 std::tuple<File, std::unordered_map<Writable *, File>::iterator,
bool>
290 getPossiblyExisting(std::string file);
294 std::shared_ptr<nlohmann::json> obtainJsonContents(
File);
297 nlohmann::json &obtainJsonContents(
Writable *writable);
301 void putJsonContents(
File,
bool unsetDirty =
true);
306 std::shared_ptr<JSONFilePosition>
307 setAndGetFilePosition(
Writable *, std::string extend);
312 std::shared_ptr<JSONFilePosition>
313 setAndGetFilePosition(
Writable *,
bool write =
true);
323 static bool isGroup(nlohmann::json::const_iterator it);
325 static bool isDataset(nlohmann::json
const &j);
328 template <
typename Param>
329 void verifyDataset(Param
const ¶meters, nlohmann::json &);
331 static nlohmann::json platformSpecifics();
335 template <
typename T>
337 nlohmann::json &json,
340 std::string errorMsg =
"JSON: writeDataset";
345 template <
typename T>
347 nlohmann::json &json,
350 std::string errorMsg =
"JSON: readDataset";
353 struct AttributeWriter
355 template <
typename T>
356 void operator()(nlohmann::json &, Attribute::resource
const &);
358 std::string errorMsg =
"JSON: writeAttribute";
361 struct AttributeReader
363 template <
typename T>
366 std::string errorMsg =
"JSON: writeAttribute";
369 template <
typename T>
372 nlohmann::json operator()(
T const &);
375 template <
typename T>
376 struct CppToJSON<std::vector<T>>
378 nlohmann::json operator()(std::vector<T>
const &);
381 template <
typename T,
int n>
382 struct CppToJSON<std::array<T, n>>
384 nlohmann::json operator()(std::array<T, n>
const &);
387 template <
typename T,
typename Enable = T>
390 T operator()(nlohmann::json
const &);
393 template <
typename T>
394 struct JsonToCpp<std::vector<T>>
396 std::vector<T> operator()(nlohmann::json
const &);
399 template <
typename T,
int n>
400 struct JsonToCpp<std::array<T, n>>
402 std::array<T, n> operator()(nlohmann::json
const &);
405 template <
typename T>
408 typename std::enable_if<std::is_floating_point<T>::value>::type>
410 T operator()(nlohmann::json
const &);
Definition: JSONIOHandlerImpl.hpp:64
Access
File access mode to use during IO.
Definition: Access.hpp:27
Definition: IOTask.hpp:144
Definition: IOTask.hpp:230
Definition: IOTask.hpp:333
Definition: JSONIOHandlerImpl.hpp:57
Definition: JSONIOHandlerImpl.hpp:151
Definition: IOTask.hpp:120
Definition: IOTask.hpp:159
Definition: IOTask.hpp:471
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:122
Public definitions of openPMD-api.
Definition: Date.cpp:28
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:63
Definition: IOTask.hpp:384
Definition: IOTask.hpp:543
Definition: IOTask.hpp:101
Definition: IOTask.hpp:584
Definition: IOTask.hpp:418
Definition: IOTask.hpp:313
Definition: IOTask.hpp:176
Definition: AbstractIOHandlerImpl.hpp:35
Definition: IOTask.hpp:488
Definition: IOTask.hpp:265
Definition: IOTask.hpp:511
Definition: IOTask.hpp:296
Definition: IOTask.hpp:213
Definition: IOTask.hpp:350
Definition: IOTask.hpp:247