1 #ifndef CASM_support_container_json_io
2 #define CASM_support_container_json_io
5 #include <unordered_set>
18 template <
typename T,
typename... Args>
26 template <
typename T,
typename... Args>
30 for (
int i = 0; i < json.
size(); i++)
from_json(value[i], json[i], args...);
100 template <
typename K,
typename V>
103 for (
const auto &val : map) {
115 template <
typename K,
typename V>
118 for (
auto it = json.
begin(); it != json.
end(); ++it) {
120 map.emplace(tmp[0].get<K>(), tmp[1].get<V>());
127 template <
typename T,
typename... Args>
130 return json.
put_obj(map.begin(), map.end(), std::forward<Args>(args)...);
136 template <
typename T,
typename... Args>
140 for (
auto it = json.
begin(); it != json.
end(); ++it) {
141 from_json(map[it.name()], *it, std::forward<Args>(args)...);
148 template <
typename T,
typename... Args>
151 return json.
put_array(vec.begin(), vec.end(), std::forward<Args>(args)...);
157 template <
typename T,
typename... Args>
160 vec.reserve(json.
size());
161 for (
auto it = json.
begin(); it != json.
end(); ++it) {
177 template <
typename T>
179 vec.resize(json.
size(), initial);
181 for (
auto it = json.
begin(); it != json.
end(); ++it, ++i) {
189 template <
typename T, std::
size_t N>
191 return json.
put_array(arr.begin(), arr.end());
197 template <
typename T, std::
size_t N>
199 if (json.
size() != N) {
200 std::ostringstream ss;
201 ss <<
"Attempting to to initialize std::array of size " << N
202 <<
" from JSON array of size " << json.
size() <<
":\n " << json
204 throw std::range_error(ss.str());
208 for (
auto it = json.
begin(); it != json.
end(); ++it, ++i) {
216 template <
typename T,
typename Compare>
224 template <
typename T,
typename Compare,
typename... Args>
228 for (
auto it = json.
begin(); it != json.
end(); ++it) {
236 template <
typename T,
typename Compare>
245 template <
typename T,
typename Compare,
typename... Args>
249 for (
auto it = json.
begin(); it != json.
end(); ++it) {
258 template <
typename Derived>
262 for (
int i = 0; i < value.rows(); i++) {
265 for (
int j = 0; j < value.cols(); j++) {
274 template <
typename Derived>
278 if (value.rows() == 1) {
279 for (
int i = 0; i < value.cols(); ++i) {
282 }
else if (value.cols() == 1) {
283 for (
int i = 0; i < value.rows(); ++i) {
287 throw std::runtime_error(
"Error in 'to_json': Not a vector");
293 template <
typename Derived>
297 if (value.rows() == 1) {
298 if (value.cols() == 1) {
303 }
else if (value.cols() == 1) {
312 template <
typename Derived>
320 template <
typename Derived>
330 template <
typename Derived>
334 value.derived().resize(1, 1);
337 value.derived().resize(json.
size(), 1);
338 for (
int i = 0; i < value.rows(); i++) {
342 value.derived().resize(json.
size(), json[0].
size());
343 for (
int i = 0; i < value.rows(); i++) {
344 for (
int j = 0; j < value.cols(); j++) {
Basic std::vector like container (deprecated)
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
iterator end()
Returns iterator to end of JSON object or JSON array.
bool is_array() const
Check if array type.
static jsonParser array()
Returns an empty json array.
jsonParser & put_obj()
Puts new empty JSON object.
jsonParser & put_array()
Puts new empty JSON array.
bool is_number() const
Check if number type (including int)
CASM::jsonParser & to_json_array(const Eigen::MatrixBase< Derived > &value, CASM::jsonParser &json)
Write Eigen Matrix with 1 row or 1 column to JSON array.
jsonParser & push_back(const T &value, Args &&... args)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void from_json(ClexDescription &desc, const jsonParser &json)
INDEX_TYPE Index
For long integer indexing:
Helper struct for constructing objects that need additional data.