|
26 | 26 | #include "openPMD/IO/Access.hpp" |
27 | 27 | #include "openPMD/IO/JSON/JSONFilePosition.hpp" |
28 | 28 | #include "openPMD/auxiliary/Filesystem.hpp" |
| 29 | +#include "openPMD/auxiliary/JSON_internal.hpp" |
29 | 30 | #include "openPMD/config.hpp" |
30 | 31 |
|
| 32 | +#include <istream> |
31 | 33 | #include <nlohmann/json.hpp> |
32 | 34 |
|
33 | 35 | #include <complex> |
@@ -153,7 +155,17 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl |
153 | 155 | using json = nlohmann::json; |
154 | 156 |
|
155 | 157 | public: |
156 | | - explicit JSONIOHandlerImpl(AbstractIOHandler *); |
| 158 | + enum class FileFormat |
| 159 | + { |
| 160 | + Json, |
| 161 | + Toml |
| 162 | + }; |
| 163 | + |
| 164 | + explicit JSONIOHandlerImpl( |
| 165 | + AbstractIOHandler *, |
| 166 | + openPMD::json::TracingJSON config, |
| 167 | + FileFormat, |
| 168 | + std::string originalExtension); |
157 | 169 |
|
158 | 170 | ~JSONIOHandlerImpl() override; |
159 | 171 |
|
@@ -229,15 +241,25 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl |
229 | 241 | // files that have logically, but not physically been written to |
230 | 242 | std::unordered_set<File> m_dirty; |
231 | 243 |
|
| 244 | + /* |
| 245 | + * Is set by constructor. |
| 246 | + */ |
| 247 | + FileFormat m_fileFormat{}; |
| 248 | + |
| 249 | + std::string m_originalExtension; |
| 250 | + |
232 | 251 | // HELPER FUNCTIONS |
233 | 252 |
|
234 | | - // will use the IOHandler to retrieve the correct directory |
235 | | - // shared pointer to circumvent the fact that c++ pre 17 does |
236 | | - // not enforce (only allow) copy elision in return statements |
237 | | - std::shared_ptr<FILEHANDLE> getFilehandle( |
238 | | - File, |
239 | | - Access access); //, Access |
240 | | - // m_frontendAccess=this->m_handler->m_frontendAccess); |
| 253 | + // will use the IOHandler to retrieve the correct directory. |
| 254 | + // first tuple element will be the underlying opened file handle. |
| 255 | + // if Access is read mode, then the second tuple element will be the istream |
| 256 | + // casted to precision std::numeric_limits<double>::digits10 + 1, else null. |
| 257 | + // if Access is write mode, then the second tuple element will be the |
| 258 | + // ostream casted to precision std::numeric_limits<double>::digits10 + 1, |
| 259 | + // else null. first tuple element needs to be a pointer, since the casted |
| 260 | + // streams are references only. |
| 261 | + std::tuple<std::unique_ptr<FILEHANDLE>, std::istream *, std::ostream *> |
| 262 | + getFilehandle(File, Access access); |
241 | 263 |
|
242 | 264 | // full operating system path of the given file |
243 | 265 | std::string fullPath(File); |
@@ -272,15 +294,13 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl |
272 | 294 | // essentially: m_i = \prod_{j=0}^{i-1} extent_j |
273 | 295 | static Extent getMultiplicators(Extent const &extent); |
274 | 296 |
|
275 | | - static nlohmann::json initializeNDArray(Extent const &extent); |
276 | | - |
277 | 297 | static Extent getExtent(nlohmann::json &j); |
278 | 298 |
|
279 | 299 | // remove single '/' in the beginning and end of a string |
280 | 300 | static std::string removeSlashes(std::string); |
281 | 301 |
|
282 | 302 | template <typename KeyT> |
283 | | - static bool hasKey(nlohmann::json &, KeyT &&key); |
| 303 | + static bool hasKey(nlohmann::json const &, KeyT &&key); |
284 | 304 |
|
285 | 305 | // make sure that the given path exists in proper form in |
286 | 306 | // the passed json value |
@@ -366,7 +386,8 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl |
366 | 386 | struct AttributeReader |
367 | 387 | { |
368 | 388 | template <typename T> |
369 | | - static void call(nlohmann::json &, Parameter<Operation::READ_ATT> &); |
| 389 | + static void |
| 390 | + call(nlohmann::json const &, Parameter<Operation::READ_ATT> &); |
370 | 391 |
|
371 | 392 | static constexpr char const *errorMsg = "JSON: writeAttribute"; |
372 | 393 | }; |
|
0 commit comments