CASM  1.1.0
A Clusters Approach to Statistical Mechanics
jsonParser.hh
Go to the documentation of this file.
1 #ifndef CASM_JSONPARSER_HH
2 #define CASM_JSONPARSER_HH
3 
4 #include <complex>
5 #include <exception>
6 
7 #include "casm/external/json_spirit/json_spirit_reader_template.h"
8 #include "casm/external/json_spirit/json_spirit_writer_template.h"
9 #include "casm/misc/CASM_TMP.hh"
10 
11 namespace boost {
12 namespace filesystem {
13 class path;
14 }
15 } // namespace boost
16 
17 namespace CASM {
18 
19 namespace fs = boost::filesystem;
20 
21 template <bool IsConst>
22 class jsonParserIterator;
23 
85 class jsonParser : public json_spirit::mValue {
86  public:
90 
91  // ---- Constructors ----------------------------------
92 
94  jsonParser() : json_spirit::mValue(json_spirit::mObject()) {}
95 
101  template <typename T>
102  explicit jsonParser(T &t) {
103  to_json(t, *this);
104  }
105 
111  template <typename T>
112  explicit jsonParser(const T &t) {
113  to_json(t, *this);
114  }
115 
118  struct as_array {};
119 
123  struct as_flattest {};
124 
125  // ---- Read/Print JSON ----------------------------------
126 
128  bool read(std::istream &stream);
129 
131  bool read(const boost::filesystem::path &mypath);
132 
134  void print(std::ostream &stream, unsigned int indent = 2,
135  unsigned int prec = 12) const;
136 
138  void write(const std::string &file_name, unsigned int indent = 2,
139  unsigned int prec = 12) const;
140 
142  void write(const boost::filesystem::path &mypath, unsigned int indent = 2,
143  unsigned int prec = 12) const;
144 
145  // ---- Value level printing options: ---------------------
146 
148  using json_spirit::mValue::set_force_column;
149 
151  using json_spirit::mValue::set_force_row;
152 
154  using json_spirit::mValue::set_scientific;
155 
157  using json_spirit::mValue::set_remove_trailing_zeros;
158 
160  using json_spirit::mValue::unset_force_column;
161 
163  using json_spirit::mValue::unset_force_row;
164 
166  using json_spirit::mValue::unset_scientific;
167 
169  using json_spirit::mValue::unset_remove_trailing_zeros;
170 
171  using json_spirit::mValue::operator==;
172 
173  bool operator!=(const jsonParser &json) const {
174  return !(json_spirit::mValue::operator==(json));
175  }
176 
177  bool almost_equal(const jsonParser &B, double tol) const;
178 
179  // ------ Type Checking Methods ------------------------------------
180 
181  bool is_null() const;
182  bool is_bool() const;
183  bool is_int() const;
184  bool is_float() const;
185  bool is_number() const;
186  bool is_string() const;
187  bool is_obj() const;
188  bool is_array() const;
189 
190  // ---- Navigate the JSON data: ----------------------------
191 
196  jsonParser &operator[](const std::string &name);
197 
201  const jsonParser &operator[](const std::string &name) const;
202 
210  jsonParser &at(const fs::path &path);
211 
219  const jsonParser &at(const fs::path &path) const;
220 
223  jsonParser &operator[](const size_type &element);
224 
227  const jsonParser &operator[](const size_type &element) const;
228 
231  jsonParser &at(const size_type &element);
232 
235  const jsonParser &at(const size_type &element) const;
236 
239  size_type size() const;
240 
242  iterator begin();
243 
245  const_iterator begin() const;
246 
248  iterator end();
249 
251  const_iterator end() const;
252 
254  const_iterator cbegin() const;
255 
257  const_iterator cend() const;
258 
260  iterator find(const std::string &name);
261 
263  const_iterator find(const std::string &name) const;
264 
266  jsonParser::iterator find_at(const fs::path &path);
267 
269  jsonParser::const_iterator find_at(const fs::path &path) const;
270 
272  bool contains(const std::string &name) const;
273 
275  size_type erase(const std::string &name);
276 
277  // ---- Data-retrieval Methods -----------------------------------------
278 
280  template <typename T, typename... Args>
281  T get(Args &&... args) const;
282 
286  template <typename T, typename... Args>
287  void get(T &t, Args &&... args) const;
288 
291  template <typename T, typename... Args>
292  bool get_if(T &t, const std::string &key, Args &&... args) const;
293 
296  template <typename T, typename... Args>
297  T get_if_else(const std::string &key, const T &default_value,
298  Args &&... args) const;
299 
302  template <typename T, typename... Args>
303  bool get_else(T &t, const std::string &key, const T &default_value,
304  Args &&... args) const;
305 
307  template <typename T, typename... Args>
308  std::unique_ptr<T> make(Args &&... args) const;
309 
311  template <typename T, typename... Args>
312  void make(std::unique_ptr<T> &ptr, Args &&... args) const;
313 
315  template <typename T, typename... Args>
316  bool make_if(std::unique_ptr<T> &ptr, const std::string &key,
317  Args &&... args) const;
318 
320  template <typename T, typename... Args>
321  std::unique_ptr<T> make_optional(const std::string &key,
322  Args &&... args) const;
323 
325  template <typename T, typename... Args>
326  std::unique_ptr<T> make_if_else(const std::string &key,
327  std::unique_ptr<T> default_value,
328  Args &&... args) const;
329 
331  template <typename T, typename... Args>
332  bool make_else(std::unique_ptr<T> &ptr, const std::string &key,
333  std::unique_ptr<T> default_value, Args &&... args) const;
334 
335  // ---- Data addition Methods (Overwrites any existing data with same 'name')
336  // ---
337 
340  template <typename T>
341  jsonParser &operator=(const T &value);
342 
345  template <typename T, typename... Args>
346  jsonParser &push_back(const T &value, Args &&... args);
347 
350  template <typename T>
351  jsonParser &put(const T &value);
352 
354  jsonParser &put_obj() { return *this = object(); }
355 
358  template <typename Iterator>
359  jsonParser &put_obj(Iterator begin, Iterator end);
360 
362  jsonParser &put_array() { return *this = array(); }
363 
365  jsonParser &put_array(size_type N) { return *this = array(N); }
366 
368  template <typename T>
369  jsonParser &put_array(size_type N, const T &t);
370 
372  template <typename Iterator, typename... Args,
374  jsonParser &put_array(Iterator begin, Iterator end, Args &&... args);
375 
377  jsonParser &put_null() { return *this = null(); }
378 
379  // ---- static Methods -------------------------------------
380 
382  static jsonParser parse(const std::string &str) {
383  std::stringstream ss;
384  ss << str;
385  return jsonParser(ss);
386  }
387 
389  static jsonParser parse(const fs::path &path);
390 
392  static jsonParser parse(std::istream &stream) { return jsonParser(stream); }
393 
395  static jsonParser object() {
396  jsonParser json;
397  return json = json_spirit::mValue(json_spirit::mObject());
398  }
399 
402  template <typename Iterator>
403  static jsonParser object(Iterator begin, Iterator end) {
404  jsonParser json;
405  return json.put_obj(begin, end);
406  }
407 
409  static jsonParser array() {
410  jsonParser json;
411  return json = json_spirit::mValue(json_spirit::mArray());
412  }
413 
416  jsonParser json;
417  return json = json_spirit::mValue(json_spirit::mArray(N));
418  }
419 
421  template <typename T>
422  static jsonParser array(size_type N, const T &t) {
423  jsonParser json;
424  return json.put_array(N, t);
425  }
426 
428  template <typename Iterator>
430  Iterator begin, Iterator end,
431  typename CASM_TMP::enable_if_iterator<Iterator>::type * = nullptr) {
432  jsonParser json;
433  return json.put_array(begin, end);
434  }
435 
437  static jsonParser null() {
438  jsonParser json;
439  return json = json_spirit::mValue();
440  }
441 
442  private:
443  jsonParser &operator=(const json_spirit::mValue &value) {
444  this->json_spirit::mValue::operator=(value);
445  return *this;
446  }
447 };
448 
449 std::ostream &operator<<(std::ostream &stream, const jsonParser &json);
450 std::istream &operator>>(std::istream &stream, jsonParser &json);
451 
453 jsonParser &to_json(bool value, jsonParser &json);
454 jsonParser &to_json(int value, jsonParser &json);
455 jsonParser &to_json(unsigned int value, jsonParser &json);
456 jsonParser &to_json(long int value, jsonParser &json);
457 jsonParser &to_json(unsigned long int value, jsonParser &json);
458 jsonParser &to_json(double value, jsonParser &json);
459 jsonParser &to_json(const std::string &value, jsonParser &json);
460 jsonParser &to_json(const char *value, jsonParser &json);
461 jsonParser &to_json(const jsonParser &value, jsonParser &json);
462 
464 template <typename T>
465 T from_json(const jsonParser &json);
466 
468 template <typename T>
469 std::unique_ptr<T> make_from_json(const jsonParser &json);
470 
471 template <>
472 bool from_json<bool>(const jsonParser &json);
473 template <>
474 int from_json<int>(const jsonParser &json);
475 template <>
476 unsigned int from_json<unsigned int>(const jsonParser &json);
477 template <>
478 long int from_json<long int>(const jsonParser &json);
479 template <>
480 unsigned long int from_json<unsigned long int>(const jsonParser &json);
481 template <>
482 double from_json<double>(const jsonParser &json);
483 template <>
484 std::string from_json<std::string>(const jsonParser &json);
485 template <>
486 jsonParser from_json<jsonParser>(const jsonParser &json);
487 
489 void from_json(bool &value, const jsonParser &json);
490 void from_json(int &value, const jsonParser &json);
491 void from_json(unsigned int &value, const jsonParser &json);
492 void from_json(long int &value, const jsonParser &json);
493 void from_json(unsigned long int &value, const jsonParser &json);
494 void from_json(double &value, const jsonParser &json);
495 void from_json(std::string &value, const jsonParser &json);
496 void from_json(jsonParser &value, const jsonParser &json);
497 void from_json(std::istream &stream, const jsonParser &json);
498 void from_json(fs::path &value, const jsonParser &json);
499 
501 inline void to_json(std::istream &stream, jsonParser &json) {
502  if (!json.read(stream)) {
503  throw std::runtime_error(
504  std::string("ERROR: Could not read JSON. Please check your formatting. "
505  "For instance, try http://www.jsoneditoronline.org."));
506  }
507 }
508 
510 void to_json(fs::path file_path, jsonParser &json);
511 
513 template <typename T>
514 jsonParser &to_json(const std::complex<T> &value, jsonParser &json) {
515  json = jsonParser::object();
516  json["real"] = value.real();
517  json["imag"] = value.imag();
518  return json;
519 }
520 
522 template <typename T>
523 void from_json(std::complex<T> &value, const jsonParser &json) {
524  try {
525  value = std::complex<T>(json["real"].get<T>(), json["imag"].get<T>());
526  } catch (...) {
528  throw;
529  }
530 }
531 
533 template <typename Key, typename T>
534 jsonParser &to_json(const std::pair<Key, T> &value, jsonParser &json);
535 
537 template <typename Key, typename T>
538 void from_json(std::pair<Key, T> &value, const jsonParser &json);
539 
547 template <typename ReturnType>
551  static ReturnType from_json(const jsonParser &json) {
552  return CASM::from_json<ReturnType>(json);
553  }
554 };
555 
563 template <typename ValueType>
564 struct jsonMake {
567  static std::unique_ptr<ValueType> make_from_json(const jsonParser &json) {
568  return CASM::make_from_json<ValueType>(json);
569  }
570 };
571 
573 template <typename T>
574 T from_json(const jsonParser &json) {
575  T value;
576  from_json(value, json);
577  return value;
578 }
579 
581 template <typename T>
582 std::unique_ptr<T> make_from_json(const jsonParser &json) {
583  return std::unique_ptr<T>(new T(from_json<T>(json)));
584 }
585 
586 // /// Make from JSON for basic types
587 // template<typename T>
588 // void make_from_json(std::unique_ptr<T>& ptr, const jsonParser &json) {
589 // ptr = jsonMake<T>::make_from_json(json);
590 // }
591 
593 template <typename T, typename... Args>
594 void make_from_json(std::unique_ptr<T> &ptr, const jsonParser &json,
595  Args &&... args) {
596  ptr = jsonMake<T>::make_from_json(json, std::forward<Args>(args)...);
597 }
598 
601 fs::path find_diff(const jsonParser &A, const jsonParser &B);
602 
605 fs::path find_diff(const jsonParser &A, const jsonParser &B, double tol);
606 
611 template <bool IsConst>
613  public:
614  typedef std::forward_iterator_tag iterator_category;
615  typedef
616  typename std::conditional<IsConst, json_spirit::mObject::const_iterator,
617  json_spirit::mObject::iterator>::type
619  typedef
620  typename std::conditional<IsConst, json_spirit::mArray::const_iterator,
621  json_spirit::mArray::iterator>::type
623  typedef int difference_type;
624  typedef typename std::conditional<IsConst, const jsonParser, jsonParser>::type
627  typedef value_type *pointer;
628 
630 
632 
634 
636 
638 
639  jsonParserIterator(pointer j, const int &iter);
640 
641  reference operator*() const;
642 
643  pointer operator->() const;
644 
645  bool operator==(const jsonParserIterator &iter) const;
646 
647  bool is_end() const;
648 
649  bool operator!=(const jsonParserIterator &iter) const;
650 
652 
654 
656 
658 
659  operator jsonParser::const_iterator() const;
660 
663  std::string name() const;
664 
665  template <bool _IsConst>
668 
669  private:
671 
672  json_spirit::Value_type type;
673 
675 
677 
678  int val_iter;
679 };
680 
683 template <typename T, typename... Args>
684 jsonParser &jsonParser::push_back(const T &value, Args &&... args) {
685  try {
686  jsonParser json;
687  get_array().push_back(to_json(value, json, std::forward<Args>(args)...));
688  return *this;
689  } catch (...) {
691  throw;
692  }
693 }
694 
715 template <typename T, typename... Args>
716 T jsonParser::get(Args &&... args) const {
717  return jsonConstructor<T>::from_json(*this, std::forward<Args>(args)...);
718 }
719 
727 template <typename T, typename... Args>
728 void jsonParser::get(T &t, Args &&... args) const {
729  from_json(t, *this, std::forward<Args>(args)...);
730 }
731 
739 template <typename T, typename... Args>
740 bool jsonParser::get_if(T &t, const std::string &key, Args &&... args) const {
741  auto it = find(key);
742  if (it != cend()) {
743  it->get(t, std::forward<Args>(args)...);
744  return true;
745  }
746  return false;
747 }
748 
756 template <typename T, typename... Args>
757 T jsonParser::get_if_else(const std::string &key, const T &default_value,
758  Args &&... args) const {
759  auto it = find(key);
760  if (it != end()) {
761  return it->get<T>(std::forward<Args>(args)...);
762  } else {
763  return default_value;
764  }
765 }
766 
774 template <typename T, typename... Args>
775 bool jsonParser::get_else(T &t, const std::string &key, const T &default_value,
776  Args &&... args) const {
777  auto it = find(key);
778  if (it != cend()) {
779  it->get(t, std::forward<Args>(args)...);
780  return true;
781  }
782 
783  t = default_value;
784  return false;
785 }
786 
805 template <typename T, typename... Args>
806 std::unique_ptr<T> jsonParser::make(Args &&... args) const {
807  return jsonMake<T>::make_from_json(*this, std::forward<Args>(args)...);
808 }
809 
817 template <typename T, typename... Args>
818 void jsonParser::make(std::unique_ptr<T> &ptr, Args &&... args) const {
819  make_from_json(ptr, *this, std::forward<Args>(args)...);
820 }
821 
829 template <typename T, typename... Args>
830 bool jsonParser::make_if(std::unique_ptr<T> &ptr, const std::string &key,
831  Args &&... args) const {
832  auto it = find(key);
833  if (it != cend()) {
834  it->make(ptr, std::forward<Args>(args)...);
835  return true;
836  }
837  return false;
838 }
839 
847 template <typename T, typename... Args>
848 std::unique_ptr<T> jsonParser::make_optional(const std::string &key,
849  Args &&... args) const {
850  auto it = find(key);
851  if (it != cend()) {
852  return it->make(std::forward<Args>(args)...);
853  }
854  return std::unique_ptr<T>();
855 }
856 
864 template <typename T, typename... Args>
865 std::unique_ptr<T> jsonParser::make_if_else(const std::string &key,
866  std::unique_ptr<T> default_value,
867  Args &&... args) const {
868  auto it = find(key);
869  if (it != cend()) {
870  return it->make(std::forward<Args>(args)...);
871  }
872  return std::move(default_value);
873 }
874 
882 template <typename T, typename... Args>
883 bool jsonParser::make_else(std::unique_ptr<T> &ptr, const std::string &key,
884  std::unique_ptr<T> default_value,
885  Args &&... args) const {
886  auto it = find(key);
887  if (it != cend()) {
888  it->make(ptr, std::forward<Args>(args)...);
889  return true;
890  }
891 
892  ptr = std::move(default_value);
893  return false;
894 }
895 
898 template <typename T>
899 jsonParser &jsonParser::put(const T &value) {
900  return to_json(value, *this);
901 }
902 
905 template <typename Iterator>
906 jsonParser &jsonParser::put_obj(Iterator begin, Iterator end) {
907  *this = object();
908  for (auto it = begin; it != end; ++it) {
909  to_json(it->second, (*this)[it->first]);
910  }
911  return *this;
912 }
913 
915 template <typename T>
917  *this = array();
918  for (auto i = 0; i < N; ++i) {
919  push_back(t);
920  }
921  return *this;
922 }
923 
925 template <typename Iterator, typename... Args,
927 jsonParser &jsonParser::put_array(Iterator begin, Iterator end,
928  Args &&... args) {
929  *this = array();
930  for (auto it = begin; it != end; ++it) {
931  push_back(*it, std::forward<Args>(args)...);
932  }
933  return *this;
934 }
935 
938 template <typename T>
940  return to_json(value, *this);
941 }
942 
944 template <typename Key, typename T>
945 jsonParser &to_json(const std::pair<Key, T> &value, jsonParser &json) {
946  json = jsonParser::object();
947  return json[value.first] = value.second;
948 }
949 
951 template <typename Key, typename T>
952 void from_json(std::pair<Key, T> &value, const jsonParser &json) {
953  auto it = json.begin();
954  value = std::make_pair<Key, T>(it.name(), *it);
955 }
956 
958 template <typename T>
959 jsonParser json_pair(const std::string &key, const T &value) {
960  jsonParser tjson;
961  tjson[key] = value;
962  return tjson;
963 }
964 
966 } // namespace CASM
967 
968 #endif
bool is_string() const
Check if string.
Definition: jsonParser.cc:269
jsonParser()
Create a new empty jsonParser.
Definition: jsonParser.hh:94
static jsonParser object()
Returns an empty json object.
Definition: jsonParser.hh:395
jsonParser(const T &t)
Definition: jsonParser.hh:112
iterator begin()
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:497
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:601
iterator end()
Returns iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:520
size_type size() const
Definition: jsonParser.cc:487
bool is_array() const
Check if array type.
Definition: jsonParser.cc:275
static jsonParser array()
Returns an empty json array.
Definition: jsonParser.hh:409
jsonParser & put_array(size_type N)
Puts new JSON array.
Definition: jsonParser.hh:365
jsonParserIterator< false > iterator
Definition: jsonParser.hh:88
json_spirit::mObject::size_type size_type
Definition: jsonParser.hh:87
static jsonParser array(size_type N)
Returns an empty json array.
Definition: jsonParser.hh:415
static jsonParser array(Iterator begin, Iterator end, typename CASM_TMP::enable_if_iterator< Iterator >::type *=nullptr)
Puts new JSON array, from iterators.
Definition: jsonParser.hh:429
bool read(std::istream &stream)
Reads json from the stream.
Definition: jsonParser.cc:168
jsonParser & operator=(const json_spirit::mValue &value)
Definition: jsonParser.hh:443
const_iterator cend() const
Returns const_iterator to end of JSON object or JSON array.
Definition: jsonParser.cc:533
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:354
bool read(const boost::filesystem::path &mypath)
Reads json from a path.
jsonParser & at(const fs::path &path)
Definition: jsonParser.cc:316
static jsonParser array(size_type N, const T &t)
Puts new JSON array, using the same value.
Definition: jsonParser.hh:422
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
Definition: jsonParser.cc:543
jsonParser & operator[](const std::string &name)
Definition: jsonParser.cc:283
void write(const std::string &file_name, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
Definition: jsonParser.cc:196
bool is_float() const
Check if number type (not including int)
Definition: jsonParser.cc:263
jsonParser & put_array()
Puts new empty JSON array.
Definition: jsonParser.hh:362
jsonParserIterator< true > const_iterator
Definition: jsonParser.hh:89
bool is_int() const
Check if int type.
Definition: jsonParser.cc:260
void write(const boost::filesystem::path &mypath, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
bool is_null() const
Check if null type.
Definition: jsonParser.cc:254
bool is_number() const
Check if number type (including int)
Definition: jsonParser.cc:266
jsonParser & put_null()
Puts 'null' JSON value.
Definition: jsonParser.hh:377
bool is_bool() const
Check if bool type.
Definition: jsonParser.cc:257
size_type erase(const std::string &name)
Erase key:value pair from an object.
Definition: jsonParser.cc:607
static jsonParser parse(const std::string &str)
Construct a jsonParser from a string containing JSON data.
Definition: jsonParser.hh:382
const_iterator cbegin() const
Returns const_iterator to beginning of JSON object or JSON array.
Definition: jsonParser.cc:510
jsonParser::iterator find_at(const fs::path &path)
Return iterator to sub-object or element, or 'end' if not found.
Definition: jsonParser.cc:556
static jsonParser parse(std::istream &stream)
Construct a jsonParser from a stream containing JSON data.
Definition: jsonParser.hh:392
static jsonParser object(Iterator begin, Iterator end)
Definition: jsonParser.hh:403
bool almost_equal(const jsonParser &B, double tol) const
Definition: jsonParser.cc:218
bool is_obj() const
Check if object type.
Definition: jsonParser.cc:272
bool operator!=(const jsonParser &json) const
Definition: jsonParser.hh:173
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
Definition: jsonParser.cc:188
friend void swap(jsonParserIterator< _IsConst > &a, jsonParserIterator< _IsConst > &b)
jsonParserIterator(pointer j, const object_iterator &iter)
std::conditional< IsConst, json_spirit::mObject::const_iterator, json_spirit::mObject::iterator >::type object_iterator
Definition: jsonParser.hh:618
pointer operator->() const
Definition: jsonParser.cc:664
object_iterator obj_iter
Definition: jsonParser.hh:674
array_iterator array_iter
Definition: jsonParser.hh:676
jsonParserIterator(pointer j, const int &iter)
jsonParserIterator & operator--()
Definition: jsonParser.cc:750
jsonParserIterator & operator++()
Definition: jsonParser.cc:720
std::conditional< IsConst, json_spirit::mArray::const_iterator, json_spirit::mArray::iterator >::type array_iterator
Definition: jsonParser.hh:622
std::forward_iterator_tag iterator_category
Definition: jsonParser.hh:614
json_spirit::Value_type type
Definition: jsonParser.hh:672
std::conditional< IsConst, const jsonParser, jsonParser >::type value_type
Definition: jsonParser.hh:625
bool operator!=(const jsonParserIterator &iter) const
Definition: jsonParser.cc:714
jsonParserIterator(pointer j, const array_iterator &iter)
std::string name() const
Definition: jsonParser.cc:792
bool operator==(const jsonParserIterator &iter) const
Definition: jsonParser.cc:674
reference operator*() const
Definition: jsonParser.cc:653
jsonParserIterator & operator=(jsonParserIterator iter)
Definition: jsonParser.cc:628
std::unique_ptr< T > make_if_else(const std::string &key, std::unique_ptr< T > default_value, Args &&... args) const
Get data from json if 'this' contains 'key', else return 'default_value'.
Definition: jsonParser.hh:865
double from_json< double >(const jsonParser &json)
Definition: jsonParser.cc:104
bool make_if(std::unique_ptr< T > &ptr, const std::string &key, Args &&... args) const
Get data from json if key exists.
Definition: jsonParser.hh:830
jsonParser json_pair(const std::string &key, const T &value)
Create pair/value json object without intermediate temporary.
Definition: jsonParser.hh:959
std::unique_ptr< T > make_from_json(const jsonParser &json)
Make from JSON for basic types.
Definition: jsonParser.hh:582
bool get_if(T &t, const std::string &key, Args &&... args) const
Definition: jsonParser.hh:740
jsonParser & put(const T &value)
Definition: jsonParser.hh:899
bool get_else(T &t, const std::string &key, const T &default_value, Args &&... args) const
Definition: jsonParser.hh:775
bool make_else(std::unique_ptr< T > &ptr, const std::string &key, std::unique_ptr< T > default_value, Args &&... args) const
Get data from json if key exists, else assign default_value.
Definition: jsonParser.hh:883
fs::path find_diff(const jsonParser &A, const jsonParser &B)
Return the location at which jsonParser 'A' != 'B' as a fs::path.
Definition: jsonParser.cc:475
bool from_json< bool >(const jsonParser &json)
Definition: jsonParser.cc:79
T get_if_else(const std::string &key, const T &default_value, Args &&... args) const
Definition: jsonParser.hh:757
std::unique_ptr< T > make_optional(const std::string &key, Args &&... args) const
Get data from json if key exists, else return empty ptr.
Definition: jsonParser.hh:848
unsigned int from_json< unsigned int >(const jsonParser &json)
Definition: jsonParser.cc:89
jsonParser & push_back(const T &value, Args &&... args)
Definition: jsonParser.hh:684
jsonParser from_json< jsonParser >(const jsonParser &json)
Definition: jsonParser.cc:116
int from_json< int >(const jsonParser &json)
Definition: jsonParser.cc:84
jsonParser & operator=(const T &value)
Definition: jsonParser.hh:939
unsigned long int from_json< unsigned long int >(const jsonParser &json)
Definition: jsonParser.cc:99
std::unique_ptr< T > make(Args &&... args) const
Get data from json.
Definition: jsonParser.hh:806
long int from_json< long int >(const jsonParser &json)
Definition: jsonParser.cc:94
T get(Args &&... args) const
Get data from json, using one of several alternatives.
Definition: jsonParser.hh:716
std::enable_if< is_iterator< T >::type::value, void > enable_if_iterator
Template alias to enable a template function via SFINAE for any iterator.
Definition: CASM_TMP.hh:63
Main CASM namespace.
Definition: APICommand.hh:8
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
std::istream & operator>>(std::istream &_in, std::vector< T > &vec)
Definition: stream_io.hh:10
GenericDatumFormatter< std::string, DataObject > name()
void from_json(ClexDescription &desc, const jsonParser &json)
bool operator==(DoFSet const &A, DoFSet const &B)
Definition: DoFSet.hh:314
Helper struct for constructing objects that need additional data.
Definition: jsonParser.hh:548
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.
Definition: jsonParser.hh:551
Helper struct for constructing objects that need additional data.
Definition: jsonParser.hh:564
static std::unique_ptr< ValueType > make_from_json(const jsonParser &json)
Default make_from_json is equivalent to.
Definition: jsonParser.hh:567