1 #ifndef DBALLE_CORE_JSON_H 2 #define DBALLE_CORE_JSON_H 5 #include <wreport/var.h> 7 #include <dballe/core/fwd.h> 16 using std::runtime_error::runtime_error;
40 std::vector<State> stack;
46 void jputs(
const char* s);
65 void add_bool(
bool val);
66 void add_int(
int val);
67 void add_double(
double val);
68 void add_cstring(
const char* val);
69 void add_string(
const std::string& val);
71 void add_ostream(
const T& val)
77 void add_number(
const std::string& val);
78 void add_level(
const Level& val);
79 void add_trange(
const Trange& val);
80 void add_datetime(
const Datetime& val);
82 void add_coords(
const Coords& val);
83 void add_ident(
const Ident& val);
85 void add_station(
const Station& s);
87 void add_values(
const Values& values);
88 void add_dbvalues(
const DBValues& values);
91 void add(
const std::string& val) { add_string(val); }
92 void add(
const char* val) { add_cstring(val); }
93 void add(
double val) { add_double(val); }
94 void add(
int val) { add_int(val); }
95 void add(
bool val) { add_bool(val); }
96 void add(
size_t val) { add_ostream(val); }
98 void add(
const Level& val) { add_level(val); }
99 void add(
const Trange& val) { add_trange(val); }
100 void add(
const Datetime& val) { add_datetime(val); }
101 void add(
const DatetimeRange& val) { add_datetimerange(val); }
102 void add(
const Coords& val) { add_coords(val); }
103 void add(
const Ident& val) { add_ident(val); }
105 void add(
const Station& s) { add_station(s); }
106 void add(
const DBStation& s) { add_dbstation(s); }
107 void add(
const Values& v) { add_values(v); }
108 void add(
const DBValues& v) { add_dbvalues(v); }
111 void add(
const char* a, T b)
118 void add_list(
const T& val)
121 for (
const auto& i : val)
135 virtual void on_start_list() = 0;
136 virtual void on_end_list() = 0;
138 virtual void on_start_mapping() = 0;
139 virtual void on_end_mapping() = 0;
141 virtual void on_add_null() = 0;
142 virtual void on_add_bool(
bool val) = 0;
143 virtual void on_add_int(
int val) = 0;
144 virtual void on_add_double(
double val) = 0;
145 virtual void on_add_string(
const std::string& val) = 0;
148 void parse(std::istream& in);
169 Stream(std::istream& in) : in(in) {}
172 void expect_token(
const char* token);
185 if (c >=
'0' and c <=
'9')
186 res = res * 10 + in.get() -
'0';
198 if (in.peek() ==
'-')
201 return -parse_unsigned<T>();
203 return parse_unsigned<T>();
207 double parse_double();
215 std::tuple<std::string, bool> parse_number();
218 std::string parse_string();
248 void parse_array(std::function<
void()> on_element);
251 void parse_object(std::function<
void(
const std::string& key)> on_value);
255 Element identify_next();
258 template<>
inline std::string Stream::parse() {
return parse_string(); }
259 template<>
inline Coords Stream::parse() {
return parse_coords(); }
260 template<>
inline Station Stream::parse() {
return parse_station(); }
261 template<>
inline DBStation Stream::parse() {
return parse_dbstation(); }
262 template<>
inline Ident Stream::parse() {
return parse_ident(); }
263 template<>
inline Level Stream::parse() {
return parse_level(); }
264 template<>
inline Trange Stream::parse() {
return parse_trange(); }
265 template<>
inline Datetime Stream::parse() {
return parse_datetime(); }
266 template<>
inline DatetimeRange Stream::parse() {
return parse_datetimerange(); }
Common base types used by most of DB-All.e code.
Station information.
Definition: types.h:793
T parse_unsigned()
Parse an unsigned integer.
Definition: json.h:179
Coordinates.
Definition: types.h:368
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:191
Vertical level or layer.
Definition: types.h:624
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: types.h:747
Range of datetimes.
Definition: types.h:294
JSON sax-like parser.
Definition: json.h:130
T parse_signed()
Parse a signed integer.
Definition: json.h:196
Date and time.
Definition: types.h:164
JSON serializer.
Definition: json.h:29
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:176