1 #ifndef CASM_jsonIO_container
2 #define CASM_jsonIO_container
92 return json.
put_obj(map.begin(), map.end());
101 for(
auto it = json.
begin(); it != json.
end(); ++it) {
111 return json.
put_array(vec.begin(), vec.end());
119 vec.resize(json.
size());
121 for(
auto it = json.
begin(); it != json.
end(); ++it, ++i) {
129 template<
typename T, std::
size_t N>
131 return json.
put_array(arr.begin(), arr.end());
137 template<
typename T, std::
size_t N>
139 if(json.
size() != N) {
140 std::ostringstream ss;
141 ss <<
"Attempting to to initialize std::array of size " << N <<
" from JSON array of size " << json.
size() <<
":\n " << json <<
"\n\n";
142 throw std::range_error(ss.str());
146 for(
auto it = json.
begin(); it != json.
end(); ++it, ++i) {
154 template<
typename T,
typename Compare>
156 return json.
put_array(set.begin(), set.end());
162 template<
typename T,
typename Compare,
typename...Args>
165 for(
auto it = json.
begin(); it != json.
end(); ++it) {
174 template <
typename Derived>
177 for(
int i = 0; i < value.rows(); i++) {
180 for(
int j = 0; j < value.cols(); j++) {
190 template <
typename Derived>
193 if(value.rows() == 1) {
194 for(
int i = 0; i < value.cols(); ++i) {
198 else if(value.cols() == 1) {
199 for(
int i = 0; i < value.rows(); ++i) {
204 throw std::runtime_error(
"Error in 'to_json_array': Not a vector");
212 template <
typename Derived>
215 value.derived().resize(json.
size(), 1);
216 for(
int i = 0; i < value.rows(); i++) {
221 value.derived().resize(json.
size(), json[0].
size());
222 for(
int i = 0; i < value.rows(); i++) {
223 for(
int j = 0; j < value.cols(); j++) {
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
void from_json(ClexDescription &desc, const jsonParser &json)
iterator end()
Returns iterator to end of JSON object or JSON array.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
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.
Helper struct for constructing objects that need additional data.
jsonParser & put_obj()
Puts new empty JSON object.
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
bool is_array() const
Check if array type.
jsonParser & put_array()
Puts new empty JSON array.