pupene  0.2.0
json.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "json-puppers.h"
4 #include "util.h"
5 #include <sstream>
6 
7 /** \file
8  * Convert to/from JSON.
9  */
10 namespace pupene {
11  template<typename T>
12  T from_json(std::istream& in, bool debug = false) {
13  T t;
14  do_pup(JsonReader{in}, t, debug);
15  return t;
16  }
17 
18  template<typename T>
19  T from_json(const std::string& s, bool debug = false) {
20  std::istringstream in{s};
21  return from_json<T>(in, debug);
22  }
23 
24  template<typename T>
25  void to_json(T& obj, std::ostream& out, bool debug = false) {
26  JsonWriter pupper{out};
27  do_pup(pupper, obj, debug);
28  }
29 
30  template<typename T>
31  std::string to_json(T& obj, bool debug = false) {
32  std::ostringstream out;
33  to_json(obj, out, debug);
34  return out.str();
35  }
36 }
T from_json(const std::string &s, bool debug=false)
Definition: json.h:19
JsonReader(std::istream &in)
Definition: json-puppers.h:83
Definition: debug.cpp:4
JsonWriter(std::ostream &stream)
Definition: json-puppers.h:17
T from_json(std::istream &in, bool debug=false)
Definition: json.h:12
std::string to_json(T &obj, bool debug=false)
Definition: json.h:31
void to_json(T &obj, std::ostream &out, bool debug=false)
Definition: json.h:25