JSONNode.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. #ifndef JSONNODE_H
  2. #define JSONNODE_H
  3. #include "JSONDebug.h" //for string type
  4. #include "internalJSONNode.h" //internal structure for json value
  5. #include <stdexcept>
  6. #include <cstdarg> //for the ... parameter
  7. #ifdef JSON_BINARY
  8. #include "JSON_Base64.h"
  9. #endif
  10. #ifdef JSON_LESS_MEMORY
  11. #ifdef __GNUC__
  12. #pragma pack(push, 1)
  13. #elif _MSC_VER
  14. #pragma pack(push, JSONNode_pack, 1)
  15. #endif
  16. #endif
  17. #ifndef JSON_REF_COUNT
  18. #define makeUniqueInternal() (void)0
  19. #endif
  20. #define JSON_CHECK_INTERNAL() JSON_ASSERT(internal != 0, JSON_TEXT("no internal"))
  21. #ifdef JSON_MUTEX_CALLBACKS
  22. #define JSON_MUTEX_COPY_DECL ,void * parentMutex
  23. #define JSON_MUTEX_COPY_DECL2 ,void * parentMutex = 0
  24. #else
  25. #define JSON_MUTEX_COPY_DECL
  26. #define JSON_MUTEX_COPY_DECL2
  27. #endif
  28. #ifdef JSON_LIBRARY
  29. #define JSON_PTR_LIB *
  30. #define JSON_NEW(x) JSONNode::newJSONNode_Shallow(x)
  31. #define DECLARE_FOR_ALL_TYPES(foo)\
  32. foo(json_int_t)json_nothrow;\
  33. foo(json_number) json_nothrow;\
  34. foo(bool) json_nothrow;\
  35. foo(const json_string &) json_nothrow;
  36. #define DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
  37. foo(json_int_t) const json_nothrow;\
  38. foo(json_number) const json_nothrow;\
  39. foo(bool) const json_nothrow;\
  40. foo(const json_string &) const json_nothrow;\
  41. #define DECLARE_FOR_ALL_TYPES_CONST(foo)\
  42. DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
  43. foo(const JSONNode &) const json_nothrow;
  44. #define IMPLEMENT_FOR_ALL_NUMBERS(foo)\
  45. foo(json_int_t)\
  46. foo(json_number)
  47. #else
  48. #define JSON_PTR_LIB
  49. #define JSON_NEW(x) x
  50. #ifdef JSON_ISO_STRICT
  51. #define DECLARE_FOR_LONG_LONG(foo)
  52. #define DECLARE_FOR_LONG_LONG_CONST(foo)
  53. #define IMPLEMENT_FOR_LONG_LONG(foo)
  54. #define DECLARE_FOR_LONG_DOUBLE(foo)
  55. #define DECLARE_FOR_LONG_DOUBLE_CONST(foo)
  56. #define IMPLEMENT_FOR_LONG_DOUBLE(foo)
  57. #else
  58. #define DECLARE_FOR_LONG_LONG(foo) foo(long long) json_nothrow; foo(unsigned long long) json_nothrow;
  59. #define DECLARE_FOR_LONG_LONG_CONST(foo) foo(long long) const json_nothrow; foo(unsigned long long) const json_nothrow;
  60. #define IMPLEMENT_FOR_LONG_LONG(foo) foo(long long) foo(unsigned long long)
  61. #define DECLARE_FOR_LONG_DOUBLE(foo) foo(long double) json_nothrow;
  62. #define DECLARE_FOR_LONG_DOUBLE_CONST(foo) foo(long double) const json_nothrow;
  63. #define IMPLEMENT_FOR_LONG_DOUBLE(foo) foo(long double)
  64. #endif
  65. #define DECLARE_FOR_ALL_TYPES(foo)\
  66. foo(char) json_nothrow; foo(unsigned char) json_nothrow;\
  67. foo(short) json_nothrow; foo(unsigned short) json_nothrow;\
  68. foo(int) json_nothrow; foo(unsigned int) json_nothrow;\
  69. foo(long) json_nothrow; foo(unsigned long) json_nothrow;\
  70. foo(float) json_nothrow; foo(double) json_nothrow;\
  71. foo(bool) json_nothrow;\
  72. foo(const json_string &) json_nothrow;\
  73. foo(const json_char *) json_nothrow;\
  74. DECLARE_FOR_LONG_LONG(foo)\
  75. DECLARE_FOR_LONG_DOUBLE(foo)
  76. #define DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
  77. foo(char) const json_nothrow; foo(unsigned char) const json_nothrow;\
  78. foo(short) const json_nothrow; foo(unsigned short) const json_nothrow;\
  79. foo(int) const json_nothrow; foo(unsigned int) const json_nothrow;\
  80. foo(long) const json_nothrow; foo(unsigned long) const json_nothrow;\
  81. foo(float) const json_nothrow; foo(double) const json_nothrow;\
  82. foo(bool) const json_nothrow;\
  83. foo(const json_string &) const json_nothrow;\
  84. DECLARE_FOR_LONG_LONG_CONST(foo)\
  85. DECLARE_FOR_LONG_DOUBLE_CONST(foo)
  86. #define DECLARE_FOR_ALL_TYPES_CONST(foo)\
  87. DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
  88. foo(const JSONNode &) const json_nothrow;\
  89. foo(const json_char *) const json_nothrow;
  90. #define IMPLEMENT_FOR_ALL_NUMBERS(foo)\
  91. foo(char) foo(unsigned char)\
  92. foo(short) foo(unsigned short)\
  93. foo(int) foo(unsigned int)\
  94. foo(long) foo(unsigned long)\
  95. foo(float) foo(double)\
  96. IMPLEMENT_FOR_LONG_LONG(foo)\
  97. IMPLEMENT_FOR_LONG_DOUBLE(foo)
  98. #endif
  99. #define IMPLEMENT_FOR_ALL_TYPES(foo)\
  100. IMPLEMENT_FOR_ALL_NUMBERS(foo)\
  101. foo(const json_string &)\
  102. foo(bool)
  103. /*
  104. This class is mostly just a wrapper class around internalJSONNode, this class keeps
  105. the reference count and handles copy on write and such. This class is also responsible
  106. for argument checking and throwing exceptions if needed.
  107. */
  108. class JSONNode {
  109. public:
  110. LIBJSON_OBJECT(JSONNode);
  111. explicit JSONNode(char mytype = JSON_NODE) json_nothrow json_hot;
  112. #define DECLARE_CTOR(type) explicit JSONNode(const json_string & name_t, type value_t)
  113. DECLARE_FOR_ALL_TYPES(DECLARE_CTOR)
  114. JSONNode(const JSONNode & orig) json_nothrow json_hot;
  115. ~JSONNode(void) json_nothrow json_hot;
  116. #if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY))
  117. static JSONNode stringType(const json_string & str);
  118. void set_name_(const json_string & newname) json_nothrow json_write_priority;
  119. #endif
  120. json_index_t size(void) const json_nothrow json_read_priority;
  121. bool empty(void) const json_nothrow json_read_priority;
  122. void clear(void) json_nothrow json_cold;
  123. unsigned char type(void) const json_nothrow json_read_priority;
  124. json_string name(void) const json_nothrow json_read_priority;
  125. void set_name(const json_string & newname) json_nothrow json_write_priority;
  126. #ifdef JSON_COMMENTS
  127. void set_comment(const json_string & comment) json_nothrow;
  128. json_string get_comment(void) const json_nothrow;
  129. #endif
  130. #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
  131. void preparse(void) json_nothrow json_read_priority;
  132. #endif
  133. json_string as_string(void) const json_nothrow json_read_priority;
  134. json_int_t as_int(void) const json_nothrow json_read_priority;
  135. json_number as_float(void) const json_nothrow json_read_priority;
  136. bool as_bool(void) const json_nothrow json_read_priority;
  137. #ifdef JSON_CASTABLE
  138. JSONNode as_node(void) const json_nothrow json_read_priority;
  139. JSONNode as_array(void) const json_nothrow json_read_priority;
  140. void cast(char newtype) json_nothrow;
  141. #endif
  142. #ifdef JSON_BINARY
  143. std::string as_binary(void) const json_nothrow json_cold;
  144. void set_binary(const unsigned char * bin, size_t bytes) json_nothrow json_cold;
  145. #endif
  146. JSONNode & at(json_index_t pos) json_throws(std::out_of_range);
  147. const JSONNode & at(json_index_t pos) const json_throws(std::out_of_range);
  148. JSONNode & operator[](json_index_t pos) json_nothrow;
  149. const JSONNode & operator[](json_index_t pos) const json_nothrow;
  150. JSONNode & at(const json_string & name_t) json_throws(std::out_of_range);
  151. const JSONNode & at(const json_string & name_t) const json_throws(std::out_of_range);
  152. #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
  153. JSONNode & at_nocase(const json_string & name_t) json_throws(std::out_of_range);
  154. const JSONNode & at_nocase(const json_string & name_t) const json_throws(std::out_of_range);
  155. #endif
  156. JSONNode & operator[](const json_string & name_t) json_nothrow;
  157. const JSONNode & operator[](const json_string & name_t) const json_nothrow;
  158. #ifdef JSON_LIBRARY
  159. void push_back(JSONNode * node) json_nothrow;
  160. #else
  161. void push_back(const JSONNode & node) json_nothrow;
  162. #endif
  163. void reserve(json_index_t siz) json_nothrow;
  164. JSONNode JSON_PTR_LIB pop_back(json_index_t pos) json_throws(std::out_of_range);
  165. JSONNode JSON_PTR_LIB pop_back(const json_string & name_t) json_throws(std::out_of_range);
  166. #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
  167. JSONNode JSON_PTR_LIB pop_back_nocase(const json_string & name_t) json_throws(std::out_of_range);
  168. #endif
  169. DECLARE_FOR_ALL_TYPES(JSONNode & operator =)
  170. JSONNode & operator = (const JSONNode &) json_nothrow;
  171. DECLARE_FOR_ALL_TYPES_CONST(bool operator ==)
  172. DECLARE_FOR_ALL_TYPES_CONST(bool operator !=)
  173. void nullify(void) json_nothrow;
  174. void swap(JSONNode & other) json_nothrow;
  175. void merge(JSONNode & other) json_nothrow json_cold;
  176. void merge(unsigned int num, ...) json_nothrow json_cold;
  177. JSONNode duplicate(void) const json_nothrow;
  178. //iterator
  179. #ifdef JSON_ITERATORS
  180. #ifndef JSON_LIBRARY
  181. #define json_iterator_ptr(iter) iter.it
  182. #define ptr_to_json_iterator(iter) json_iterator(iter)
  183. struct iterator;
  184. struct const_iterator {
  185. inline const_iterator& operator ++(void) json_nothrow { ++it; return *this; }
  186. inline const_iterator& operator --(void) json_nothrow { --it; return *this; }
  187. inline const_iterator& operator +=(long i) json_nothrow { it += i; return *this; }
  188. inline const_iterator& operator -=(long i) json_nothrow { it -= i; return *this; }
  189. inline const_iterator operator ++(int) json_nothrow {
  190. const_iterator result(*this);
  191. ++it;
  192. return result;
  193. }
  194. inline const_iterator operator --(int) json_nothrow {
  195. const_iterator result(*this);
  196. --it;
  197. return result;
  198. }
  199. inline const_iterator operator +(long i) const json_nothrow {
  200. const_iterator result(*this);
  201. result.it += i;
  202. return result;
  203. }
  204. inline const_iterator operator -(long i) const json_nothrow {
  205. const_iterator result(*this);
  206. result.it -= i;
  207. return result;
  208. }
  209. inline const JSONNode& operator [](size_t pos) const json_nothrow { return const_cast<const JSONNode&>(*it[pos]); };
  210. inline const JSONNode& operator *(void) const json_nothrow { return const_cast<const JSONNode&>(*(*it)); }
  211. inline const JSONNode* operator ->(void) const json_nothrow { return const_cast<const JSONNode*>(*it); }
  212. inline bool operator == (const const_iterator & other) const json_nothrow { return it == other.it; }
  213. inline bool operator != (const const_iterator & other) const json_nothrow { return it != other.it; }
  214. inline bool operator > (const const_iterator & other) const json_nothrow { return it > other.it; }
  215. inline bool operator >= (const const_iterator & other) const json_nothrow { return it >= other.it; }
  216. inline bool operator < (const const_iterator & other) const json_nothrow { return it < other.it; }
  217. inline bool operator <= (const const_iterator & other) const json_nothrow { return it <= other.it; }
  218. inline bool operator == (const iterator & other) const json_nothrow { return it == other.it; }
  219. inline bool operator != (const iterator & other) const json_nothrow { return it != other.it; }
  220. inline bool operator > (const iterator & other) const json_nothrow { return it > other.it; }
  221. inline bool operator >= (const iterator & other) const json_nothrow { return it >= other.it; }
  222. inline bool operator < (const iterator & other) const json_nothrow { return it < other.it; }
  223. inline bool operator <= (const iterator & other) const json_nothrow { return it <= other.it; }
  224. inline const_iterator & operator =(const const_iterator & orig) json_nothrow { it = orig.it; return *this; }
  225. const_iterator (const const_iterator & orig) json_nothrow : it(orig.it) {}
  226. private:
  227. JSONNode ** it;
  228. const_iterator(JSONNode ** starter) : it(starter) {}
  229. friend class JSONNode;
  230. friend struct iterator;
  231. };
  232. const_iterator begin(void) const json_nothrow;
  233. const_iterator end(void) const json_nothrow;
  234. struct iterator {
  235. inline iterator& operator ++(void) json_nothrow { ++it; return *this; }
  236. inline iterator& operator --(void) json_nothrow { --it; return *this; }
  237. inline iterator& operator +=(long i) json_nothrow { it += i; return *this; }
  238. inline iterator& operator -=(long i) json_nothrow { it -= i; return *this; }
  239. inline iterator operator ++(int) json_nothrow {
  240. iterator result(*this);
  241. ++it;
  242. return result;
  243. }
  244. inline iterator operator --(int) json_nothrow {
  245. iterator result(*this);
  246. --it;
  247. return result;
  248. }
  249. inline iterator operator +(long i) const json_nothrow {
  250. iterator result(*this);
  251. result.it += i;
  252. return result;
  253. }
  254. inline iterator operator -(long i) const json_nothrow {
  255. iterator result(*this);
  256. result.it -= i;
  257. return result;
  258. }
  259. inline JSONNode& operator [](size_t pos) const json_nothrow { return *it[pos]; };
  260. inline JSONNode& operator *(void) const json_nothrow { return *(*it); }
  261. inline JSONNode* operator ->(void) const json_nothrow { return *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; }
  268. inline iterator & operator = (const iterator & orig) json_nothrow { it = orig.it; return *this; }
  269. inline bool operator == (const const_iterator & other) const json_nothrow { return it == other.it; }
  270. inline bool operator != (const const_iterator & other) const json_nothrow { return it != other.it; }
  271. inline bool operator > (const const_iterator & other) const json_nothrow { return it > other.it; }
  272. inline bool operator >= (const const_iterator & other) const json_nothrow { return it >= other.it; }
  273. inline bool operator < (const const_iterator & other) const json_nothrow { return it < other.it; }
  274. inline bool operator <= (const const_iterator & other) const json_nothrow { return it <= other.it; }
  275. inline iterator & operator = (const const_iterator & orig) json_nothrow { it = orig.it; return *this; }
  276. iterator (const iterator & orig) json_nothrow : it(orig.it) {}
  277. inline operator const_iterator() const json_nothrow { return const_iterator(it); }
  278. private:
  279. JSONNode ** it;
  280. iterator(JSONNode ** starter) json_nothrow : it(starter) {}
  281. friend class JSONNode;
  282. friend struct const_iterator;
  283. };
  284. typedef iterator json_iterator;
  285. struct reverse_iterator;
  286. struct reverse_const_iterator {
  287. inline reverse_const_iterator& operator ++(void) json_nothrow{ --it; return *this; }
  288. inline reverse_const_iterator& operator --(void) json_nothrow{ ++it; return *this; }
  289. inline reverse_const_iterator& operator +=(long i) json_nothrow{ it -= i; return *this; }
  290. inline reverse_const_iterator& operator -=(long i) json_nothrow{ it += i; return *this; }
  291. inline reverse_const_iterator operator ++(int) json_nothrow{
  292. reverse_const_iterator result(*this);
  293. --it;
  294. return result;
  295. }
  296. inline reverse_const_iterator operator --(int) json_nothrow{
  297. reverse_const_iterator result(*this);
  298. ++it;
  299. return result;
  300. }
  301. inline reverse_const_iterator operator +(long i) const json_nothrow {
  302. reverse_const_iterator result(*this);
  303. result.it -= i;
  304. return result;
  305. }
  306. inline reverse_const_iterator operator -(long i) const json_nothrow {
  307. reverse_const_iterator result(*this);
  308. result.it += i;
  309. return result;
  310. }
  311. inline const JSONNode& operator [](size_t pos) const json_nothrow { return const_cast<const JSONNode&>(*it[pos]); };
  312. inline const JSONNode& operator *(void) const json_nothrow { return const_cast<const JSONNode&>(*(*it)); }
  313. inline const JSONNode* operator ->(void) const json_nothrow { return const_cast<const JSONNode*>(*it); }
  314. inline bool operator == (const reverse_const_iterator & other) const json_nothrow { return it == other.it; }
  315. inline bool operator != (const reverse_const_iterator & other) const json_nothrow { return it != other.it; }
  316. inline bool operator < (const reverse_const_iterator & other) const json_nothrow { return it > other.it; }
  317. inline bool operator <= (const reverse_const_iterator & other) const json_nothrow { return it >= other.it; }
  318. inline bool operator > (const reverse_const_iterator & other) const json_nothrow { return it < other.it; }
  319. inline bool operator >= (const reverse_const_iterator & other) const json_nothrow { return it <= other.it; }
  320. inline bool operator == (const reverse_iterator & other) const json_nothrow { return it == other.it; }
  321. inline bool operator != (const reverse_iterator & other) const json_nothrow { return it != other.it; }
  322. inline bool operator < (const reverse_iterator & other) const json_nothrow { return it > other.it; }
  323. inline bool operator <= (const reverse_iterator & other) const json_nothrow { return it >= other.it; }
  324. inline bool operator > (const reverse_iterator & other) const json_nothrow { return it < other.it; }
  325. inline bool operator >= (const reverse_iterator & other) const json_nothrow { return it <= other.it; }
  326. inline reverse_const_iterator & operator = (const reverse_const_iterator & orig) json_nothrow { it = orig.it; return *this; }
  327. reverse_const_iterator (const reverse_const_iterator & orig) json_nothrow : it(orig.it) {}
  328. private:
  329. JSONNode ** it;
  330. reverse_const_iterator(JSONNode ** starter) json_nothrow : it(starter) {}
  331. friend class JSONNode;
  332. friend struct reverse_iterator;
  333. };
  334. reverse_const_iterator rbegin(void) const json_nothrow;
  335. reverse_const_iterator rend(void) const json_nothrow;
  336. struct reverse_iterator {
  337. inline reverse_iterator& operator ++(void) json_nothrow { --it; return *this; }
  338. inline reverse_iterator& operator --(void) json_nothrow { ++it; return *this; }
  339. inline reverse_iterator& operator +=(long i) json_nothrow { it -= i; return *this; }
  340. inline reverse_iterator& operator -=(long i) json_nothrow { it += i; return *this; }
  341. inline reverse_iterator operator ++(int) json_nothrow {
  342. reverse_iterator result(*this);
  343. --it;
  344. return result;
  345. }
  346. inline reverse_iterator operator --(int) json_nothrow {
  347. reverse_iterator result(*this);
  348. ++it;
  349. return result;
  350. }
  351. inline reverse_iterator operator +(long i) const json_nothrow {
  352. reverse_iterator result(*this);
  353. result.it -= i;
  354. return result;
  355. }
  356. inline reverse_iterator operator -(long i) const json_nothrow {
  357. reverse_iterator result(*this);
  358. result.it += i;
  359. return result;
  360. }
  361. inline JSONNode& operator [](size_t pos) const json_nothrow { return *it[pos]; };
  362. inline JSONNode& operator *(void) const json_nothrow { return *(*it); }
  363. inline JSONNode* operator ->(void) const json_nothrow { return *it; }
  364. inline bool operator == (const reverse_iterator & other) const json_nothrow { return it == other.it; }
  365. inline bool operator != (const reverse_iterator & other) const json_nothrow { return it != other.it; }
  366. inline bool operator < (const reverse_iterator & other) const json_nothrow { return it > other.it; }
  367. inline bool operator <= (const reverse_iterator & other) const json_nothrow { return it >= other.it; }
  368. inline bool operator > (const reverse_iterator & other) const json_nothrow { return it < other.it; }
  369. inline bool operator >= (const reverse_iterator & other) const json_nothrow { return it <= other.it; }
  370. inline bool operator == (const reverse_const_iterator & other) const json_nothrow { return it == other.it; }
  371. inline bool operator != (const reverse_const_iterator & other) const json_nothrow { return it != other.it; }
  372. inline bool operator < (const reverse_const_iterator & other) const json_nothrow { return it > other.it; }
  373. inline bool operator <= (const reverse_const_iterator & other) const json_nothrow { return it >= other.it; }
  374. inline bool operator > (const reverse_const_iterator & other) const json_nothrow { return it < other.it; }
  375. inline bool operator >= (const reverse_const_iterator & other) const json_nothrow { return it <= other.it; }
  376. inline reverse_iterator & operator = (const reverse_iterator & orig) json_nothrow { it = orig.it; return *this; }
  377. reverse_iterator (const reverse_iterator & orig) json_nothrow : it(orig.it) {}
  378. inline operator reverse_const_iterator() const json_nothrow { return reverse_const_iterator(it); }
  379. private:
  380. JSONNode ** it;
  381. reverse_iterator(JSONNode ** starter) json_nothrow : it(starter) {}
  382. friend class JSONNode;
  383. friend struct reverse_const_iterator;
  384. };
  385. reverse_iterator rbegin(void) json_nothrow;
  386. reverse_iterator rend(void) json_nothrow;
  387. const_iterator find(const json_string & name_t) const json_nothrow;
  388. #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
  389. const_iterator find_nocase(const json_string & name_t) const json_nothrow;
  390. #endif
  391. reverse_iterator erase(reverse_iterator pos) json_nothrow;
  392. reverse_iterator erase(reverse_iterator start, const reverse_iterator & end) json_nothrow;
  393. iterator insert(iterator pos, const JSONNode & x) json_nothrow;
  394. reverse_iterator insert(reverse_iterator pos, const JSONNode & x) json_nothrow;
  395. iterator insert(iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow;
  396. reverse_iterator insert(reverse_iterator pos, const iterator & _start, const iterator & _end) json_nothrow;
  397. reverse_iterator insert(reverse_iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow;
  398. json_iterator insert(json_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow;
  399. reverse_iterator insert(reverse_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow;
  400. json_iterator insert(json_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow;
  401. reverse_iterator insert(reverse_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow;
  402. #else
  403. typedef JSONNode** json_iterator;
  404. #define json_iterator_ptr(iter) iter
  405. #define ptr_to_json_iterator(iter) iter
  406. json_iterator insert(json_iterator pos, JSONNode * x) json_nothrow;
  407. #endif
  408. json_iterator begin(void) json_nothrow;
  409. json_iterator end(void) json_nothrow;
  410. json_iterator find(const json_string & name_t) json_nothrow;
  411. #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
  412. json_iterator find_nocase(const json_string & name_t) json_nothrow;
  413. #endif
  414. json_iterator erase(json_iterator pos) json_nothrow;
  415. json_iterator erase(json_iterator start, const json_iterator & end) json_nothrow;
  416. json_iterator insert(json_iterator pos, const json_iterator & _start, const json_iterator & _end) json_nothrow;
  417. #endif
  418. #ifdef JSON_MUTEX_CALLBACKS
  419. static void register_mutex_callbacks(json_mutex_callback_t lock, json_mutex_callback_t unlock, void * manager_lock) json_nothrow json_cold;
  420. #ifdef JSON_MUTEX_MANAGE
  421. static void register_mutex_destructor(json_mutex_callback_t destroy) json_nothrow json_cold;
  422. #endif
  423. static void set_global_mutex(void * mutex) json_nothrow json_cold;
  424. void set_mutex(void * mutex) json_nothrow json_cold;
  425. void lock(int thread) json_nothrow json_cold;
  426. void unlock(int thread) json_nothrow json_cold;
  427. struct auto_lock {
  428. public:
  429. auto_lock(JSONNode & node, int thread) json_nothrow: mynode(&node), mythread(thread){
  430. mynode -> lock(mythread);
  431. }
  432. auto_lock(JSONNode * node, int thread) json_nothrow: mynode(node), mythread(thread){
  433. mynode -> lock(mythread);
  434. }
  435. ~auto_lock(void) json_nothrow{
  436. mynode -> unlock(mythread);
  437. }
  438. private:
  439. auto_lock & operator = (const auto_lock &);
  440. auto_lock(const auto_lock &);
  441. JSONNode * mynode;
  442. int mythread;
  443. };
  444. static void * getThisLock(JSONNode * pthis) json_nothrow json_cold;
  445. #endif
  446. #ifdef JSON_WRITE_PRIORITY
  447. #ifdef JSON_LESS_MEMORY
  448. #define DEFAULT_APPROX_SIZE 8
  449. #define DEFAULT_APPROX_SIZE_FORMATTED 16
  450. #else
  451. #define DEFAULT_APPROX_SIZE 1024
  452. #define DEFAULT_APPROX_SIZE_FORMATTED 2048
  453. #endif
  454. json_string write(size_t approxsize = DEFAULT_APPROX_SIZE) const json_nothrow json_write_priority;
  455. json_string write_formatted(size_t approxsize = DEFAULT_APPROX_SIZE_FORMATTED) const json_nothrow json_write_priority;
  456. #endif
  457. #ifdef JSON_DEBUG
  458. #ifndef JSON_LIBRARY
  459. JSONNode dump(void) const json_nothrow;
  460. #endif
  461. #endif
  462. static void deleteJSONNode(JSONNode * ptr) json_nothrow json_hot;
  463. static JSONNode * newJSONNode_Shallow(const JSONNode & orig) json_hot;
  464. #define DECLARE_CAST_OP(type) operator type()
  465. //DECLARE_FOR_ALL_CAST_TYPES_CONST(DECLARE_CAST_OP)
  466. JSON_PRIVATE
  467. static JSONNode * newJSONNode(const JSONNode & orig JSON_MUTEX_COPY_DECL2) json_hot;
  468. static JSONNode * newJSONNode(internalJSONNode * internal_t) json_hot;
  469. #ifdef JSON_READ_PRIORITY
  470. //used by JSONWorker
  471. JSONNode(const json_string & unparsed) json_nothrow : internal(internalJSONNode::newInternal(unparsed)){ //root, specialized because it can only be array or node
  472. LIBJSON_CTOR;
  473. }
  474. #endif
  475. JSONNode(internalJSONNode * internal_t) json_nothrow : internal(internal_t){ //do not increment anything, this is only used in one case and it's already taken care of
  476. LIBJSON_CTOR;
  477. }
  478. JSONNode(bool, JSONNode & orig) json_nothrow json_hot;
  479. void decRef(void) json_nothrow json_hot; //decrements internal's counter, deletes it if needed
  480. #ifdef JSON_REF_COUNT
  481. void makeUniqueInternal(void) json_nothrow; //makes internal it's own
  482. void merge(JSONNode * other) json_nothrow json_cold;
  483. #endif
  484. #ifdef JSON_DEBUG
  485. #ifndef JSON_LIBRARY
  486. JSONNode dump(size_t & totalmemory) json_nothrow;
  487. #endif
  488. #endif
  489. #ifdef JSON_ITERATORS
  490. #ifndef JSON_LIBRARY
  491. json_iterator insertFRR(json_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
  492. reverse_iterator insertRRR(reverse_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
  493. reverse_iterator insertRFF(reverse_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
  494. #endif
  495. json_iterator insertFFF(json_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
  496. #endif
  497. inline void clear_name(void) json_nothrow {
  498. JSON_CHECK_INTERNAL();
  499. makeUniqueInternal();
  500. internal -> clearname();
  501. }
  502. mutable internalJSONNode * internal;
  503. friend class JSONWorker;
  504. friend class internalJSONNode;
  505. };
  506. /*
  507. Implementations are here to keep the class declaration cleaner. They can't be placed in a different
  508. file because they are inlined.
  509. */
  510. #define CAST_OP(type)\
  511. inline JSONNode::operator type() const json_nothrow {\
  512. return static_cast<type>(*internal);\
  513. }
  514. //IMPLEMENT_FOR_ALL_TYPES(CAST_OP)
  515. inline JSONNode::JSONNode(char mytype) json_nothrow : internal(internalJSONNode::newInternal(mytype)){
  516. JSON_ASSERT((mytype == JSON_NULL) ||
  517. (mytype == JSON_STRING) ||
  518. (mytype == JSON_NUMBER) ||
  519. (mytype == JSON_BOOL) ||
  520. (mytype == JSON_ARRAY) ||
  521. (mytype == JSON_NODE), JSON_TEXT("Not a proper JSON type"));
  522. LIBJSON_CTOR;
  523. }
  524. inline JSONNode::JSONNode(const JSONNode & orig) json_nothrow : internal(orig.internal -> incRef()){
  525. LIBJSON_COPY_CTOR;
  526. }
  527. //this allows a temp node to simply transfer its contents, even with ref counting off
  528. inline JSONNode::JSONNode(bool, JSONNode & orig) json_nothrow : internal(orig.internal){
  529. orig.internal = 0;
  530. LIBJSON_CTOR;
  531. }
  532. inline JSONNode::~JSONNode(void) json_nothrow{
  533. if (internal != 0) decRef();
  534. LIBJSON_DTOR;
  535. }
  536. inline json_index_t JSONNode::size(void) const json_nothrow {
  537. JSON_CHECK_INTERNAL();
  538. return internal -> size();
  539. }
  540. inline bool JSONNode::empty(void) const json_nothrow {
  541. JSON_CHECK_INTERNAL();
  542. return internal -> empty();
  543. }
  544. inline void JSONNode::clear(void) json_nothrow {
  545. JSON_CHECK_INTERNAL();
  546. if (!empty()){
  547. makeUniqueInternal();
  548. internal -> CHILDREN -> clear();
  549. }
  550. }
  551. inline unsigned char JSONNode::type(void) const json_nothrow {
  552. JSON_CHECK_INTERNAL();
  553. return internal -> type();
  554. }
  555. inline json_string JSONNode::name(void) const json_nothrow {
  556. JSON_CHECK_INTERNAL();
  557. return internal -> name();
  558. }
  559. inline void JSONNode::set_name(const json_string & newname) json_nothrow{
  560. JSON_CHECK_INTERNAL();
  561. makeUniqueInternal();
  562. internal -> setname(newname);
  563. }
  564. #ifdef JSON_COMMENTS
  565. inline void JSONNode::set_comment(const json_string & newname) json_nothrow{
  566. JSON_CHECK_INTERNAL();
  567. makeUniqueInternal();
  568. internal -> setcomment(newname);
  569. }
  570. inline json_string JSONNode::get_comment(void) const json_nothrow {
  571. JSON_CHECK_INTERNAL();
  572. return internal -> getcomment();
  573. }
  574. #endif
  575. //#ifdef JSON_DEPRECATED_FUNCTIONS
  576. inline json_string JSONNode::as_string(void) const json_nothrow {
  577. JSON_CHECK_INTERNAL();
  578. return static_cast<json_string>(*internal);
  579. }
  580. inline json_int_t JSONNode::as_int(void) const json_nothrow {
  581. JSON_CHECK_INTERNAL();
  582. return static_cast<json_int_t>(*internal);
  583. }
  584. inline json_number JSONNode::as_float(void) const json_nothrow {
  585. JSON_CHECK_INTERNAL();
  586. return static_cast<json_number>(*internal);
  587. }
  588. inline bool JSONNode::as_bool(void) const json_nothrow {
  589. JSON_CHECK_INTERNAL();
  590. return static_cast<bool>(*internal);
  591. }
  592. //#endif
  593. #ifdef JSON_BINARY
  594. inline void JSONNode::set_binary(const unsigned char * bin, size_t bytes) json_nothrow{
  595. JSON_CHECK_INTERNAL();
  596. *this = JSONBase64::json_encode64(bin, bytes);
  597. }
  598. inline std::string JSONNode::as_binary(void) const json_nothrow {
  599. JSON_ASSERT_SAFE(type() == JSON_STRING, JSON_TEXT("using as_binary for a non-string type"), return json_global(EMPTY_STD_STRING););
  600. JSON_CHECK_INTERNAL();
  601. return JSONBase64::json_decode64(as_string());
  602. }
  603. #endif
  604. inline JSONNode & JSONNode::operator[](const json_string & name_t) json_nothrow {
  605. JSON_CHECK_INTERNAL();
  606. makeUniqueInternal();
  607. return *(*(internal -> at(name_t)));
  608. }
  609. inline const JSONNode & JSONNode::operator[](const json_string & name_t) const json_nothrow {
  610. JSON_CHECK_INTERNAL();
  611. return *(*(internal -> at(name_t)));
  612. }
  613. #ifdef JSON_LIBRARY
  614. inline void JSONNode::push_back(JSONNode * child) json_nothrow{
  615. #else
  616. inline void JSONNode::push_back(const JSONNode & child) json_nothrow{
  617. #endif
  618. JSON_CHECK_INTERNAL();
  619. makeUniqueInternal();
  620. internal -> push_back(child);
  621. }
  622. inline void JSONNode::reserve(json_index_t siz) json_nothrow{
  623. makeUniqueInternal();
  624. internal -> reserve(siz);
  625. }
  626. inline JSONNode & JSONNode::operator = (const JSONNode & orig) json_nothrow {
  627. JSON_CHECK_INTERNAL();
  628. #ifdef JSON_REF_COUNT
  629. if (internal == orig.internal) return *this; //don't want it accidentally deleting itself
  630. #endif
  631. decRef(); //dereference my current one
  632. internal = orig.internal -> incRef(); //increase reference of original
  633. return *this;
  634. }
  635. #ifndef JSON_LIBRARY
  636. inline JSONNode & JSONNode::operator = (const json_char * val) json_nothrow {
  637. JSON_CHECK_INTERNAL();
  638. *this = json_string(val);
  639. return *this;
  640. }
  641. #endif
  642. #define NODE_SET_TYPED(type)\
  643. inline JSONNode & JSONNode::operator = (type val) json_nothrow {\
  644. LIBJSON_ASSIGNMENT;\
  645. JSON_CHECK_INTERNAL();\
  646. makeUniqueInternal();\
  647. internal -> Set(val);\
  648. return *this;\
  649. }
  650. IMPLEMENT_FOR_ALL_TYPES(NODE_SET_TYPED)
  651. /*
  652. This section is the equality operators
  653. */
  654. #define NODE_CHECK_EQUALITY(type)\
  655. inline bool JSONNode::operator == (type val) const json_nothrow {\
  656. JSON_CHECK_INTERNAL();\
  657. return internal -> IsEqualToNum<type>(val);\
  658. }
  659. IMPLEMENT_FOR_ALL_NUMBERS(NODE_CHECK_EQUALITY)
  660. inline bool JSONNode::operator == (const json_string & val) const json_nothrow {
  661. JSON_CHECK_INTERNAL();
  662. return internal -> IsEqualTo(val);
  663. }
  664. #ifndef JSON_LIBRARY
  665. inline bool JSONNode::operator == (const json_char * val) const json_nothrow {
  666. JSON_CHECK_INTERNAL();
  667. return *this == json_string(val);
  668. }
  669. #endif
  670. inline bool JSONNode::operator == (bool val) const json_nothrow {
  671. JSON_CHECK_INTERNAL();
  672. return internal -> IsEqualTo(val);
  673. }
  674. inline bool JSONNode::operator == (const JSONNode & val) const json_nothrow {
  675. JSON_CHECK_INTERNAL();
  676. return internal -> IsEqualTo(val.internal);
  677. }
  678. /*
  679. This section is the inequality operators
  680. */
  681. #define NODE_CHECK_INEQUALITY(type)\
  682. inline bool JSONNode::operator != (type val) const json_nothrow {\
  683. JSON_CHECK_INTERNAL();\
  684. return !(*this == val);\
  685. }
  686. IMPLEMENT_FOR_ALL_TYPES(NODE_CHECK_INEQUALITY)
  687. NODE_CHECK_INEQUALITY(const JSONNode &)
  688. #ifndef JSON_LIBRARY
  689. NODE_CHECK_INEQUALITY(const json_char * )
  690. #endif
  691. inline void JSONNode::nullify(void) json_nothrow {
  692. JSON_CHECK_INTERNAL();
  693. makeUniqueInternal();
  694. internal -> Nullify();
  695. }
  696. inline void JSONNode::swap(JSONNode & other) json_nothrow {
  697. JSON_CHECK_INTERNAL();
  698. internalJSONNode * temp = other.internal;
  699. other.internal = internal;
  700. internal = temp;
  701. JSON_CHECK_INTERNAL();
  702. }
  703. inline void JSONNode::decRef(void) json_nothrow { //decrements internal's counter, deletes it if needed
  704. JSON_CHECK_INTERNAL();
  705. #ifdef JSON_REF_COUNT
  706. internal -> decRef();
  707. if (internal -> hasNoReferences()){
  708. internalJSONNode::deleteInternal(internal);
  709. }
  710. #else
  711. internalJSONNode::deleteInternal(internal);
  712. #endif
  713. }
  714. #ifdef JSON_REF_COUNT
  715. inline void JSONNode::makeUniqueInternal() json_nothrow { //makes internal it's own
  716. JSON_CHECK_INTERNAL();
  717. internal = internal -> makeUnique(); //might return itself or a new one that's exactly the same
  718. }
  719. #endif
  720. #ifdef JSON_ITERATORS
  721. inline JSONNode::json_iterator JSONNode::begin(void) json_nothrow {
  722. JSON_CHECK_INTERNAL();
  723. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("begin"));
  724. makeUniqueInternal();
  725. return json_iterator(internal -> begin());
  726. }
  727. inline JSONNode::json_iterator JSONNode::end(void) json_nothrow {
  728. JSON_CHECK_INTERNAL();
  729. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("end"));
  730. makeUniqueInternal();
  731. return json_iterator(internal -> end());
  732. }
  733. #ifndef JSON_LIBRARY
  734. inline JSONNode::const_iterator JSONNode::begin(void) const json_nothrow {
  735. JSON_CHECK_INTERNAL();
  736. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("begin"));
  737. return JSONNode::const_iterator(internal -> begin());
  738. }
  739. inline JSONNode::const_iterator JSONNode::end(void) const json_nothrow {
  740. JSON_CHECK_INTERNAL();
  741. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("end"));
  742. return JSONNode::const_iterator(internal -> end());
  743. }
  744. inline JSONNode::reverse_iterator JSONNode::rbegin(void) json_nothrow {
  745. JSON_CHECK_INTERNAL();
  746. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rbegin"));
  747. makeUniqueInternal();
  748. return JSONNode::reverse_iterator(internal -> end() - 1);
  749. }
  750. inline JSONNode::reverse_iterator JSONNode::rend(void) json_nothrow {
  751. JSON_CHECK_INTERNAL();
  752. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rend"));
  753. makeUniqueInternal();
  754. return JSONNode::reverse_iterator(internal -> begin() - 1);
  755. }
  756. inline JSONNode::reverse_const_iterator JSONNode::rbegin(void) const json_nothrow {
  757. JSON_CHECK_INTERNAL();
  758. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rbegin"));
  759. return JSONNode::reverse_const_iterator(internal -> end() - 1);
  760. }
  761. inline JSONNode::reverse_const_iterator JSONNode::rend(void) const json_nothrow {
  762. JSON_CHECK_INTERNAL();
  763. JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rend"));
  764. return JSONNode::reverse_const_iterator(internal -> begin() - 1);
  765. }
  766. inline JSONNode::iterator JSONNode::insert(json_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow {
  767. return insertFFF(pos, _start.it, _end.it);
  768. }
  769. inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow {
  770. return insertRFF(pos, _start.it, _end.it);
  771. }
  772. inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const iterator & _start, const iterator & _end) json_nothrow {
  773. return insertRFF(pos, _start.it, _end.it);
  774. }
  775. inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow {
  776. return insertRRR(pos, _start.it, _end.it);
  777. }
  778. inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow {
  779. return insertRRR(pos, _start.it, _end.it);
  780. }
  781. inline JSONNode::iterator JSONNode::insert(json_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow {
  782. return insertFRR(pos, _start.it, _end.it);
  783. }
  784. inline JSONNode::iterator JSONNode::insert(iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow {
  785. return insertFRR(pos, _start.it, _end.it);
  786. }
  787. #endif
  788. inline JSONNode::json_iterator JSONNode::insert(json_iterator pos, const json_iterator & _start, const json_iterator & _end) json_nothrow {
  789. return insertFFF(pos, json_iterator_ptr(_start), json_iterator_ptr(_end));
  790. }
  791. #endif
  792. #ifdef JSON_WRITE_PRIORITY
  793. inline json_string JSONNode::write(size_t approxsize) const json_nothrow {
  794. JSON_CHECK_INTERNAL();
  795. JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT("Writing a non-writable node"), return json_global(EMPTY_JSON_STRING););
  796. json_string result;
  797. result.reserve(approxsize);
  798. internal -> Write(0xFFFFFFFF, true, result);
  799. return result;
  800. }
  801. inline json_string JSONNode::write_formatted(size_t approxsize) const json_nothrow {
  802. JSON_CHECK_INTERNAL();
  803. JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT("Writing a non-writable node"), return json_global(EMPTY_JSON_STRING););
  804. json_string result;
  805. result.reserve(approxsize);
  806. internal -> Write(0, true, result);
  807. return result;
  808. }
  809. #endif
  810. #if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
  811. inline void JSONNode::preparse(void) json_nothrow {
  812. JSON_CHECK_INTERNAL();
  813. internal -> preparse();
  814. }
  815. #endif
  816. #ifdef JSON_DEBUG
  817. #ifndef JSON_LIBRARY
  818. inline JSONNode JSONNode::dump(void) const json_nothrow {
  819. JSON_CHECK_INTERNAL();
  820. JSONNode dumpage(JSON_NODE);
  821. dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("this"), (long)this)));
  822. size_t total = 0;
  823. JSONNode node(internal -> Dump(total));
  824. dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("total bytes used"), total)));
  825. dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("bytes used"), sizeof(JSONNode))));
  826. dumpage.push_back(JSON_NEW(node));
  827. return dumpage;
  828. }
  829. inline JSONNode JSONNode::dump(size_t & totalmemory) json_nothrow {
  830. JSON_CHECK_INTERNAL();
  831. JSONNode dumpage(JSON_NODE);
  832. dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("this"), (long)this)));
  833. dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("bytes used"), sizeof(JSONNode))));
  834. dumpage.push_back(JSON_NEW(internal -> Dump(totalmemory)));
  835. return dumpage;
  836. }
  837. #endif
  838. #endif
  839. #ifdef JSON_LESS_MEMORY
  840. #ifdef __GNUC__
  841. #pragma pack(pop)
  842. #elif _MSC_VER
  843. #pragma pack(pop, JSONNode_pack)
  844. #endif
  845. #endif
  846. #endif