json.h
Go to the documentation of this file.
1 // BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2 
3 #ifndef AWKWARD_IO_JSON_H_
4 #define AWKWARD_IO_JSON_H_
5 
6 #include <complex>
7 #include <cstdio>
8 #include <string>
9 
10 #include "awkward/common.h"
14 
15 namespace awkward {
20  public:
24  virtual ~ToJson();
25 
27  virtual void
28  null() = 0;
30  virtual void
31  boolean(bool x) = 0;
33  virtual void
34  integer(int64_t x) = 0;
36  virtual void
37  real(double x) = 0;
39  virtual void
40  complex(std::complex<double> x) = 0;
42  virtual void
43  string(const char* x, int64_t length) = 0;
45  virtual void
46  beginlist() = 0;
48  virtual void
49  endlist() = 0;
51  virtual void
52  beginrecord() = 0;
54  virtual void
55  field(const char* x) = 0;
57  virtual void
58  endrecord() = 0;
60  virtual void
61  json(const char* data) = 0;
63  void
64  string(const std::string& x);
66  void
67  field(const std::string& x);
68  };
69 
74  public:
89  ToJsonString(int64_t maxdecimals,
90  const char* nan_string = nullptr,
91  const char* infinity_string = nullptr,
92  const char* minus_infinity_string = nullptr,
93  const char* complex_real_string = nullptr,
94  const char* complex_imag_string = nullptr);
96  ~ToJsonString();
97  void
98  null() override;
99  void
100  boolean(bool x) override;
101  void
102  integer(int64_t x) override;
103  void
104  real(double x) override;
105  void
106  complex(std::complex<double> x) override;
107  void
108  string(const char* x, int64_t length) override;
109  void
110  beginlist() override;
111  void
112  endlist() override;
113  void
114  beginrecord() override;
115  void
116  field(const char* x) override;
117  void
118  endrecord() override;
119  void
120  json(const char* data) override;
122  const std::string
123  tostring();
124  private:
125  class Impl;
126  Impl* impl_;
127  const char* nan_string_;
128  const char* infinity_string_;
129  const char* minus_infinity_string_;
130  const char* complex_real_string_;
131  const char* complex_imag_string_;
132  };
133 
138  public:
153  ToJsonPrettyString(int64_t maxdecimals,
154  const char* nan_string = nullptr,
155  const char* infinity_string = nullptr,
156  const char* minus_infinity_string = nullptr,
157  const char* complex_real_string = nullptr,
158  const char* complex_imag_string = nullptr);
161  void
162  null() override;
163  void
164  boolean(bool x) override;
165  void
166  integer(int64_t x) override;
167  void
168  real(double x) override;
169  void
170  complex(std::complex<double> x) override;
171  void
172  string(const char* x, int64_t length) override;
173  void
174  beginlist() override;
175  void
176  endlist() override;
177  void
178  beginrecord() override;
179  void
180  field(const char* x) override;
181  void
182  endrecord() override;
183  void
184  json(const char* data) override;
186  const std::string
187  tostring();
188  private:
189  class Impl;
190  Impl* impl_;
191  const char* nan_string_;
192  const char* infinity_string_;
193  const char* minus_infinity_string_;
194  const char* complex_real_string_;
195  const char* complex_imag_string_;
196  };
197 
202  public:
219  ToJsonFile(FILE* destination,
220  int64_t maxdecimals,
221  int64_t buffersize,
222  const char* nan_string = nullptr,
223  const char* infinity_string = nullptr,
224  const char* minus_infinity_string = nullptr,
225  const char* complex_real_string = nullptr,
226  const char* complex_imag_string = nullptr);
228  ~ToJsonFile();
229  void
230  null() override;
231  void
232  boolean(bool x) override;
233  void
234  integer(int64_t x) override;
235  void
236  real(double x) override;
237  void
238  complex(std::complex<double> x) override;
239  void
240  string(const char* x, int64_t length) override;
241  void
242  beginlist() override;
243  void
244  endlist() override;
245  void
246  beginrecord() override;
247  void
248  field(const char* x) override;
249  void
250  endrecord() override;
251  void
252  json(const char* data) override;
253  private:
254  class Impl;
255  Impl* impl_;
256  const char* nan_string_;
257  const char* infinity_string_;
258  const char* minus_infinity_string_;
259  const char* complex_real_string_;
260  const char* complex_imag_string_;
261  };
262 
267  public:
284  ToJsonPrettyFile(FILE* destination,
285  int64_t maxdecimals,
286  int64_t buffersize,
287  const char* nan_string = nullptr,
288  const char* infinity_string = nullptr,
289  const char* minus_infinity_string = nullptr,
290  const char* complex_real_string = nullptr,
291  const char* complex_imag_string = nullptr);
293  ~ToJsonPrettyFile();
294  void
295  null() override;
296  void
297  boolean(bool x) override;
298  void
299  integer(int64_t x) override;
300  void
301  real(double x) override;
302  void
303  complex(std::complex<double> x) override;
304  void
305  string(const char* x, int64_t length) override;
306  void
307  beginlist() override;
308  void
309  endlist() override;
310  void
311  beginrecord() override;
312  void
313  field(const char* x) override;
314  void
315  endrecord() override;
316  void
317  json(const char* data) override;
318  private:
319  class Impl;
320  Impl* impl_;
321  const char* nan_string_;
322  const char* infinity_string_;
323  const char* minus_infinity_string_;
324  const char* complex_real_string_;
325  const char* complex_imag_string_;
326  };
327 
340  FromJsonString(const char* source,
341  ArrayBuilder& builder,
342  const char* nan_string = nullptr,
343  const char* infinity_string = nullptr,
344  const char* minus_infinity_string = nullptr);
345 
359  FromJsonFile(FILE* source,
360  ArrayBuilder& builder,
361  int64_t buffersize,
362  const char* nan_string = nullptr,
363  const char* infinity_string = nullptr,
364  const char* minus_infinity_string = nullptr);
365 
371  public:
372  virtual int64_t read(int64_t num_bytes, char* buffer) = 0;
373  };
374 
393  ArrayBuilder& builder,
394  int64_t buffersize,
395  bool read_one,
396  const char* nan_string = nullptr,
397  const char* infinity_string = nullptr,
398  const char* minus_infinity_string = nullptr);
399 
400 }
401 
402 #endif // AWKWARD_IO_JSON_H_
LIBAWKWARD_EXPORT_SYMBOL int64_t FromJsonObject(FileLikeObject *source, ArrayBuilder &builder, int64_t buffersize, bool read_one, const char *nan_string=nullptr, const char *infinity_string=nullptr, const char *minus_infinity_string=nullptr)
Parses a JSON-encoded file-like object using an ArrayBuilder.
Produces a pretty JSON-formatted file.
Definition: json.h:266
LIBAWKWARD_EXPORT_SYMBOL int64_t FromJsonFile(FILE *source, ArrayBuilder &builder, int64_t buffersize, const char *nan_string=nullptr, const char *infinity_string=nullptr, const char *minus_infinity_string=nullptr)
Parses a JSON-encoded file using an ArrayBuilder.
#define LIBAWKWARD_EXPORT_SYMBOL
Definition: common.h:45
Definition: json.h:19
Definition: BitMaskedArray.h:15
User interface to the Builder system: the ArrayBuilder is a fixed reference while the Builder subclas...
Definition: ArrayBuilder.h:26
LIBAWKWARD_EXPORT_SYMBOL int64_t FromJsonString(const char *source, ArrayBuilder &builder, const char *nan_string=nullptr, const char *infinity_string=nullptr, const char *minus_infinity_string=nullptr)
Parses a JSON-encoded string using an ArrayBuilder.
Abstract class to represent a file-like object, something with a read(num_bytes) method. Satisfies RapidJSON&#39;s Stream interface.
Definition: json.h:370
Produces a JSON-formatted string.
Definition: json.h:73
Produces a pretty JSON-formatted string.
Definition: json.h:137
Produces a JSON-formatted file.
Definition: json.h:201