Warning, file /include/corecel/cont/ArrayIO.json.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <nlohmann/json.hpp>
0010
0011 #include "corecel/Assert.hh"
0012
0013 #include "Array.hh"
0014
0015 namespace celeritas
0016 {
0017
0018
0019
0020
0021 template<class T, size_type N>
0022 void from_json(nlohmann::json const& j, Array<T, N>& value)
0023 {
0024 CELER_VALIDATE(j.size() == N,
0025 << "unexpected array size (" << j.size()
0026 << ") in JSON input: should be " << N);
0027 for (size_type i = 0; i != N; ++i)
0028 {
0029 value[i] = j[i].get<T>();
0030 }
0031 }
0032
0033
0034
0035
0036
0037 template<class T, size_type N>
0038 void to_json(nlohmann::json& j, Array<T, N> const& value)
0039 {
0040 j = nlohmann::json::array();
0041 for (size_type i = 0; i != N; ++i)
0042 {
0043 j.push_back(value[i]);
0044 }
0045 }
0046
0047
0048 }