5 #include "internalJSONNode.h"
10 #include "JSON_Base64.h"
13 #ifdef JSON_LESS_MEMORY
17 #pragma pack(push, JSONNode_pack, 1)
21 #ifndef JSON_REF_COUNT
22 #define makeUniqueInternal() (void)0
25 #define JSON_CHECK_INTERNAL() JSON_ASSERT(internal != 0, JSON_TEXT("no internal"))
27 #ifdef JSON_MUTEX_CALLBACKS
28 #define JSON_MUTEX_COPY_DECL ,void * parentMutex
29 #define JSON_MUTEX_COPY_DECL2 ,void * parentMutex = 0
31 #define JSON_MUTEX_COPY_DECL
32 #define JSON_MUTEX_COPY_DECL2
36 #define JSON_PTR_LIB *
37 #define JSON_NEW(x) JSONNode::newJSONNode_Shallow(x)
40 #define DECLARE_FOR_ALL_TYPES(foo)\
41 foo(json_int_t)json_nothrow;\
42 foo(json_number) json_nothrow;\
43 foo(bool) json_nothrow;\
44 foo(const json_string &) json_nothrow;
46 #define DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
47 foo(json_int_t) const json_nothrow;\
48 foo(json_number) const json_nothrow;\
49 foo(bool) const json_nothrow;\
50 foo(const json_string &) const json_nothrow;\
52 #define DECLARE_FOR_ALL_TYPES_CONST(foo)\
53 DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
54 foo(const JSONNode &) const json_nothrow;
56 #define IMPLEMENT_FOR_ALL_NUMBERS(foo)\
65 #ifdef JSON_ISO_STRICT
66 #define DECLARE_FOR_LONG_LONG(foo)
67 #define DECLARE_FOR_LONG_LONG_CONST(foo)
68 #define IMPLEMENT_FOR_LONG_LONG(foo)
69 #define DECLARE_FOR_LONG_DOUBLE(foo)
70 #define DECLARE_FOR_LONG_DOUBLE_CONST(foo)
71 #define IMPLEMENT_FOR_LONG_DOUBLE(foo)
73 #define DECLARE_FOR_LONG_LONG(foo) foo(long long) json_nothrow; foo(unsigned long long) json_nothrow;
74 #define DECLARE_FOR_LONG_LONG_CONST(foo) foo(long long) const json_nothrow; foo(unsigned long long) const json_nothrow;
75 #define IMPLEMENT_FOR_LONG_LONG(foo) foo(long long) foo(unsigned long long)
76 #define DECLARE_FOR_LONG_DOUBLE(foo) foo(long double) json_nothrow;
77 #define DECLARE_FOR_LONG_DOUBLE_CONST(foo) foo(long double) const json_nothrow;
78 #define IMPLEMENT_FOR_LONG_DOUBLE(foo) foo(long double)
81 #define DECLARE_FOR_ALL_TYPES(foo)\
82 foo(char) json_nothrow; foo(unsigned char) json_nothrow;\
83 foo(short) json_nothrow; foo(unsigned short) json_nothrow;\
84 foo(int) json_nothrow; foo(unsigned int) json_nothrow;\
85 foo(long) json_nothrow; foo(unsigned long) json_nothrow;\
86 foo(float) json_nothrow; foo(double) json_nothrow;\
87 foo(bool) json_nothrow;\
88 foo(const json_string &) json_nothrow;\
89 foo(const json_char *) json_nothrow;\
90 DECLARE_FOR_LONG_LONG(foo)\
91 DECLARE_FOR_LONG_DOUBLE(foo)
93 #define DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
94 foo(char) const json_nothrow; foo(unsigned char) const json_nothrow;\
95 foo(short) const json_nothrow; foo(unsigned short) const json_nothrow;\
96 foo(int) const json_nothrow; foo(unsigned int) const json_nothrow;\
97 foo(long) const json_nothrow; foo(unsigned long) const json_nothrow;\
98 foo(float) const json_nothrow; foo(double) const json_nothrow;\
99 foo(bool) const json_nothrow;\
100 foo(const json_string &) const json_nothrow;\
101 DECLARE_FOR_LONG_LONG_CONST(foo)\
102 DECLARE_FOR_LONG_DOUBLE_CONST(foo)
104 #define DECLARE_FOR_ALL_TYPES_CONST(foo)\
105 DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
106 foo(const JSONNode &) const json_nothrow;\
107 foo(const json_char *) const json_nothrow;
109 #define IMPLEMENT_FOR_ALL_NUMBERS(foo)\
110 foo(char) foo(unsigned char)\
111 foo(short) foo(unsigned short)\
112 foo(int) foo(unsigned int)\
113 foo(long) foo(unsigned long)\
114 foo(float) foo(double)\
115 IMPLEMENT_FOR_LONG_LONG(foo)\
116 IMPLEMENT_FOR_LONG_DOUBLE(foo)
120 #define IMPLEMENT_FOR_ALL_TYPES(foo)\
121 IMPLEMENT_FOR_ALL_NUMBERS(foo)\
122 foo(const json_string &)\
135 explicit JSONNode(
char mytype = JSON_NODE) json_nothrow json_hot;
136 #define DECLARE_CTOR(type) explicit JSONNode(const json_string & name_t, type value_t)
137 DECLARE_FOR_ALL_TYPES(DECLARE_CTOR)
140 ~
JSONNode(
void) json_nothrow json_hot;
142 #if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY))
144 void set_name_(
const json_string & newname) json_nothrow json_write_priority;
147 json_index_t size(
void)
const json_nothrow json_read_priority;
148 bool empty(
void)
const json_nothrow json_read_priority;
149 void clear(
void) json_nothrow json_cold;
150 unsigned char type(
void)
const json_nothrow json_read_priority;
152 json_string name(
void)
const json_nothrow json_read_priority;
153 void set_name(
const json_string & newname) json_nothrow json_write_priority;
155 void set_comment(
const json_string & comment) json_nothrow;
158 #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
159 void preparse(
void) json_nothrow json_read_priority;
163 json_string as_string(
void)
const json_nothrow json_read_priority;
164 json_int_t as_int(
void)
const json_nothrow json_read_priority;
165 json_number as_float(
void)
const json_nothrow json_read_priority;
166 bool as_bool(
void)
const json_nothrow json_read_priority;
169 JSONNode as_node(
void)
const json_nothrow json_read_priority;
170 JSONNode as_array(
void)
const json_nothrow json_read_priority;
171 void cast(
char newtype) json_nothrow;
175 std::string as_binary(
void)
const json_nothrow json_cold;
176 void set_binary(
const unsigned char * bin,
size_t bytes) json_nothrow json_cold;
179 JSONNode & at(json_index_t pos) json_throws(std::out_of_range);
180 const JSONNode & at(json_index_t pos)
const json_throws(std::out_of_range);
182 JSONNode & operator[](json_index_t pos) json_nothrow;
183 const JSONNode & operator[](json_index_t pos)
const json_nothrow;
187 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
189 const JSONNode & at_nocase(
const json_string & name_t)
const json_throws(std::out_of_range);
195 void push_back(
JSONNode * node) json_nothrow;
197 void push_back(
const JSONNode & node) json_nothrow;
199 void reserve(json_index_t siz) json_nothrow;
200 JSONNode JSON_PTR_LIB pop_back(json_index_t pos) json_throws(std::out_of_range);
202 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
203 JSONNode JSON_PTR_LIB pop_back_nocase(
const json_string & name_t) json_throws(std::out_of_range);
206 DECLARE_FOR_ALL_TYPES(
JSONNode &
operator =)
209 DECLARE_FOR_ALL_TYPES_CONST(
bool operator ==)
210 DECLARE_FOR_ALL_TYPES_CONST(
bool operator !=)
213 void nullify(
void) json_nothrow;
214 void swap(
JSONNode & other) json_nothrow;
215 void merge(
JSONNode & other) json_nothrow json_cold;
216 void merge(
unsigned int num, ...) json_nothrow json_cold;
217 JSONNode duplicate(
void)
const json_nothrow;
221 #ifdef JSON_ITERATORS
223 #define json_iterator_ptr(iter) iter.it
224 #define ptr_to_json_iterator(iter) json_iterator(iter)
227 struct const_iterator {
228 inline const_iterator& operator ++(
void) json_nothrow { ++it;
return *
this; }
229 inline const_iterator& operator --(
void) json_nothrow { --it;
return *
this; }
230 inline const_iterator& operator +=(
long i) json_nothrow { it += i;
return *
this; }
231 inline const_iterator& operator -=(
long i) json_nothrow { it -= i;
return *
this; }
232 inline const_iterator operator ++(
int) json_nothrow {
233 const_iterator result(*
this);
237 inline const_iterator operator --(
int) json_nothrow {
238 const_iterator result(*
this);
242 inline const_iterator operator +(
long i)
const json_nothrow {
243 const_iterator result(*
this);
247 inline const_iterator operator -(
long i)
const json_nothrow {
248 const_iterator result(*
this);
252 inline const JSONNode& operator [](
size_t pos)
const json_nothrow {
return const_cast<const JSONNode&
>(*it[pos]); };
253 inline const JSONNode& operator *(
void)
const json_nothrow {
return const_cast<const JSONNode&
>(*(*it)); }
254 inline const JSONNode* operator ->(
void)
const json_nothrow {
return const_cast<const JSONNode*
>(*it); }
255 inline bool operator == (
const const_iterator & other)
const json_nothrow {
return it == other.it; }
256 inline bool operator != (
const const_iterator & other)
const json_nothrow {
return it != other.it; }
257 inline bool operator > (
const const_iterator & other)
const json_nothrow {
return it > other.it; }
258 inline bool operator >= (
const const_iterator & other)
const json_nothrow {
return it >= other.it; }
259 inline bool operator < (
const const_iterator & other)
const json_nothrow {
return it < other.it; }
260 inline bool operator <= (
const const_iterator & other)
const json_nothrow {
return it <= other.it; }
262 inline bool operator == (
const iterator & other)
const json_nothrow {
return it == other.it; }
263 inline bool operator != (
const iterator & other)
const json_nothrow {
return it != other.it; }
264 inline bool operator > (
const iterator & other)
const json_nothrow {
return it > other.it; }
265 inline bool operator >= (
const iterator & other)
const json_nothrow {
return it >= other.it; }
266 inline bool operator < (
const iterator & other)
const json_nothrow {
return it < other.it; }
267 inline bool operator <= (
const iterator & other)
const json_nothrow {
return it <= other.it; }
269 inline const_iterator & operator =(
const const_iterator & orig) json_nothrow { it = orig.it;
return *
this; }
270 const_iterator (
const const_iterator & orig) json_nothrow : it(orig.it) {}
273 const_iterator(
JSONNode ** starter) : it(starter) {}
275 friend struct iterator;
277 const_iterator begin(
void)
const json_nothrow;
278 const_iterator end(
void)
const json_nothrow;
281 inline iterator& operator ++(
void) json_nothrow { ++it;
return *
this; }
282 inline iterator& operator --(
void) json_nothrow { --it;
return *
this; }
283 inline iterator& operator +=(
long i) json_nothrow { it += i;
return *
this; }
284 inline iterator& operator -=(
long i) json_nothrow { it -= i;
return *
this; }
285 inline iterator operator ++(
int) json_nothrow {
286 iterator result(*
this);
290 inline iterator operator --(
int) json_nothrow {
291 iterator result(*
this);
295 inline iterator operator +(
long i)
const json_nothrow {
296 iterator result(*
this);
300 inline iterator operator -(
long i)
const json_nothrow {
301 iterator result(*
this);
305 inline JSONNode& operator [](
size_t pos)
const json_nothrow {
return *it[pos]; };
306 inline JSONNode& operator *(
void)
const json_nothrow {
return *(*it); }
307 inline JSONNode* operator ->(
void)
const json_nothrow {
return *it; }
308 inline bool operator == (
const iterator & other)
const json_nothrow {
return it == other.it; }
309 inline bool operator != (
const iterator & other)
const json_nothrow {
return it != other.it; }
310 inline bool operator > (
const iterator & other)
const json_nothrow {
return it > other.it; }
311 inline bool operator >= (
const iterator & other)
const json_nothrow {
return it >= other.it; }
312 inline bool operator < (
const iterator & other)
const json_nothrow {
return it < other.it; }
313 inline bool operator <= (
const iterator & other)
const json_nothrow {
return it <= other.it; }
314 inline iterator & operator = (
const iterator & orig) json_nothrow { it = orig.it;
return *
this; }
316 inline bool operator == (
const const_iterator & other)
const json_nothrow {
return it == other.it; }
317 inline bool operator != (
const const_iterator & other)
const json_nothrow {
return it != other.it; }
318 inline bool operator > (
const const_iterator & other)
const json_nothrow {
return it > other.it; }
319 inline bool operator >= (
const const_iterator & other)
const json_nothrow {
return it >= other.it; }
320 inline bool operator < (
const const_iterator & other)
const json_nothrow {
return it < other.it; }
321 inline bool operator <= (
const const_iterator & other)
const json_nothrow {
return it <= other.it; }
322 inline iterator & operator = (
const const_iterator & orig) json_nothrow { it = orig.it;
return *
this; }
324 iterator (
const iterator & orig) json_nothrow : it(orig.it) {}
325 inline operator const_iterator()
const json_nothrow {
return const_iterator(it); }
328 iterator(
JSONNode ** starter) json_nothrow : it(starter) {}
330 friend struct const_iterator;
332 typedef iterator json_iterator;
334 struct reverse_iterator;
335 struct reverse_const_iterator {
336 inline reverse_const_iterator& operator ++(
void) json_nothrow{ --it;
return *
this; }
337 inline reverse_const_iterator& operator --(
void) json_nothrow{ ++it;
return *
this; }
338 inline reverse_const_iterator& operator +=(
long i) json_nothrow{ it -= i;
return *
this; }
339 inline reverse_const_iterator& operator -=(
long i) json_nothrow{ it += i;
return *
this; }
340 inline reverse_const_iterator operator ++(
int) json_nothrow{
341 reverse_const_iterator result(*
this);
345 inline reverse_const_iterator operator --(
int) json_nothrow{
346 reverse_const_iterator result(*
this);
350 inline reverse_const_iterator operator +(
long i)
const json_nothrow {
351 reverse_const_iterator result(*
this);
355 inline reverse_const_iterator operator -(
long i)
const json_nothrow {
356 reverse_const_iterator result(*
this);
360 inline const JSONNode& operator [](
size_t pos)
const json_nothrow {
return const_cast<const JSONNode&
>(*it[pos]); };
361 inline const JSONNode& operator *(
void)
const json_nothrow {
return const_cast<const JSONNode&
>(*(*it)); }
362 inline const JSONNode* operator ->(
void)
const json_nothrow {
return const_cast<const JSONNode*
>(*it); }
363 inline bool operator == (
const reverse_const_iterator & other)
const json_nothrow {
return it == other.it; }
364 inline bool operator != (
const reverse_const_iterator & other)
const json_nothrow {
return it != other.it; }
365 inline bool operator < (
const reverse_const_iterator & other)
const json_nothrow {
return it > other.it; }
366 inline bool operator <= (
const reverse_const_iterator & other)
const json_nothrow {
return it >= other.it; }
367 inline bool operator > (
const reverse_const_iterator & other)
const json_nothrow {
return it < other.it; }
368 inline bool operator >= (
const reverse_const_iterator & other)
const json_nothrow {
return it <= other.it; }
370 inline bool operator == (
const reverse_iterator & other)
const json_nothrow {
return it == other.it; }
371 inline bool operator != (
const reverse_iterator & other)
const json_nothrow {
return it != other.it; }
372 inline bool operator < (
const reverse_iterator & other)
const json_nothrow {
return it > other.it; }
373 inline bool operator <= (
const reverse_iterator & other)
const json_nothrow {
return it >= other.it; }
374 inline bool operator > (
const reverse_iterator & other)
const json_nothrow {
return it < other.it; }
375 inline bool operator >= (
const reverse_iterator & other)
const json_nothrow {
return it <= other.it; }
377 inline reverse_const_iterator & operator = (
const reverse_const_iterator & orig) json_nothrow { it = orig.it;
return *
this; }
378 reverse_const_iterator (
const reverse_const_iterator & orig) json_nothrow : it(orig.it) {}
381 reverse_const_iterator(
JSONNode ** starter) json_nothrow : it(starter) {}
383 friend struct reverse_iterator;
385 reverse_const_iterator rbegin(
void)
const json_nothrow;
386 reverse_const_iterator rend(
void)
const json_nothrow;
388 struct reverse_iterator {
389 inline reverse_iterator& operator ++(
void) json_nothrow { --it;
return *
this; }
390 inline reverse_iterator& operator --(
void) json_nothrow { ++it;
return *
this; }
391 inline reverse_iterator& operator +=(
long i) json_nothrow { it -= i;
return *
this; }
392 inline reverse_iterator& operator -=(
long i) json_nothrow { it += i;
return *
this; }
393 inline reverse_iterator operator ++(
int) json_nothrow {
394 reverse_iterator result(*
this);
398 inline reverse_iterator operator --(
int) json_nothrow {
399 reverse_iterator result(*
this);
403 inline reverse_iterator operator +(
long i)
const json_nothrow {
404 reverse_iterator result(*
this);
408 inline reverse_iterator operator -(
long i)
const json_nothrow {
409 reverse_iterator result(*
this);
413 inline JSONNode& operator [](
size_t pos)
const json_nothrow {
return *it[pos]; };
414 inline JSONNode& operator *(
void)
const json_nothrow {
return *(*it); }
415 inline JSONNode* operator ->(
void)
const json_nothrow {
return *it; }
416 inline bool operator == (
const reverse_iterator & other)
const json_nothrow {
return it == other.it; }
417 inline bool operator != (
const reverse_iterator & other)
const json_nothrow {
return it != other.it; }
418 inline bool operator < (
const reverse_iterator & other)
const json_nothrow {
return it > other.it; }
419 inline bool operator <= (
const reverse_iterator & other)
const json_nothrow {
return it >= other.it; }
420 inline bool operator > (
const reverse_iterator & other)
const json_nothrow {
return it < other.it; }
421 inline bool operator >= (
const reverse_iterator & other)
const json_nothrow {
return it <= other.it; }
423 inline bool operator == (
const reverse_const_iterator & other)
const json_nothrow {
return it == other.it; }
424 inline bool operator != (
const reverse_const_iterator & other)
const json_nothrow {
return it != other.it; }
425 inline bool operator < (
const reverse_const_iterator & other)
const json_nothrow {
return it > other.it; }
426 inline bool operator <= (
const reverse_const_iterator & other)
const json_nothrow {
return it >= other.it; }
427 inline bool operator > (
const reverse_const_iterator & other)
const json_nothrow {
return it < other.it; }
428 inline bool operator >= (
const reverse_const_iterator & other)
const json_nothrow {
return it <= other.it; }
430 inline reverse_iterator & operator = (
const reverse_iterator & orig) json_nothrow { it = orig.it;
return *
this; }
431 reverse_iterator (
const reverse_iterator & orig) json_nothrow : it(orig.it) {}
432 inline operator reverse_const_iterator()
const json_nothrow {
return reverse_const_iterator(it); }
435 reverse_iterator(
JSONNode ** starter) json_nothrow : it(starter) {}
437 friend struct reverse_const_iterator;
439 reverse_iterator rbegin(
void) json_nothrow;
440 reverse_iterator rend(
void) json_nothrow;
442 const_iterator find(
const json_string & name_t)
const json_nothrow;
443 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
444 const_iterator find_nocase(
const json_string & name_t)
const json_nothrow;
447 reverse_iterator erase(reverse_iterator pos) json_nothrow;
448 reverse_iterator erase(reverse_iterator start,
const reverse_iterator & end) json_nothrow;
450 iterator insert(iterator pos,
const JSONNode & x) json_nothrow;
451 reverse_iterator insert(reverse_iterator pos,
const JSONNode & x) json_nothrow;
452 iterator insert(iterator pos,
const reverse_iterator & _start,
const reverse_iterator & _end) json_nothrow;
453 reverse_iterator insert(reverse_iterator pos,
const iterator & _start,
const iterator & _end) json_nothrow;
454 reverse_iterator insert(reverse_iterator pos,
const reverse_iterator & _start,
const reverse_iterator & _end) json_nothrow;
456 json_iterator insert(json_iterator pos,
const const_iterator & _start,
const const_iterator & _end) json_nothrow;
457 reverse_iterator insert(reverse_iterator pos,
const const_iterator & _start,
const const_iterator & _end) json_nothrow;
458 json_iterator insert(json_iterator pos,
const reverse_const_iterator & _start,
const reverse_const_iterator & _end) json_nothrow;
459 reverse_iterator insert(reverse_iterator pos,
const reverse_const_iterator & _start,
const reverse_const_iterator & _end) json_nothrow;
462 #define json_iterator_ptr(iter) iter
463 #define ptr_to_json_iterator(iter) iter
464 json_iterator insert(json_iterator pos,
JSONNode * x) json_nothrow;
467 json_iterator begin(
void) json_nothrow;
468 json_iterator end(
void) json_nothrow;
470 json_iterator find(
const json_string & name_t) json_nothrow;
471 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
472 json_iterator find_nocase(
const json_string & name_t) json_nothrow;
474 json_iterator erase(json_iterator pos) json_nothrow;
475 json_iterator erase(json_iterator start,
const json_iterator & end) json_nothrow;
476 json_iterator insert(json_iterator pos,
const json_iterator & _start,
const json_iterator & _end) json_nothrow;
480 #ifdef JSON_MUTEX_CALLBACKS
481 static void register_mutex_callbacks(json_mutex_callback_t lock, json_mutex_callback_t unlock,
void * manager_lock) json_nothrow json_cold;
482 #ifdef JSON_MUTEX_MANAGE
483 static void register_mutex_destructor(json_mutex_callback_t destroy) json_nothrow json_cold;
485 static void set_global_mutex(
void * mutex) json_nothrow json_cold;
486 void set_mutex(
void * mutex) json_nothrow json_cold;
487 void lock(
int thread) json_nothrow json_cold;
488 void unlock(
int thread) json_nothrow json_cold;
491 auto_lock(
JSONNode & node,
int thread) json_nothrow: mynode(&node), mythread(thread){
492 mynode -> lock(mythread);
494 auto_lock(
JSONNode * node,
int thread) json_nothrow: mynode(node), mythread(thread){
495 mynode -> lock(mythread);
497 ~auto_lock(
void) json_nothrow{
498 mynode -> unlock(mythread);
501 auto_lock & operator = (
const auto_lock &);
502 auto_lock(
const auto_lock &);
506 static void * getThisLock(
JSONNode * pthis) json_nothrow json_cold;
509 #ifdef JSON_WRITE_PRIORITY
510 #ifdef JSON_LESS_MEMORY
511 #define DEFAULT_APPROX_SIZE 8
512 #define DEFAULT_APPROX_SIZE_FORMATTED 16
514 #define DEFAULT_APPROX_SIZE 1024
515 #define DEFAULT_APPROX_SIZE_FORMATTED 2048
517 json_string write(
size_t approxsize = DEFAULT_APPROX_SIZE)
const json_nothrow json_write_priority;
518 json_string write_formatted(
size_t approxsize = DEFAULT_APPROX_SIZE_FORMATTED)
const json_nothrow json_write_priority;
523 JSONNode dump(
void)
const json_nothrow;
526 static void deleteJSONNode(
JSONNode * ptr) json_nothrow json_hot;
529 #define DECLARE_CAST_OP(type) operator type()
532 static JSONNode * newJSONNode(
const JSONNode & orig JSON_MUTEX_COPY_DECL2) json_hot;
534 #ifdef JSON_READ_PRIORITY
536 JSONNode(
const json_string & unparsed) json_nothrow :
internal(internalJSONNode::newInternal(unparsed)){
545 void decRef(
void) json_nothrow json_hot;
546 #ifdef JSON_REF_COUNT
547 void makeUniqueInternal(
void) json_nothrow;
548 void merge(
JSONNode * other) json_nothrow json_cold;
553 JSONNode dump(
size_t & totalmemory) json_nothrow;
557 #ifdef JSON_ITERATORS
559 json_iterator insertFRR(json_iterator pos,
JSONNode **
const _start,
JSONNode **
const _end) json_nothrow;
560 reverse_iterator insertRRR(reverse_iterator pos,
JSONNode **
const _start,
JSONNode **
const _end) json_nothrow;
561 reverse_iterator insertRFF(reverse_iterator pos,
JSONNode **
const _start,
JSONNode **
const _end) json_nothrow;
563 json_iterator insertFFF(json_iterator pos,
JSONNode **
const _start,
JSONNode **
const _end) json_nothrow;
566 inline void clear_name(
void) json_nothrow {
567 JSON_CHECK_INTERNAL();
568 makeUniqueInternal();
569 internal -> clearname();
584 #define CAST_OP(type)\
585 inline JSONNode::operator type() const json_nothrow {\
586 return static_cast<type>(*internal);\
591 inline JSONNode::JSONNode(
char mytype) json_nothrow :
internal(internalJSONNode::newInternal(mytype)){
592 JSON_ASSERT((mytype == JSON_NULL) ||
593 (mytype == JSON_STRING) ||
594 (mytype == JSON_NUMBER) ||
595 (mytype == JSON_BOOL) ||
596 (mytype == JSON_ARRAY) ||
597 (mytype == JSON_NODE), JSON_TEXT(
"Not a proper JSON type"));
601 inline JSONNode::JSONNode(
const JSONNode & orig) json_nothrow :
internal(orig.internal -> incRef()){
606 inline JSONNode::JSONNode(
bool,
JSONNode & orig) json_nothrow :
internal(orig.internal){
611 inline JSONNode::~JSONNode(
void) json_nothrow{
612 if (
internal != 0) decRef();
616 inline json_index_t JSONNode::size(
void) const json_nothrow {
617 JSON_CHECK_INTERNAL();
618 return internal -> size();
621 inline bool JSONNode::empty(
void) const json_nothrow {
622 JSON_CHECK_INTERNAL();
623 return internal -> empty();
626 inline void JSONNode::clear(
void) json_nothrow {
627 JSON_CHECK_INTERNAL();
629 makeUniqueInternal();
630 internal -> CHILDREN -> clear();
634 inline unsigned char JSONNode::type(
void) const json_nothrow {
635 JSON_CHECK_INTERNAL();
636 return internal -> type();
639 inline json_string JSONNode::name(
void) const json_nothrow {
640 JSON_CHECK_INTERNAL();
641 return internal -> name();
644 inline void JSONNode::set_name(
const json_string & newname) json_nothrow{
645 JSON_CHECK_INTERNAL();
646 makeUniqueInternal();
647 internal -> setname(newname);
651 inline void JSONNode::set_comment(
const json_string & newname) json_nothrow{
652 JSON_CHECK_INTERNAL();
653 makeUniqueInternal();
654 internal -> setcomment(newname);
657 inline json_string JSONNode::get_comment(
void) const json_nothrow {
658 JSON_CHECK_INTERNAL();
659 return internal -> getcomment();
664 inline json_string JSONNode::as_string(
void) const json_nothrow {
665 JSON_CHECK_INTERNAL();
669 inline json_int_t JSONNode::as_int(
void) const json_nothrow {
670 JSON_CHECK_INTERNAL();
671 return static_cast<json_int_t
>(*internal);
674 inline json_number JSONNode::as_float(
void) const json_nothrow {
675 JSON_CHECK_INTERNAL();
676 return static_cast<json_number
>(*internal);
679 inline bool JSONNode::as_bool(
void) const json_nothrow {
680 JSON_CHECK_INTERNAL();
681 return static_cast<bool>(*internal);
686 inline void JSONNode::set_binary(
const unsigned char * bin,
size_t bytes) json_nothrow{
687 JSON_CHECK_INTERNAL();
688 *
this = JSONBase64::json_encode64(bin, bytes);
691 inline std::string JSONNode::as_binary(
void) const json_nothrow {
692 JSON_ASSERT_SAFE(type() == JSON_STRING, JSON_TEXT(
"using as_binary for a non-string type"),
return json_global(EMPTY_STD_STRING););
693 JSON_CHECK_INTERNAL();
694 return JSONBase64::json_decode64(as_string());
699 JSON_CHECK_INTERNAL();
700 makeUniqueInternal();
701 return *(*(
internal -> at(name_t)));
704 inline const JSONNode & JSONNode::operator[](
const json_string & name_t)
const json_nothrow {
705 JSON_CHECK_INTERNAL();
706 return *(*(
internal -> at(name_t)));
710 inline void JSONNode::push_back(
JSONNode * child) json_nothrow{
712 inline void JSONNode::push_back(
const JSONNode & child) json_nothrow{
714 JSON_CHECK_INTERNAL();
715 makeUniqueInternal();
716 internal -> push_back(child);
719 inline void JSONNode::reserve(json_index_t siz) json_nothrow{
720 makeUniqueInternal();
721 internal -> reserve(siz);
724 inline JSONNode & JSONNode::operator = (
const JSONNode & orig) json_nothrow {
725 JSON_CHECK_INTERNAL();
726 #ifdef JSON_REF_COUNT
727 if (
internal == orig.internal)
return *
this;
730 internal = orig.internal -> incRef();
735 inline JSONNode & JSONNode::operator = (
const json_char * val) json_nothrow {
736 JSON_CHECK_INTERNAL();
742 #define NODE_SET_TYPED(type)\
743 inline JSONNode & JSONNode::operator = (type val) json_nothrow {\
745 JSON_CHECK_INTERNAL();\
746 makeUniqueInternal();\
747 internal -> Set(val);\
750 IMPLEMENT_FOR_ALL_TYPES(NODE_SET_TYPED)
757 #define NODE_CHECK_EQUALITY(type)\
758 inline bool JSONNode::operator == (type val) const json_nothrow {\
759 JSON_CHECK_INTERNAL();\
760 return internal -> IsEqualToNum<type>(val);\
763 IMPLEMENT_FOR_ALL_NUMBERS(NODE_CHECK_EQUALITY)
766 JSON_CHECK_INTERNAL();
767 return internal -> IsEqualTo(val);
771 inline bool JSONNode::operator == (
const json_char * val)
const json_nothrow {
772 JSON_CHECK_INTERNAL();
777 inline bool JSONNode::operator == (
bool val)
const json_nothrow {
778 JSON_CHECK_INTERNAL();
779 return internal -> IsEqualTo(val);
781 inline bool JSONNode::operator == (
const JSONNode & val)
const json_nothrow {
782 JSON_CHECK_INTERNAL();
783 return internal -> IsEqualTo(val.internal);
792 #define NODE_CHECK_INEQUALITY(type)\
793 inline bool JSONNode::operator != (type val) const json_nothrow {\
794 JSON_CHECK_INTERNAL();\
795 return !(*this == val);\
798 IMPLEMENT_FOR_ALL_TYPES(NODE_CHECK_INEQUALITY)
799 NODE_CHECK_INEQUALITY(const
JSONNode &)
801 NODE_CHECK_INEQUALITY(
const json_char * )
804 inline void JSONNode::nullify(
void) json_nothrow {
805 JSON_CHECK_INTERNAL();
806 makeUniqueInternal();
807 internal -> Nullify();
810 inline void JSONNode::swap(
JSONNode & other) json_nothrow {
811 JSON_CHECK_INTERNAL();
813 other.internal =
internal;
815 JSON_CHECK_INTERNAL();
818 inline void JSONNode::decRef(
void) json_nothrow {
819 JSON_CHECK_INTERNAL();
820 #ifdef JSON_REF_COUNT
821 internal -> decRef();
822 if (
internal -> hasNoReferences()){
823 internalJSONNode::deleteInternal(
internal);
826 internalJSONNode::deleteInternal(
internal);
830 #ifdef JSON_REF_COUNT
831 inline void JSONNode::makeUniqueInternal() json_nothrow {
832 JSON_CHECK_INTERNAL();
833 internal =
internal -> makeUnique();
837 #ifdef JSON_ITERATORS
838 inline JSONNode::json_iterator JSONNode::begin(
void) json_nothrow {
839 JSON_CHECK_INTERNAL();
840 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"begin"));
841 makeUniqueInternal();
842 return json_iterator(
internal -> begin());
845 inline JSONNode::json_iterator JSONNode::end(
void) json_nothrow {
846 JSON_CHECK_INTERNAL();
847 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"end"));
848 makeUniqueInternal();
849 return json_iterator(
internal -> end());
853 inline JSONNode::const_iterator JSONNode::begin(
void) const json_nothrow {
854 JSON_CHECK_INTERNAL();
855 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"begin"));
856 return JSONNode::const_iterator(
internal -> begin());
859 inline JSONNode::const_iterator JSONNode::end(
void) const json_nothrow {
860 JSON_CHECK_INTERNAL();
861 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"end"));
862 return JSONNode::const_iterator(
internal -> end());
865 inline JSONNode::reverse_iterator JSONNode::rbegin(
void) json_nothrow {
866 JSON_CHECK_INTERNAL();
867 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"rbegin"));
868 makeUniqueInternal();
869 return JSONNode::reverse_iterator(
internal -> end() - 1);
872 inline JSONNode::reverse_iterator JSONNode::rend(
void) json_nothrow {
873 JSON_CHECK_INTERNAL();
874 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"rend"));
875 makeUniqueInternal();
876 return JSONNode::reverse_iterator(
internal -> begin() - 1);
879 inline JSONNode::reverse_const_iterator JSONNode::rbegin(
void) const json_nothrow {
880 JSON_CHECK_INTERNAL();
881 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"rbegin"));
882 return JSONNode::reverse_const_iterator(
internal -> end() - 1);
885 inline JSONNode::reverse_const_iterator JSONNode::rend(
void) const json_nothrow {
886 JSON_CHECK_INTERNAL();
887 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT(
"rend"));
888 return JSONNode::reverse_const_iterator(
internal -> begin() - 1);
891 inline JSONNode::iterator JSONNode::insert(json_iterator pos,
const const_iterator & _start,
const const_iterator & _end) json_nothrow {
892 return insertFFF(pos, _start.it, _end.it);
895 inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos,
const const_iterator & _start,
const const_iterator & _end) json_nothrow {
896 return insertRFF(pos, _start.it, _end.it);
899 inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos,
const iterator & _start,
const iterator & _end) json_nothrow {
900 return insertRFF(pos, _start.it, _end.it);
903 inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos,
const reverse_const_iterator & _start,
const reverse_const_iterator & _end) json_nothrow {
904 return insertRRR(pos, _start.it, _end.it);
907 inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos,
const reverse_iterator & _start,
const reverse_iterator & _end) json_nothrow {
908 return insertRRR(pos, _start.it, _end.it);
911 inline JSONNode::iterator JSONNode::insert(json_iterator pos,
const reverse_const_iterator & _start,
const reverse_const_iterator & _end) json_nothrow {
912 return insertFRR(pos, _start.it, _end.it);
915 inline JSONNode::iterator JSONNode::insert(iterator pos,
const reverse_iterator & _start,
const reverse_iterator & _end) json_nothrow {
916 return insertFRR(pos, _start.it, _end.it);
920 inline JSONNode::json_iterator JSONNode::insert(json_iterator pos,
const json_iterator & _start,
const json_iterator & _end) json_nothrow {
921 return insertFFF(pos, json_iterator_ptr(_start), json_iterator_ptr(_end));
925 #ifdef JSON_WRITE_PRIORITY
926 inline json_string JSONNode::write(
size_t approxsize)
const json_nothrow {
927 JSON_CHECK_INTERNAL();
928 JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT(
"Writing a non-writable node"),
return json_global(EMPTY_JSON_STRING););
930 result.reserve(approxsize);
931 internal -> Write(0xFFFFFFFF,
true, result);
935 inline json_string JSONNode::write_formatted(
size_t approxsize)
const json_nothrow {
936 JSON_CHECK_INTERNAL();
937 JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT(
"Writing a non-writable node"),
return json_global(EMPTY_JSON_STRING););
939 result.reserve(approxsize);
940 internal -> Write(0,
true, result);
946 #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
947 inline void JSONNode::preparse(
void) json_nothrow {
948 JSON_CHECK_INTERNAL();
949 internal -> preparse();
955 inline JSONNode JSONNode::dump(
void) const json_nothrow {
956 JSON_CHECK_INTERNAL();
958 dumpage.push_back(JSON_NEW(
JSONNode(JSON_TEXT(
"this"), (
long)
this)));
960 JSONNode node(
internal -> Dump(total));
961 dumpage.push_back(JSON_NEW(
JSONNode(JSON_TEXT(
"total bytes used"), total)));
962 dumpage.push_back(JSON_NEW(
JSONNode(JSON_TEXT(
"bytes used"),
sizeof(
JSONNode))));
963 dumpage.push_back(JSON_NEW(node));
967 inline JSONNode JSONNode::dump(
size_t & totalmemory) json_nothrow {
968 JSON_CHECK_INTERNAL();
970 dumpage.push_back(JSON_NEW(
JSONNode(JSON_TEXT(
"this"), (
long)
this)));
971 dumpage.push_back(JSON_NEW(
JSONNode(JSON_TEXT(
"bytes used"),
sizeof(
JSONNode))));
972 dumpage.push_back(JSON_NEW(
internal -> Dump(totalmemory)));
978 #ifdef JSON_LESS_MEMORY
982 #pragma pack(pop, JSONNode_pack)
Definition: JSONWorker.h:7
Definition: StringTest.h:22
Definition: JSONNode.h:132
Definition: internalJSONNode.h:81