1 #include "internalJSONNode.h"
2 #include "NumberToString.h"
4 #include "JSONWorker.h"
5 #include "JSONGlobals.h"
7 internalJSONNode::internalJSONNode(
const internalJSONNode & orig) json_nothrow :
8 _type(orig._type), _name(orig._name), _name_encoded(orig._name_encoded),
9 _string(orig._string), _string_encoded(orig._string_encoded), _value(orig._value)
12 initializeFetch(orig.fetched)
13 initializeComment(orig._comment)
14 initializeChildren(0){
19 CHILDREN = jsonChildren::newChildren();
20 if (json_likely(!orig.CHILDREN -> empty())){
21 CHILDREN -> reserve(orig.CHILDREN -> size());
22 json_foreach(orig.CHILDREN, myrunner){
23 CHILDREN -> push_back(JSONNode::newJSONNode((*myrunner) -> duplicate()));
27 #ifdef JSON_MUTEX_CALLBACKS
28 _set_mutex(orig.mylock,
false);
33 #define SetFetchedFalseOrDo(code) code
35 #define SetFetchedFalseOrDo(code) SetFetched(false)
39 #ifdef JSON_READ_PRIORITY
40 internalJSONNode::internalJSONNode(
const json_string & unparsed) json_nothrow : _type(), _name(),_name_encoded(
false), _string(unparsed), _string_encoded(), _value()
43 initializeFetch(false)
44 initializeComment(json_global(EMPTY_JSON_STRING))
45 initializeChildren(0){
51 CHILDREN = jsonChildren::newChildren();
58 CHILDREN = jsonChildren::newChildren();
64 JSON_FAIL_SAFE(JSON_TEXT(
"root not starting with either { or ["), Nullify(););
70 #define LETTERCASE(x, y)\
74 #define LETTERCASE(x, y)\
78 internalJSONNode::internalJSONNode(
const json_string & name_t,
const json_string & value_t) json_nothrow : _type(), _name_encoded(), _name(JSONWorker::FixString(name_t, NAME_ENCODED)), _string(), _string_encoded(), _value()
81 initializeFetch(false)
82 initializeComment(json_global(EMPTY_JSON_STRING))
83 initializeChildren(0){
88 JSON_ASSERT_SAFE(!value_t.empty(), JSON_TEXT(
"empty node"), Nullify();
return;);
90 if (json_unlikely(value_t.empty())){
99 const json_char firstchar = value_t[0];
100 #if defined JSON_DEBUG || defined JSON_SAFE
101 const json_char lastchar = value_t[value_t.length() - 1];
105 case JSON_TEXT(
'\"'):
106 JSON_ASSERT_SAFE(lastchar == JSON_TEXT(
'\"'), JSON_TEXT(
"Unterminated quote"), Nullify();
return;);
108 SetFetchedFalseOrDo(FetchString());
111 JSON_ASSERT_SAFE(lastchar == JSON_TEXT(
'}'), JSON_TEXT(
"Missing }"), Nullify();
return;);
113 CHILDREN = jsonChildren::newChildren();
114 SetFetchedFalseOrDo(FetchNode());
117 JSON_ASSERT_SAFE(lastchar == JSON_TEXT(
']'), JSON_TEXT(
"Missing ]"), Nullify();
return;);
119 CHILDREN = jsonChildren::newChildren();
120 SetFetchedFalseOrDo(FetchArray());
122 LETTERCASE(
't',
'T'):
123 JSON_ASSERT_SAFE(value_t == json_global(CONST_TRUE), json_string(json_global(ERROR_UNKNOWN_LITERAL) + value_t).c_str(), Nullify();
return;);
128 LETTERCASE(
'f',
'F'):
129 JSON_ASSERT_SAFE(value_t == json_global(CONST_FALSE), json_string(json_global(ERROR_UNKNOWN_LITERAL) + value_t).c_str(), Nullify();
return;);
130 _value._bool =
false;
134 LETTERCASE(
'n',
'N'):
135 JSON_ASSERT_SAFE(value_t == json_global(CONST_NULL), json_string(json_global(ERROR_UNKNOWN_LITERAL) + value_t).c_str(), Nullify();
return;);
140 JSON_ASSERT_SAFE(NumberToString::isNumeric(value_t), json_string(json_global(ERROR_UNKNOWN_LITERAL) + value_t).c_str(), Nullify();
return;);
142 SetFetchedFalseOrDo(FetchNumber());
150 internalJSONNode::~internalJSONNode(
void) json_nothrow {
152 #ifdef JSON_MUTEX_CALLBACKS
158 #ifdef JSON_READ_PRIORITY
159 void internalJSONNode::FetchString(
void) const json_nothrow {
160 JSON_ASSERT_SAFE(!_string.empty(), JSON_TEXT(
"JSON json_string type is empty?"), Nullify();
return;);
161 JSON_ASSERT_SAFE(_string[0] == JSON_TEXT(
'\"'), JSON_TEXT(
"JSON json_string type doesn't start with a quotation?"), Nullify();
return;);
162 JSON_ASSERT_SAFE(_string[_string.length() - 1] == JSON_TEXT(
'\"'), JSON_TEXT(
"JSON json_string type doesn't end with a quotation?"), Nullify();
return;);
163 _string = JSONWorker::FixString(json_string(_string.begin() + 1, _string.end() - 1), STRING_ENCODED);
164 #ifdef JSON_LESS_MEMORY
165 JSON_ASSERT(_string.capacity() == _string.length(), JSON_TEXT(
"_string object too large 2"));
169 void internalJSONNode::FetchNode(
void) const json_nothrow {
170 JSON_ASSERT_SAFE(!_string.empty(), JSON_TEXT(
"JSON node type is empty?"), Nullify();
return;);
171 JSON_ASSERT_SAFE(_string[0] == JSON_TEXT(
'{'), JSON_TEXT(
"JSON node type doesn't start with a bracket?"), Nullify();
return;);
172 JSON_ASSERT_SAFE(_string[_string.length() - 1] == JSON_TEXT(
'}'), JSON_TEXT(
"JSON node type doesn't end with a bracket?"), Nullify();
return;);
173 JSONWorker::DoNode(
this, _string);
174 clearString(_string);
177 void internalJSONNode::FetchArray(
void) const json_nothrow {
178 JSON_ASSERT_SAFE(!_string.empty(), JSON_TEXT(
"JSON node type is empty?"), Nullify();
return;);
179 JSON_ASSERT_SAFE(_string[0] == JSON_TEXT(
'['), JSON_TEXT(
"JSON node type doesn't start with a square bracket?"), Nullify();
return;);
180 JSON_ASSERT_SAFE(_string[_string.length() - 1] == JSON_TEXT(
']'), JSON_TEXT(
"JSON node type doesn't end with a square bracket?"), Nullify();
return;);
181 JSONWorker::DoArray(
this, _string);
182 clearString(_string);
188 void internalJSONNode::FetchNumber(
void) const json_nothrow {
190 _value._number = NumberToString::_atof(_string.c_str());
193 const size_t len = _string.length();
194 #if defined(_MSC_VER) && defined(JSON_SAFE)
195 const size_t bytes = (len * (
sizeof(json_char) /
sizeof(
char))) + 1;
196 json_auto<char> temp(bytes);
198 errno_t err = wcstombs_s(&res, temp.ptr, bytes, _string.c_str(), len);
200 _value._number = (json_number)0.0;
203 #elif defined(JSON_SAFE)
204 const size_t bytes = (len * (
sizeof(json_char) /
sizeof(
char))) + 1;
205 json_auto<char> temp(bytes);
206 size_t res = std::wcstombs(temp.ptr, _string.c_str(), len);
207 if (res == (
size_t)-1){
208 _value._number = (json_number)0.0;
212 json_auto<char> temp(len + 1);
213 size_t res = std::wcstombs(temp.ptr, _string.c_str(), len);
215 temp.ptr[res] =
'\0';
216 _value._number = (json_number)std::atof(temp.ptr);
218 _value._number = (json_number)std::atof(_string.c_str());
221 #if((!defined(JSON_CASTABLE) && defined(JSON_LESS_MEMORY)) && !defined(JSON_WRITE_PRIORITY))
222 clearString(_string);
226 #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
227 void internalJSONNode::Fetch(
void) const json_nothrow {
242 #if defined JSON_DEBUG || defined JSON_SAFE
244 JSON_FAIL(JSON_TEXT(
"Fetching an unknown type"));
252 void internalJSONNode::Set(
const json_string & val) json_nothrow {
256 shrinkString(_string);
257 _string_encoded =
true;
262 void internalJSONNode::Set(json_int_t val) json_nothrow {
265 _value._number = (json_number)val;
266 #if(defined(JSON_CASTABLE) || !defined(JSON_LESS_MEMORY) || defined(JSON_WRITE_PRIORITY))
267 _string = NumberToString::_itoa<json_int_t>(val);
269 clearString(_string);
274 void internalJSONNode::Set(json_number val) json_nothrow {
277 _value._number = val;
278 #if(defined(JSON_CASTABLE) || !defined(JSON_LESS_MEMORY) || defined(JSON_WRITE_PRIORITY))
279 _string = NumberToString::_ftoa(val);
281 clearString(_string);
286 #if(defined(JSON_CASTABLE) || !defined(JSON_LESS_MEMORY) || defined(JSON_WRITE_PRIORITY))
287 #define SET(converter, type)\
288 void internalJSONNode::Set(type val) json_nothrow {\
290 _type = JSON_NUMBER;\
291 _value._number = (json_number)val;\
292 _string = NumberToString::converter<type>(val);\
295 #define SET_FLOAT(type) \
296 void internalJSONNode::Set(type val) json_nothrow {\
298 _type = JSON_NUMBER;\
299 _value._number = (json_number)val;\
300 _string = NumberToString::_ftoa(_value._number);\
304 #define SET(converter, type)\
305 void internalJSONNode::Set(type val) json_nothrow {\
307 _type = JSON_NUMBER;\
308 _value._number = (json_number)val;\
309 clearString(_string);\
312 #define SET_FLOAT(type) \
313 void internalJSONNode::Set(type val) json_nothrow {\
315 _type = JSON_NUMBER;\
316 _value._number = (json_number)val;\
317 clearString(_string);\
321 #define SET_INTEGER(type) SET(_itoa, type) SET(_uitoa, unsigned type)
327 #ifndef JSON_ISO_STRICT
328 SET_INTEGER(
long long)
329 SET_FLOAT(
long double)
336 void internalJSONNode::Set(
bool val) json_nothrow {
340 #if(defined(JSON_CASTABLE) || !defined(JSON_LESS_MEMORY) || defined(JSON_WRITE_PRIORITY))
341 _string = val ? json_global(CONST_TRUE) : json_global(CONST_FALSE);
346 bool internalJSONNode::IsEqualTo(
const internalJSONNode * val)
const json_nothrow {
347 if (
this == val)
return true;
348 if (type() != val -> type())
return false;
349 if (_name != val -> _name)
return false;
350 if (type() == JSON_NULL)
return true;
351 #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
357 return val -> _string == _string;
359 return _floatsAreEqual(val -> _value._number, _value._number);
361 return val -> _value._bool == _value._bool;
364 JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT(
"Checking for equality, not sure what type"));
365 if (CHILDREN -> size() != val -> CHILDREN -> size())
return false;
368 JSONNode ** valrunner = val -> CHILDREN -> begin();
369 json_foreach(CHILDREN, myrunner){
370 JSON_ASSERT(*myrunner != NULL, json_global(ERROR_NULL_IN_CHILDREN));
371 JSON_ASSERT(*valrunner != NULL, json_global(ERROR_NULL_IN_CHILDREN));
372 JSON_ASSERT(valrunner != val -> CHILDREN -> end(), JSON_TEXT(
"at the end of other one's children, but they're the same size?"));
373 if (**myrunner != **valrunner)
return false;
379 void internalJSONNode::Nullify(
void) const json_nothrow {
381 #if(defined(JSON_CASTABLE) || !defined(JSON_LESS_MEMORY) || defined(JSON_WRITE_PRIORITY))
382 _string = json_global(CONST_NULL);
384 clearString(_string);
389 #ifdef JSON_MUTEX_CALLBACKS
390 #define JSON_MUTEX_COPY ,mylock
392 #define JSON_MUTEX_COPY
396 void internalJSONNode::push_back(JSONNode * node) json_nothrow {
398 void internalJSONNode::push_back(
const JSONNode & node) json_nothrow {
400 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"push_back"),
return;);
402 #ifdef JSON_MUTEX_CALLBACKS
403 if (mylock != 0) node -> set_mutex(mylock);
405 CHILDREN -> push_back(node);
407 CHILDREN -> push_back(JSONNode::newJSONNode(node JSON_MUTEX_COPY));
411 void internalJSONNode::push_front(
const JSONNode & node) json_nothrow {
412 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"push_front"),
return;);
413 CHILDREN -> push_front(JSONNode::newJSONNode(node JSON_MUTEX_COPY));
416 JSONNode * internalJSONNode::pop_back(json_index_t pos) json_nothrow {
417 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"pop_back"),
return 0;);
418 JSONNode * result = (*CHILDREN)[pos];
419 JSONNode ** temp = CHILDREN -> begin() + pos;
420 CHILDREN -> erase(temp);
424 JSONNode * internalJSONNode::pop_back(
const json_string & name_t) json_nothrow {
425 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"pop_back(str)"),
return 0;);
426 if (JSONNode ** res = at(name_t)){
427 JSONNode * result = *res;
428 CHILDREN -> erase(res);
434 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
435 JSONNode * internalJSONNode::pop_back_nocase(
const json_string & name_t) json_nothrow {
436 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"pop_back_nocase"),
return 0;);
437 if (JSONNode ** res = at_nocase(name_t)){
438 JSONNode * result = *res;
439 CHILDREN -> erase(res);
446 JSONNode ** internalJSONNode::at(
const json_string & name_t) json_nothrow {
447 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"at"),
return 0;);
449 json_foreach(CHILDREN, myrunner){
450 JSON_ASSERT(*myrunner != NULL, json_global(ERROR_NULL_IN_CHILDREN));
451 if (json_unlikely((*myrunner) -> name() == name_t))
return myrunner;
456 #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
457 bool internalJSONNode::AreEqualNoCase(
const json_char * ch_one,
const json_char * ch_two) json_nothrow {
459 const json_char c_one = *ch_one;
460 const json_char c_two = *ch_two;
462 if ((c_two > 64) && (c_two < 91)){
463 if (c_one != (json_char)(c_two + 32))
return false;
464 }
else if ((c_two > 96) && (c_two < 123)){
465 if (c_one != (json_char)(c_two - 32))
return false;
474 return *ch_two ==
'\0';
477 JSONNode ** internalJSONNode::at_nocase(
const json_string & name_t) json_nothrow {
478 JSON_ASSERT_SAFE(isContainer(), json_global(ERROR_NON_CONTAINER) + JSON_TEXT(
"at_nocase"),
return 0;);
480 json_foreach(CHILDREN, myrunner){
481 JSON_ASSERT(*myrunner, json_global(ERROR_NULL_IN_CHILDREN));
482 if (json_unlikely(AreEqualNoCase((*myrunner) -> name().c_str(), name_t.c_str())))
return myrunner;
488 #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
489 void internalJSONNode::preparse(
void) json_nothrow {
492 json_foreach(CHILDREN, myrunner){
493 (*myrunner) -> preparse();
499 internalJSONNode::operator bool() const json_nothrow {
504 return !_floatsAreEqual(_value._number, (json_number)0.0);
509 JSON_ASSERT(type() == JSON_BOOL, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(bool)"));
514 internalJSONNode::operator json_number() const json_nothrow {
519 return (json_number)0.0;
521 return (json_number)(_value._bool ? 1.0 : 0.0);
526 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"as_float"));
527 return (json_number)_value._number;
530 internalJSONNode::operator json_int_t() const json_nothrow {
537 return _value._bool ? 1 : 0;
542 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"as_int"));
543 JSON_ASSERT(_value._number == (json_number)((json_int_t)_value._number), json_string(JSON_TEXT(
"as_int will truncate ")) + _string);
544 return (json_int_t)_value._number;
547 #ifndef JSON_ISO_STRICT
548 internalJSONNode::operator
long double() const json_nothrow {
553 return (
long double)0.0;
555 return (
long double)(_value._bool ? 1.0 : 0.0);
560 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(long double)"));
561 return (
long double)_value._number;
564 internalJSONNode::operator double() const json_nothrow {
571 return (
double)(_value._bool ? 1.0 : 0.0);
576 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(double)"));
577 return (
double)_value._number;
582 #ifdef JSON_ISO_STRICT
583 internalJSONNode::operator long() const json_nothrow
585 internalJSONNode::operator
long long() const json_nothrow
594 return _value._bool ? 1 : 0;
599 #ifdef JSON_ISO_STRICT
600 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(long)"));
601 JSON_ASSERT(_value._number > LONG_MIN, _string + json_global(ERROR_LOWER_RANGE) + JSON_TEXT(
"long"));
602 JSON_ASSERT(_value._number < LONG_MAX, _string + json_global(ERROR_UPPER_RANGE) + JSON_TEXT(
"long"));
603 JSON_ASSERT(_value._number == (json_number)((
long)_value._number), json_string(JSON_TEXT(
"(long) will truncate ")) + _string);
604 return (
long)_value._number;
606 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(long long)"));
608 JSON_ASSERT(_value._number < LONG_LONG_MAX, _string + json_global(ERROR_UPPER_RANGE) + JSON_TEXT(
"long long"));
609 #elif defined(LLONG_MAX)
610 JSON_ASSERT(_value._number < LLONG_MAX, _string + json_global(ERROR_UPPER_RANGE) + JSON_TEXT(
"long long"));
613 JSON_ASSERT(_value._number > LONG_LONG_MIN, _string + json_global(ERROR_LOWER_RANGE) + JSON_TEXT(
"long long"));
614 #elif defined(LLONG_MAX)
615 JSON_ASSERT(_value._number > LLONG_MIN, _string + json_global(ERROR_LOWER_RANGE) + JSON_TEXT(
"long long"));
618 JSON_ASSERT(_value._number == (json_number)((
long long)_value._number), json_string(JSON_TEXT(
"(long long) will truncate ")) + _string);
619 return (
long long)_value._number;
623 #ifdef JSON_ISO_STRICT
624 internalJSONNode::operator
unsigned long() const json_nothrow
626 internalJSONNode::operator
unsigned long long() const json_nothrow
635 return _value._bool ? 1 : 0;
640 #ifdef JSON_ISO_STRICT
641 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(unsigned long)"));
642 JSON_ASSERT(_value._number > 0, _string + json_global(ERROR_LOWER_RANGE) + JSON_TEXT(
"unsigned long"));
643 JSON_ASSERT(_value._number < ULONG_MAX, _string + json_global(ERROR_UPPER_RANGE) + JSON_TEXT(
"unsigned long"));
644 JSON_ASSERT(_value._number == (json_number)((
unsigned long)_value._number), json_string(JSON_TEXT(
"(unsigend long) will truncate ")) + _string);
645 return (
unsigned long)_value._number;
647 JSON_ASSERT(type() == JSON_NUMBER, json_global(ERROR_UNDEFINED) + JSON_TEXT(
"(unsigned long long)"));
648 JSON_ASSERT(_value._number > 0, _string + json_global(ERROR_LOWER_RANGE) + JSON_TEXT(
"unsigned long long"));
649 #ifdef ULONG_LONG_MAX
650 JSON_ASSERT(_value._number < ULONG_LONG_MAX, _string + json_global(ERROR_UPPER_RANGE) + JSON_TEXT(
"unsigned long long"));
651 #elif defined(ULLONG_MAX)
652 JSON_ASSERT(_value._number < ULLONG_MAX, _string + json_global(ERROR_UPPER_RANGE) + JSON_TEXT(
"unsigned long long"));
654 JSON_ASSERT(_value._number == (json_number)((
unsigned long long)_value._number), json_string(JSON_TEXT(
"(unsigned long long) will truncate ")) + _string);
655 return (
unsigned long long)_value._number;
664 #ifdef JSON_MEMORY_POOL
665 #include "JSONMemoryPool.h"
666 static memory_pool<INTERNALNODEPOOL> json_internal_mempool;
669 void internalJSONNode::deleteInternal(internalJSONNode * ptr) json_nothrow {
670 #ifdef JSON_MEMORY_POOL
671 ptr -> ~internalJSONNode();
672 json_internal_mempool.deallocate((
void*)ptr);
673 #elif defined(JSON_MEMORY_CALLBACKS)
674 ptr -> ~internalJSONNode();
675 libjson_free<internalJSONNode>(ptr);
681 internalJSONNode * internalJSONNode::newInternal(
char mytype) {
682 #ifdef JSON_MEMORY_POOL
683 return new((internalJSONNode*)json_internal_mempool.allocate()) internalJSONNode(mytype);
684 #elif defined(JSON_MEMORY_CALLBACKS)
685 return new(json_malloc<internalJSONNode>(1)) internalJSONNode(mytype);
687 return new internalJSONNode(mytype);
691 #ifdef JSON_READ_PRIORITY
692 internalJSONNode * internalJSONNode::newInternal(
const json_string & unparsed) {
693 #ifdef JSON_MEMORY_POOL
694 return new((internalJSONNode*)json_internal_mempool.allocate()) internalJSONNode(unparsed);
695 #elif defined(JSON_MEMORY_CALLBACKS)
696 return new(json_malloc<internalJSONNode>(1)) internalJSONNode(unparsed);
698 return new internalJSONNode(unparsed);
702 internalJSONNode * internalJSONNode::newInternal(
const json_string & name_t,
const json_string & value_t) {
703 #ifdef JSON_MEMORY_POOL
704 return new((internalJSONNode*)json_internal_mempool.allocate()) internalJSONNode(name_t, value_t);
705 #elif defined(JSON_MEMORY_CALLBACKS)
706 return new(json_malloc<internalJSONNode>(1)) internalJSONNode(name_t, value_t);
708 return new internalJSONNode(name_t, value_t);
714 internalJSONNode * internalJSONNode::newInternal(
const internalJSONNode & orig) {
715 #ifdef JSON_MEMORY_POOL
716 return new((internalJSONNode*)json_internal_mempool.allocate()) internalJSONNode(orig);
717 #elif defined(JSON_MEMORY_CALLBACKS)
718 return new(json_malloc<internalJSONNode>(1)) internalJSONNode(orig);
720 return new internalJSONNode(orig);
726 JSONNode internalJSONNode::Dump(
size_t & totalbytes)
const json_nothrow {
727 JSONNode dumpage(JSON_NODE);
728 dumpage.set_name(JSON_TEXT(
"internalJSONNode"));
729 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"this"), (
long)
this)));
732 size_t memory =
sizeof(internalJSONNode);
733 memory += _name.capacity() *
sizeof(json_char);
734 memory += _string.capacity() *
sizeof(json_char);
736 memory +=
sizeof(jsonChildren);
737 memory += CHILDREN -> capacity() *
sizeof(JSONNode*);
740 memory += _comment.capacity() *
sizeof(json_char);
742 totalbytes += memory;
743 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"bytes used"), memory)));
747 #ifdef JSON_REF_COUNT
748 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"refcount"), refcount)));
750 #ifdef JSON_MUTEX_CALLBACKS
751 dumpage.push_back(JSON_NEW(DumpMutex()));
755 #define DUMPCASE(ty)\
757 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("_type"), JSON_TEXT(#ty))));\
762 DUMPCASE(JSON_STRING)
763 DUMPCASE(JSON_NUMBER)
768 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("_type"), JSON_TEXT("Unknown"))));
771 JSONNode str(JSON_NODE);
772 str.set_name(JSON_TEXT("_name"));
773 str.push_back(JSON_NEW(JSONNode(json_string(JSON_TEXT("value")), _name)));
774 str.push_back(JSON_NEW(JSONNode(JSON_TEXT("length"), _name.length())));
775 str.push_back(JSON_NEW(JSONNode(JSON_TEXT("capactiy"), _name.capacity())));
777 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("_name_encoded"), _name_encoded)));
778 dumpage.push_back(JSON_NEW(str));
779 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("_string_encoded"), _string_encoded)));
781 str.set_name(JSON_TEXT("_string"));
782 str.push_back(JSON_NEW(JSONNode(json_string(JSON_TEXT("value")), _string)));
783 str.push_back(JSON_NEW(JSONNode(JSON_TEXT("length"), _string.length())));
784 str.push_back(JSON_NEW(JSONNode(JSON_TEXT("capactiy"), _string.capacity())));
785 dumpage.push_back(JSON_NEW(str));
787 if ((type() == JSON_BOOL) || (type() == JSON_NUMBER)){
788 JSONNode unio(JSON_NODE);
789 unio.set_name(JSON_TEXT(
"_value"));
790 if (type() == JSON_BOOL){
791 unio.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"_bool"), _value._bool)));
792 }
else if (type() == JSON_NUMBER){
793 unio.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"_number"), _value._number)));
795 dumpage.push_back(JSON_NEW(unio));
798 #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
799 dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"fetched"), fetched)));
804 str.set_name(JSON_TEXT(
"_comment"));
805 str.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"value"), _comment)));
806 str.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"length"), _comment.length())));
807 str.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"capactiy"), _comment.capacity())));
808 dumpage.push_back(JSON_NEW(str));
812 JSONNode arra(JSON_NODE);
813 arra.set_name(JSON_TEXT(
"Children"));
814 arra.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"size"), CHILDREN -> size())));
815 arra.push_back(JSON_NEW(JSONNode(JSON_TEXT(
"capacity"), CHILDREN -> capacity())));
816 JSONNode chil(JSON_ARRAY);
817 chil.set_name(JSON_TEXT(
"array"));
818 json_foreach(CHILDREN, it){
819 chil.push_back(JSON_NEW((*it) -> dump(totalbytes)));
821 arra.push_back(JSON_NEW(chil));
822 dumpage.push_back(JSON_NEW(arra));