Awali
Another Weighted Automata library
node.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_JSON_NODE_HH
18 #define AWALI_JSON_NODE_HH
19 
22 #include<vector>
23 #include<unordered_map>
24 #include<cmath>
25 #include<memory>
26 
27 namespace awali {
28 namespace json {
29 
30 
31 /* =============================================================================
32  Forward declarations
33 ============================================================================= */
34 
35 class node_t;
36 class object_t;
37 class array_t;
38 class int_t;
39 class float_t;
40 class string_t;
41 class bool_t;
42 class null_t;
43 class parser_t;
44 
45 /* =============================================================================
46  uint_or_string and navigation path
47 ============================================================================= */
49 protected:
50  long i;
51  std::string str;
52 public:
53  uint_or_string_t(unsigned integer) : i(integer), str("") {}
54 
55  uint_or_string_t(std::string s) : i(-1), str(std::move(s)) {}
56 
58  : i(uos.i), str(uos.str) {}
59 
61  : i(uos.i), str(std::move(uos.str)) {}
62 
63  uint_or_string_t(char const* s) : i(-1), str(s?s:"") {}
64 
65  inline bool is_string() const {return i<0;}
66 
67  inline bool is_integer() const {return i>=0;}
68 
69  inline unsigned integer() const {return i;}
70 
71  inline std::string const& string() const {return str;}
72 
73 
74  inline operator std::string&() {return str;}
75  inline operator std::string() const {return str;}
76  inline operator unsigned() const {return i;}
77 
79  { i = uos.i, str = std::move(uos.str); return *this;}
80 };
81 
82 typedef std::vector<uint_or_string_t> path_t;
83 
84 
85 
86 /* =============================================================================
87  NODE KIND
88 ============================================================================= */
90  OBJECT = 0,
91  ARRAY = 1,
92  INTEGER = 2,
93  FLOATING = 3,
94  STRING = 4,
95  BOOLEAN = 5,
96  _NULL = 6
97 };
98 
99 std::string const& string_of(node_kind_t kind);
100 
101 std::ostream& operator<<(std::ostream& o, node_kind_t kind);
102 
103 /* =============================================================================
104  EXCEPTIONS
105 ============================================================================= */
106 
107 class exception : public std::exception {
108 public:
109  std::string message;
110  std::string caller;
111  node_t const* node;
114  std::string what_msg;
115 
116  exception(std::string const& message, std::string const& caller,
117  path_t path_to_root, int line, int col);
118 
119  exception(std::string const& message, std::string const& caller,
120  node_t const* node = nullptr);
121 
122  exception(std::string message, node_t const* node = nullptr)
123  : exception(message, "", node) {}
124 
125  virtual const char* what() const noexcept override
126  {return what_msg.c_str();}
127 };
128 
129 class parse_exception: public exception {
130 public:
131  parse_exception(std::string const& message, std::string const& caller,
132  path_t path_to_root, int line, int col):
133  exception(message, caller, path_to_root, line, col) {}
134  parse_exception(std::string const& message, std::string const& caller):
136 };
137 
138 
140 class coercion_exception : public exception {
141 public:
142  coercion_exception(std::string const& message, std::string const& caller,
143  node_t const* node = nullptr)
144  : exception(message, caller, node) {}
145 
146  coercion_exception(std::string message, node_t const* node = nullptr)
147  : coercion_exception(message, "", node) {}
148 };
149 
150 
151 class out_of_range : public exception {
152 public:
153  out_of_range(std::string const& message, std::string const& caller,
154  node_t const* node = nullptr)
156  {}
157 
158  out_of_range(std::string const& message, node_t const* node = nullptr)
159  : out_of_range(message, "", node)
160  {}
161 };
162 
163 
164 
165 class kind_mismatch : public exception {
166 public:
167  std::vector<node_kind_t> expected_types;
168  kind_mismatch(std::string const& caller, node_t const* node,
169  node_kind_t expected_type)
170  : kind_mismatch(caller, node, {expected_type}){}
171 
172  kind_mismatch(std::string const& caller, node_t const* node,
173  std::initializer_list<node_kind_t> types);
174 
175 
176 protected:
177  static std::string message_builder(std::string const& caller_method,
178  node_kind_t caller_kind,
179  std::initializer_list<node_kind_t> types);
180 
181 };
182 
183 
184 
185 
186 
187 /* =============================================================================
188  node_t
189 ============================================================================= */
190 
191 class node_t {
192 public:
193  node_t const* parent;
195 
196 // static node_t* parse(std::istream& i);
197 
198  virtual ~node_t() {}
199 
201  virtual inline object_t const* object() const
202  {throw kind_mismatch("node_t::object()", this, node_kind_t::OBJECT);}
203 
205  virtual inline array_t const* array() const
206  {throw kind_mismatch("node_t::array()", this, node_kind_t::ARRAY);}
207 
209  virtual inline int_t const* integer() const
210  {throw kind_mismatch("node_t::integer()", this, node_kind_t::INTEGER);}
211 
213  virtual inline string_t const* string() const
214  {throw kind_mismatch("node_t::string()", this, node_kind_t::STRING);}
215 
217  virtual inline float_t const* floating() const
218  {throw kind_mismatch("node_t::floating()", this, node_kind_t::FLOATING);}
219 
221  virtual inline bool_t const* boolean() const
222  {throw kind_mismatch("node_t::boolean()", this, node_kind_t::BOOLEAN);}
223 
225  virtual inline null_t const* null() const
226  {throw kind_mismatch("node_t::null()", this, node_kind_t::_NULL);}
227 
229  virtual inline object_t* object()
230  {throw kind_mismatch("node_t::object()", this, node_kind_t::OBJECT);}
231 
233  virtual inline array_t* array()
234  {throw kind_mismatch("node_t::array()", this, node_kind_t::ARRAY);}
235 
237  virtual inline int_t* integer()
238  {throw kind_mismatch("node_t::integer()", this, node_kind_t::INTEGER);}
239 
241  virtual inline string_t* string()
242  {throw kind_mismatch("node_t::string()", this, node_kind_t::STRING);}
243 
245  virtual inline float_t* floating()
246  {throw kind_mismatch("node_t::floating()", this, node_kind_t::FLOATING);}
247 
249  virtual inline bool_t* boolean()
250  {throw kind_mismatch("node_t::boolean()", this, node_kind_t::BOOLEAN);}
251 
253  virtual inline null_t* null()
254  {throw kind_mismatch("node_t::null()", this, node_kind_t::_NULL);}
255 
256  virtual node_t* copy() const =0;
257 
258  node_t* at_path(path_t const& path, unsigned i = 0);
259  node_t const* at_path(path_t const& path, unsigned i = 0) const;
260  bool has_path(json::path_t const& path) const;
261 
262  inline virtual unsigned height() const {return 0;}
263 
264 // template<typename T2, typename... Args>
265 // node_t* at(std::string const& str, T2 arg2, Args... args) {
266 // return this->at(str)->at(arg2, args...);
267 // }
268 
269 // template<typename T2, typename... Args>
270 // bool has_path(std::string const& str, T2 arg2, Args... args) const {
271 // if (!this->has_child(str))
272 // return false;
273 // return this->at(str)->has_path(arg2, args...);
274 // }
275 
276  //node_t* at(std::initializer_list<std::string> const&);
277  //node_t const* at(std::initializer_list<std::string> const&) const;
278  //bool has_child(std::initializer_list<std::string> const&l) const;
279 
280  virtual node_t* at(std::string const& key);
281  virtual node_t const* at(std::string const& key) const;
282  inline virtual bool has_child(std::string const&) const
283  {return false;}
284 
285 
286  //node_t const* at(std::initializer_list<unsigned> const&) const;
287  virtual node_t* at(unsigned i);
288  virtual node_t const* at(unsigned i) const;
289  inline virtual bool has_child(unsigned i) const
290  {return false;}
291  //inline virtual bool has_child(std::initializer_list<unsigned> const& l) const
292  //{node_t const* n = this; for (auto x : l) if (n->has_child(x)) n = n->at(x); else return false; return true;}
293 
294 
304  virtual inline bool to_bool() const
305  {throw kind_mismatch("node_t::to_bool()", this,
308 
309 
319  virtual inline int to_int() const
320  {throw kind_mismatch("node_t::to_int()", this,
323 
324 
329  virtual std::string to_string() const
330  {throw kind_mismatch("node_t::to_string()", this, node_kind_t::STRING);}
331 
332 
341  virtual double to_double() const
342  {throw kind_mismatch("node_t::to_double()", this,
345 
346 
347  inline bool is(node_kind_t k) const {return (this-> kind == k);}
348  inline bool is(std::vector<node_kind_t>const& v) const
349  {for(auto k:v) if (this->is(k)) return true; return false;}
350 
351  inline bool is_leaf() const {return !this->is({OBJECT,ARRAY});}
352 
353  virtual inline unsigned arity() const {return 0u;}
354 
356 
357 protected:
358  node_t(node_kind_t k) : parent(nullptr), kind(k) {}
359 };
360 
361 
362 /* =============================================================================
363  OBJECT
364 ============================================================================= */
365 class object_t : public node_t {
367 public:
371 
372  object_t() : node_t(node_kind_t::OBJECT), _fields(), fields(_fields) {}
373  object_t(std::string key, node_t* child) : object_t()
374  {this->push_back(std::move(key),child);}
375 
377 
378  inline virtual bool has_child(std::string const& key) const override
379  {return fields.find(key) != fields.end(); }
380 
381  virtual node_t* at(std::string const& key) override;
382 
383  virtual node_t const* at(std::string const& key) const override;
384 
385  object_t* push_back(std::string key, node_t* node);
386 
387  object_t* push_front(std::string key, node_t* node);
388 
389  object_t* insert_after(std::string const& ref_key,
390  std::string key, node_t* node);
391 
392  object_t* insert_before(std::string const& ref_key,
393  std::string key, node_t* node);
394 
395  inline void erase(std::string const& key) {_fields.erase(key);}
396 
397  inline virtual object_t* object() override {return this;}
398  inline virtual object_t const* object() const override {return this;}
399 
400  virtual object_t* copy() const override ;
401 
402  inline virtual unsigned height() const override {
403  unsigned d = 0;
404  for (auto p : fields) {
405  unsigned x = p.second->height() + 1;
406  if (x > d)
407  d = x;
408  }
409  return d;
410  }
411 
412  inline iterator begin() {return _fields.begin();}
413  inline iterator end() {return _fields.end();}
414  inline const_iterator begin() const {return fields.begin();}
415  inline const_iterator end() const {return fields.end();}
416 
417  inline virtual unsigned arity() const override {return fields.size();}
418 };
419 
420 
421 /* =============================================================================
422  ARRAY
423 ============================================================================= */
424 class array_t : public node_t {
425 protected:
426  std::vector<node_t*> _values;
427 
428 public:
429  std::vector<node_t*> const& values;
430 
431  typedef std::vector<node_t*>::iterator iterator;
432  typedef std::vector<node_t*>::const_iterator const_iterator;
433 
435  array_t(std::vector<node_t*> v)
436  : node_t(node_kind_t::ARRAY), _values(std::move(v)), values(_values) {}
437 
439 
440 // static array_t* parse(std::istream& i);
441 
442  inline virtual array_t* array() override {return this;}
443  inline virtual array_t const* array() const override {return this;}
444 
445  virtual array_t* copy() const override;
446 
447 
448  virtual node_t* at(unsigned i) override;
449 
450  virtual node_t const* at(unsigned i) const override;
451 
452  inline iterator begin() {return _values.begin();}
453  inline const_iterator begin() const {return values.begin();}
454 
455  inline iterator end() {return _values.end();}
456  inline const_iterator end() const {return values.end();}
457 
459 
460  inline unsigned arity() const override {return values.size();}
461 
462  inline unsigned empty() const {return arity() == 0;}
463 
464 
465  inline virtual bool has_child(unsigned i) const override
466  {return i < arity();}
467 
468  inline virtual unsigned height() const override {
469  unsigned d = 0;
470  for (auto p : values) {
471  unsigned x = p->height()+1;
472  if (x > d)
473  d = x;
474  }
475  return d;
476  }
477 };
478 
479 
480 /* =============================================================================
481  INTEGER
482 ============================================================================= */
483 class int_t : public node_t {
484 public:
485  int value;
486 
488 
489  inline virtual int_t* copy() const override {return new int_t(value);}
490 
491  inline virtual int_t* integer() override {return this;}
492  inline virtual int_t const* integer() const override {return this;}
493 
494  virtual bool to_bool() const override;
495  virtual inline int to_int() const override {return value;}
496  virtual inline double to_double() const override {return value;}
497 };
498 
499 
500 /* =============================================================================
501  FLOATING
502 ============================================================================= */
503 class float_t : public node_t {
504 public:
505  double value;
506 
507  float_t(double v) : node_t(node_kind_t::FLOATING), value(v) {}
508 
509 // static node_t* parse(std::istream& i);
510 
511  inline virtual float_t* copy() const override
512  {return new float_t(value);}
513 
514  inline virtual float_t* floating() override {return this;}
515  inline virtual float_t const* floating() const override {return this;}
516 
517  virtual bool to_bool() const override;
518  virtual int to_int() const override;
519  virtual inline double to_double() const override {return value;}
520 };
521 
522 
523 /* =============================================================================
524  STRING
525 ============================================================================= */
526 class string_t : public node_t {
527 public:
528  std::string value;
529 
530  string_t(char c)
531  : node_t(node_kind_t::STRING), value(1,c) {}
532 
533  string_t(std::string v)
534  : node_t(node_kind_t::STRING), value(std::move(v)) {}
535 
536 // static inline string_t* parse(std::istream& i)
537 // {return new string_t(internal::parsestring(i));}
538 
539  inline virtual string_t* copy() const override
540  {return new string_t(value);}
541 
542  inline virtual string_t* string() override {return this;}
543  inline virtual string_t const* string() const override {return this;}
544 
545  virtual bool to_bool() const override;
546  virtual int to_int() const override;
547  virtual double to_double() const override;
548  virtual inline std::string to_string() const override {return this->value;}
549 };
550 
551 
552 /* =============================================================================
553  BOOLEAN
554 ============================================================================= */
555 class bool_t : public node_t {
556 public:
557  bool value;
558 
559  bool_t(bool v) : node_t(node_kind_t::BOOLEAN), value(v) {}
560 
561 // static bool_t* parse(std::istream& i);
562 // static bool_t* parse_true(std::istream& i);
563 // static bool_t* parse_false(std::istream& i);
564 
565  inline virtual bool_t* copy() const override
566  {return new bool_t(value);}
567 
568  inline virtual bool_t* boolean() override {return this;};
569  inline virtual bool_t const* boolean() const override {return this;};
570 
571 
572  virtual inline bool to_bool() const override {return this->value;}
573  virtual inline int to_int() const override {return this->value;}
574  virtual inline double to_double() const override {return this->value;}
575 
576 };
577 
578 
579 /* =============================================================================
580  NULL
581 ============================================================================= */
582 class null_t : public node_t {
583 public:
585 
586 // static null_t* parse(std::istream& i);
587 
588  inline virtual null_t* copy() const override { return new null_t();}
589 
590  inline virtual null_t* null() override {return this;}
591 
592  inline virtual null_t const* null() const override {return this;}
593 };
594 
595 
596 
597 }// end of namespace awali::json
598 
599 
600 
601 }// end of namespace awali
602 
603 namespace std {
604 std::ostream& operator<<(std::ostream& o, awali::json::uint_or_string_t const& uos);
605 std::ostream& operator<<(std::ostream& o, awali::json::path_t const& path);
606 }
607 
608 #endif
Definition: node.hh:424
virtual node_t * at(unsigned i) override
const_iterator begin() const
Definition: node.hh:453
virtual unsigned height() const override
Definition: node.hh:468
const_iterator end() const
Definition: node.hh:456
virtual node_t const * at(unsigned i) const override
std::vector< node_t * >::iterator iterator
Definition: node.hh:431
array_t * push_back(node_t *p)
array_t()
Definition: node.hh:434
virtual array_t * array() override
Casts this node to array_t.
Definition: node.hh:442
iterator end()
Definition: node.hh:455
array_t(std::vector< node_t * > v)
Definition: node.hh:435
virtual array_t * copy() const override
unsigned arity() const override
Definition: node.hh:460
std::vector< node_t * > _values
Definition: node.hh:426
virtual bool has_child(unsigned i) const override
Definition: node.hh:465
iterator begin()
Definition: node.hh:452
std::vector< node_t * >::const_iterator const_iterator
Definition: node.hh:432
virtual array_t const * array() const override
Casts this node to array_t.
Definition: node.hh:443
std::vector< node_t * > const & values
Definition: node.hh:429
unsigned empty() const
Definition: node.hh:462
Definition: node.hh:555
bool value
Definition: node.hh:557
virtual bool to_bool() const override
Coerces this node_t to bool.
Definition: node.hh:572
bool_t(bool v)
Definition: node.hh:559
virtual bool_t * boolean() override
Casts this node to bool_t.
Definition: node.hh:568
virtual bool_t const * boolean() const override
Casts this node to bool_t.
Definition: node.hh:569
virtual double to_double() const override
Coerces this node_t to a double
Definition: node.hh:574
virtual int to_int() const override
Coerces this node_t to int.
Definition: node.hh:573
virtual bool_t * copy() const override
Definition: node.hh:565
Exception used when trying to coerce a node to a given type.
Definition: exceptions.hh:83
coercion_exception(std::string const &message, std::string const &caller, node_t const *node=nullptr)
Definition: node.hh:142
coercion_exception(std::string message, node_t const *node=nullptr)
Definition: node.hh:146
The main exception for json manipulation.
Definition: exceptions.hh:26
exception(std::string message, node_t const *node=nullptr)
Definition: node.hh:122
node_t const * node
Definition: node.hh:111
virtual const char * what() const noexcept override
Definition: node.hh:125
exception(std::string const &message, std::string const &caller, node_t const *node=nullptr)
exception(std::string const &message, std::string const &caller, path_t path_to_root, int line, int col)
std::string caller
Definition: exceptions.hh:29
std::string what_msg
Definition: exceptions.hh:30
node_t * attempted_parsed_tree
Definition: node.hh:112
path_t path_to_root
Definition: node.hh:113
std::string message
Definition: exceptions.hh:28
Definition: node.hh:503
virtual float_t * floating() override
Casts this not to float_t.
Definition: node.hh:514
double value
Definition: node.hh:505
virtual double to_double() const override
Coerces this node_t to a double
Definition: node.hh:519
float_t(double v)
Definition: node.hh:507
virtual int to_int() const override
Coerces this node_t to int.
virtual float_t * copy() const override
Definition: node.hh:511
virtual float_t const * floating() const override
Casts this not to float_t.
Definition: node.hh:515
virtual bool to_bool() const override
Coerces this node_t to bool.
Definition: node.hh:483
virtual bool to_bool() const override
Coerces this node_t to bool.
virtual int_t * integer() override
Casts this node to int_t.
Definition: node.hh:491
virtual int to_int() const override
Coerces this node_t to int.
Definition: node.hh:495
int value
Definition: node.hh:485
virtual int_t * copy() const override
Definition: node.hh:489
virtual int_t const * integer() const override
Casts this node to int_t.
Definition: node.hh:492
virtual double to_double() const override
Coerces this node_t to a double
Definition: node.hh:496
int_t(int v)
Definition: node.hh:487
Definition: exceptions.hh:78
std::vector< node_kind_t > expected_types
Definition: node.hh:167
kind_mismatch(std::string const &caller, node_t const *node, std::initializer_list< node_kind_t > types)
kind_mismatch(std::string const &caller, node_t const *node, node_kind_t expected_type)
Definition: node.hh:168
static std::string message_builder(std::string const &caller_method, node_kind_t caller_kind, std::initializer_list< node_kind_t > types)
Definition: node.hh:191
virtual bool has_child(unsigned i) const
Definition: node.hh:289
bool is(node_kind_t k) const
Definition: node.hh:347
node_t const * parent
Definition: node.hh:193
virtual float_t const * floating() const
Casts this not to float_t.
Definition: node.hh:217
virtual node_t * at(std::string const &key)
node_t * at_path(path_t const &path, unsigned i=0)
virtual bool_t const * boolean() const
Casts this node to bool_t.
Definition: node.hh:221
path_t path_to_root() const
virtual double to_double() const
Coerces this node_t to a double
Definition: node.hh:341
virtual std::string to_string() const
Coerces this node_t to an std::string.
Definition: node.hh:329
virtual node_t * at(unsigned i)
bool is(std::vector< node_kind_t >const &v) const
Definition: node.hh:348
virtual node_t const * at(unsigned i) const
virtual array_t * array()
Casts this node to array_t.
Definition: node.hh:233
bool has_path(json::path_t const &path) const
virtual int_t const * integer() const
Casts this node to int_t.
Definition: node.hh:209
virtual int to_int() const
Coerces this node_t to int.
Definition: node.hh:319
node_t const * at_path(path_t const &path, unsigned i=0) const
virtual unsigned height() const
Definition: node.hh:262
virtual string_t * string()
Casts this node to string_t.
Definition: node.hh:241
virtual bool to_bool() const
Coerces this node_t to bool.
Definition: node.hh:304
virtual float_t * floating()
Casts this not to float_t.
Definition: node.hh:245
virtual string_t const * string() const
Casts this node to string_t.
Definition: node.hh:213
virtual ~node_t()
Definition: node.hh:198
virtual bool has_child(std::string const &) const
Definition: node.hh:282
virtual node_t const * at(std::string const &key) const
virtual object_t * object()
Casts this node to object_t.
Definition: node.hh:229
virtual object_t const * object() const
Casts this node to object_t.
Definition: node.hh:201
node_kind_t const kind
Definition: node.hh:194
node_t(node_kind_t k)
Definition: node.hh:358
virtual node_t * copy() const =0
virtual unsigned arity() const
Definition: node.hh:353
virtual bool_t * boolean()
Casts this node to bool_t.
Definition: node.hh:249
virtual int_t * integer()
Casts this node to int_t.
Definition: node.hh:237
bool is_leaf() const
Definition: node.hh:351
virtual array_t const * array() const
Casts this node to array_t.
Definition: node.hh:205
Definition: node.hh:582
null_t()
Definition: node.hh:584
virtual null_t * copy() const override
Definition: node.hh:588
Definition: node.hh:365
const_iterator end() const
Definition: node.hh:415
virtual bool has_child(std::string const &key) const override
Definition: node.hh:378
linked_map_t< std::string, node_t * >::const_iterator const_iterator
Definition: node.hh:370
iterator begin()
Definition: node.hh:412
object_t(std::string key, node_t *child)
Definition: node.hh:373
virtual node_t * at(std::string const &key) override
object_t * insert_after(std::string const &ref_key, std::string key, node_t *node)
object_t * push_back(std::string key, node_t *node)
virtual object_t * object() override
Casts this node to object_t.
Definition: node.hh:397
object_t()
Definition: node.hh:372
iterator end()
Definition: node.hh:413
virtual unsigned height() const override
Definition: node.hh:402
const_iterator begin() const
Definition: node.hh:414
void erase(std::string const &key)
Definition: node.hh:395
virtual object_t const * object() const override
Casts this node to object_t.
Definition: node.hh:398
linked_map_t< std::string, node_t * >::iterator iterator
Definition: node.hh:369
virtual object_t * copy() const override
object_t * insert_before(std::string const &ref_key, std::string key, node_t *node)
object_t * push_front(std::string key, node_t *node)
virtual node_t const * at(std::string const &key) const override
virtual unsigned arity() const override
Definition: node.hh:417
linked_map_t< std::string, node_t * > const & fields
Definition: node.hh:368
Definition: node.hh:151
out_of_range(std::string const &message, node_t const *node=nullptr)
Definition: node.hh:158
out_of_range(std::string const &message, std::string const &caller, node_t const *node=nullptr)
Definition: node.hh:153
parse_exception(std::string const &message, std::string const &caller, path_t path_to_root, int line, int col)
Definition: node.hh:131
parse_exception(std::string const &message, std::string const &caller)
Definition: node.hh:134
Definition: node.hh:526
virtual int to_int() const override
Coerces this node_t to int.
virtual std::string to_string() const override
Coerces this node_t to an std::string.
Definition: node.hh:548
virtual bool to_bool() const override
Coerces this node_t to bool.
std::string value
Definition: node.hh:528
virtual string_t * string() override
Casts this node to string_t.
Definition: node.hh:542
virtual string_t * copy() const override
Definition: node.hh:539
virtual double to_double() const override
Coerces this node_t to a double
virtual string_t const * string() const override
Casts this node to string_t.
Definition: node.hh:543
string_t(std::string v)
Definition: node.hh:533
string_t(char c)
Definition: node.hh:530
Definition: node.hh:48
unsigned integer() const
Definition: node.hh:69
uint_or_string_t(std::string s)
Definition: node.hh:55
uint_or_string_t(char const *s)
Definition: node.hh:63
bool is_string() const
Definition: node.hh:65
std::string str
Definition: node.hh:51
uint_or_string_t(uint_or_string_t const &uos)
Definition: node.hh:57
long i
Definition: node.hh:50
uint_or_string_t(unsigned integer)
Definition: node.hh:53
std::string const & string() const
Definition: node.hh:71
bool is_integer() const
Definition: node.hh:67
uint_or_string_t & operator=(uint_or_string_t &&uos)
Definition: node.hh:78
uint_or_string_t(uint_or_string_t &&uos)
Definition: node.hh:60
Implemention of a linked hash-map.
Definition: linked_map.hxx:72
std::list< pair_t >::iterator iterator
Definition: linked_map.hxx:81
iterator begin() noexcept
Definition: linked_map.hxx:143
std::list< pair_t >::const_iterator const_iterator
Definition: linked_map.hxx:82
iterator erase(const_iterator pos)
Definition: linked_map.hxx:256
iterator end() noexcept
Definition: linked_map.hxx:144
std::ostream & json(automaton_t aut, std::ostream &out)
std::vector< uint_or_string_t > path_t
Definition: node.hh:82
std::string const & string_of(node_kind_t kind)
std::ostream & operator<<(std::ostream &o, node_kind_t kind)
node_kind_t
Definition: node.hh:89
@ OBJECT
Definition: node.hh:90
@ INTEGER
Definition: node.hh:92
@ ARRAY
Definition: node.hh:91
@ BOOLEAN
Definition: node.hh:95
@ STRING
Definition: node.hh:94
@ FLOATING
Definition: node.hh:93
@ _NULL
Definition: node.hh:96
Main namespace of Awali.
Definition: ato.hh:22
Exceptions thrown during parsing.
Definition: parse_exception.hh:26