OpenCPN Partial API docs
Loading...
Searching...
No Matches
jsonval.cpp
Go to the documentation of this file.
1
2// Name: jsonval.cpp
3// Purpose: the wxJSON class that holds a JSON value
4// Author: Luciano Cattani
5// Created: 2007/10/01
6// RCS-ID: $Id: jsonval.cpp,v 1.12 2008/03/06 10:25:18 luccat Exp $
7// Copyright: (c) 2007 Luciano Cattani
8// Licence: wxWidgets licence
10
14#ifdef NDEBUG
15// make wxLogTrace a noop if no debug set, it's really slow
16// must be defined before including debug.h
17#define wxDEBUG_LEVEL 0
18#endif
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24#pragma hdrstop
25#endif
26
27#include <wx/log.h>
28#include <wx/debug.h>
29#include <wx/arrimpl.cpp>
30
31#include <wx/jsonval.h>
32
33WX_DEFINE_OBJARRAY(wxJSONInternalArray);
34
35#if wxCHECK_VERSION(3, 0, 0)
36#define compatibleLongLongFmtSpec _T(wxLongLongFmtSpec)
37#else
38#define compatibleLongLongFmtSpec wxLongLongFmtSpec
39#endif
40
41// the trace mask used in wxLogTrace() function
42// static const wxChar* traceMask = "jsonval";
43#if wxDEBUG_LEVEL > 0
44static const wxChar* traceMask = "jsonval";
45static const wxChar* compareTraceMask = "sameas";
46static const wxChar* cowTraceMask = _T("traceCOW" );
47#endif
48
49/*******************************************************************
50
51 class wxJSONRefData
52
53*******************************************************************/
54
66#if defined(WXJSON_USE_VALUE_COUNTER)
67// The progressive counter (used for debugging only)
68int wxJSONRefData::sm_progr = 1;
69#endif
70
73 m_lineNo = -1;
74 m_refCount = 1;
75 m_memBuff = nullptr;
76
77#if defined(WXJSON_USE_VALUE_COUNTER)
78 m_progr = sm_progr;
79 ++sm_progr;
80 wxLogTrace(traceMask, "(%s) JSON refData ctor progr=%d", __PRETTY_FUNCTION__,
81 m_progr);
82#endif
83}
84
85// Dtor
86wxJSONRefData::~wxJSONRefData() {
87 if (m_memBuff) {
88 delete m_memBuff;
89 }
90}
91
92// Return the number of objects that reference this data.
93int wxJSONRefData::GetRefCount() const { return m_refCount; }
94
95/*******************************************************************
96
97 class wxJSONValue
98
99*******************************************************************/
100
160#if defined(WXJSON_USE_VALUE_COUNTER)
161// The progressive counter (used for debugging only)
162int wxJSONValue::sm_progr = 1;
163#endif
164
166
184 m_refData = nullptr;
185 Init(wxJSONTYPE_NULL);
186}
187
189
197 wxJSONRefData* data = GetRefData();
198 if (data != 0) {
199 UnRef();
200 }
201
202 // we allocate a new instance of the referenced data
203 data = new wxJSONRefData();
204 wxJSON_ASSERT(data);
205
206 // in release builds we do not have ASSERT so we check 'data' before
207 // using it
208 if (data) {
209 data->m_type = type;
210 data->m_commentPos = wxJSONVALUE_COMMENT_BEFORE;
211 }
212 SetRefData(data);
213
214#if defined(WXJSON_USE_VALUE_COUNTER)
215 m_progr = sm_progr;
216 ++sm_progr;
217 wxLogTrace(cowTraceMask, "(%s) Init a new object progr=%d",
218 __PRETTY_FUNCTION__, m_progr);
219#endif
220 return data;
221}
222
224wxJSONValue::wxJSONValue(wxJSONType type) {
225 m_refData = nullptr;
226 Init(type);
227}
228
231 m_refData = nullptr;
232 wxJSONRefData* data = Init(wxJSONTYPE_INT);
233 wxJSON_ASSERT(data);
234 if (data != 0) {
235 // the 'VAL_INT' macro expands to 'm_valLong' or 'm_valInt64' depending
236 // on 64-bits integer support being enabled on not
237 data->m_value.VAL_INT = i;
238 }
239}
240
242wxJSONValue::wxJSONValue(unsigned int ui) {
243 m_refData = nullptr;
244 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
245 wxJSON_ASSERT(data);
246 if (data != 0) {
247 // the 'VAL_UINT' macro expands to 'm_valULong' or 'm_valUInt64' depending
248 // on 64-bits integer support being enabled on not
249 data->m_value.VAL_UINT = ui;
250 }
251}
252
254wxJSONValue::wxJSONValue(short int i) {
255 m_refData = nullptr;
256 wxJSONRefData* data = Init(wxJSONTYPE_INT);
257 wxJSON_ASSERT(data);
258 if (data != 0) {
259 // the 'VAL_INT' macro expands to 'm_valLong' or 'm_valInt64' depending
260 // on 64-bits integer support being enabled on not
261 data->m_value.VAL_INT = i;
262 }
263}
264
266wxJSONValue::wxJSONValue(unsigned short ui) {
267 m_refData = nullptr;
268 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
269 wxJSON_ASSERT(data);
270 if (data != 0) {
271 // the 'VAL_UINT' macro expands to 'm_valULong' or 'm_valUInt64' depending
272 // on 64-bits integer support being enabled on not
273 data->m_value.VAL_UINT = ui;
274 }
275}
276
279 m_refData = nullptr;
280 wxJSONRefData* data = Init(wxJSONTYPE_BOOL);
281 wxJSON_ASSERT(data);
282 if (data != 0) {
283 data->m_value.m_valBool = b;
284 }
285}
286
288wxJSONValue::wxJSONValue(double d) {
289 m_refData = nullptr;
290 wxJSONRefData* data = Init(wxJSONTYPE_DOUBLE);
291 wxJSON_ASSERT(data);
292 if (data != 0) {
293 data->m_value.m_valDouble = d;
294 }
295}
296
298wxJSONValue::wxJSONValue(const wxChar* str) {
299 m_refData = nullptr;
300 wxJSONRefData* data = Init(wxJSONTYPE_CSTRING);
301 wxJSON_ASSERT(data);
302 if (data != 0) {
303#if !defined(WXJSON_USE_CSTRING)
304 data->m_type = wxJSONTYPE_STRING;
305 data->m_valString.assign(str);
306#else
307 data->m_value.m_valCString = str;
308#endif
309 }
310}
311
313wxJSONValue::wxJSONValue(const wxString& str) {
314 m_refData = nullptr;
315 wxJSONRefData* data = Init(wxJSONTYPE_STRING);
316 wxJSON_ASSERT(data);
317 if (data != 0) {
318 data->m_valString.assign(str);
319 }
320}
321
323wxJSONValue::wxJSONValue(long int l) {
324 m_refData = nullptr;
325 wxJSONRefData* data = Init(wxJSONTYPE_INT);
326 wxJSON_ASSERT(data);
327 if (data != 0) {
328 data->m_value.VAL_INT = l;
329 }
330}
331
333wxJSONValue::wxJSONValue(unsigned long int ul) {
334 m_refData = nullptr;
335 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
336 wxJSON_ASSERT(data);
337 if (data != 0) {
338 data->m_value.VAL_UINT = ul;
339 }
340}
341
343
348wxJSONValue::wxJSONValue(const wxMemoryBuffer& buff) {
349 m_refData = nullptr;
350 wxJSONRefData* data = Init(wxJSONTYPE_MEMORYBUFF);
351 wxJSON_ASSERT(data);
352 if (data != 0) {
353 data->m_memBuff = new wxMemoryBuffer();
354 const void* ptr = buff.GetData();
355 size_t buffLen = buff.GetDataLen();
356 if (buffLen > 0) {
357 data->m_memBuff->AppendData(ptr, buffLen);
358 }
359 }
360}
361
363
368wxJSONValue::wxJSONValue(const void* buff, size_t len) {
369 m_refData = nullptr;
370 wxJSONRefData* data = Init(wxJSONTYPE_MEMORYBUFF);
371 wxJSON_ASSERT(data);
372 if (data != 0 && len > 0) {
373 data->m_memBuff = new wxMemoryBuffer();
374 data->m_memBuff->AppendData(buff, len);
375 }
376}
377
379
387 m_refData = nullptr;
388 Ref(other);
389
390 // the progressive counter of the ctor is not copied from
391 // the other wxJSONValue object: only data is shared, the
392 // progressive counter is not shared because this object
393 // is a copy of 'other' and it has its own progressive
394#if defined(WXJSON_USE_VALUE_COUNTER)
395 m_progr = sm_progr;
396 ++sm_progr;
397 wxLogTrace(cowTraceMask, "(%s) Copy ctor - progr=%d other progr=%d",
398 __PRETTY_FUNCTION__, m_progr, other.m_progr);
399#endif
400}
401
404
405// functions for retreiving the value type: they are all 'const'
406
408
458wxJSONType wxJSONValue::GetType() const {
459 wxJSONRefData* data = GetRefData();
460 wxJSONType type = wxJSONTYPE_INVALID;
461 if (data) {
462 type = data->m_type;
463
464 // for integers and unsigned ints check the storage requirements
465 // note that ints are stored as 'long' or as 'long long'
466 switch (type) {
467 case wxJSONTYPE_INT:
468 // check if the integer fits in a SHORT INT
469 if (data->m_value.VAL_INT >= SHORT_MIN &&
470 data->m_value.VAL_INT <= SHORT_MAX) {
471 type = wxJSONTYPE_SHORT;
472 }
473 // check if the value fits in LONG INT
474 else if (data->m_value.VAL_INT >= LONG_MIN &&
475 data->m_value.VAL_INT <= LONG_MAX) {
476 type = wxJSONTYPE_LONG;
477 } else {
478 type = wxJSONTYPE_INT64;
479 }
480 break;
481
482 case wxJSONTYPE_UINT:
483 if (data->m_value.VAL_UINT <= USHORT_MAX) {
484 type = wxJSONTYPE_USHORT;
485 } else if (data->m_value.VAL_UINT <= ULONG_MAX) {
486 type = wxJSONTYPE_ULONG;
487 } else {
488 type = wxJSONTYPE_UINT64;
489 }
490 break;
491
492 default:
493 break;
494 }
495 }
496 return type;
497}
498
501 wxJSONType type = GetType();
502 bool r = false;
503 if (type == wxJSONTYPE_NULL) {
504 r = true;
505 }
506 return r;
507}
508
510
522 wxJSONType type = GetType();
523 bool r = false;
524 if (type != wxJSONTYPE_INVALID) {
525 r = true;
526 }
527 return r;
528}
529
531
552bool wxJSONValue::IsInt() const {
553 wxJSONType type = GetType();
554 bool r = false;
555 // if the type is SHORT the value fits into an INT, too
556 if (type == wxJSONTYPE_SHORT) {
557 r = true;
558 } else if (type == wxJSONTYPE_LONG) {
559 // in case of LONG, check if the bit width is the same
560 if (INT_MAX == LONG_MAX) {
561 r = true;
562 }
563 }
564 return r;
565}
566
568
582 wxJSONType type = GetType();
583 bool r = false;
584 if (type == wxJSONTYPE_SHORT) {
585 r = true;
586 }
587 return r;
588}
589
591
614 wxJSONType type = GetType();
615 bool r = false;
616 if (type == wxJSONTYPE_USHORT) {
617 r = true;
618 } else if (type == wxJSONTYPE_ULONG) {
619 if (INT_MAX == LONG_MAX) {
620 r = true;
621 }
622 }
623 return r;
624}
625
627
641 wxJSONType type = GetType();
642 bool r = false;
643 if (type == wxJSONTYPE_USHORT) {
644 r = true;
645 }
646 return r;
647}
648
650
664 wxJSONType type = GetType();
665 bool r = false;
666 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_SHORT) {
667 r = true;
668 }
669 return r;
670}
671
674
688 wxJSONType type = GetType();
689 bool r = false;
690 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_USHORT) {
691 r = true;
692 }
693 return r;
694}
695
698 wxJSONType type = GetType();
699 bool r = false;
700 if (type == wxJSONTYPE_BOOL) {
701 r = true;
702 }
703 return r;
704}
705
708 wxJSONType type = GetType();
709 bool r = false;
710 if (type == wxJSONTYPE_DOUBLE) {
711 r = true;
712 }
713 return r;
714}
715
718 wxJSONType type = GetType();
719 bool r = false;
720 if (type == wxJSONTYPE_STRING) {
721 r = true;
722 }
723 return r;
724}
725
728
737 wxJSONType type = GetType();
738 bool r = false;
739 if (type == wxJSONTYPE_CSTRING) {
740 r = true;
741 }
742 return r;
743}
744
747 wxJSONType type = GetType();
748 bool r = false;
749 if (type == wxJSONTYPE_ARRAY) {
750 r = true;
751 }
752 return r;
753}
754
757 wxJSONType type = GetType();
758 bool r = false;
759 if (type == wxJSONTYPE_OBJECT) {
760 r = true;
761 }
762 return r;
763}
764
767 wxJSONType type = GetType();
768 bool r = false;
769 if (type == wxJSONTYPE_MEMORYBUFF) {
770 r = true;
771 }
772 return r;
773}
774
775// get the stored value; all these functions are 'const'
776
778
790 wxJSONRefData* data = GetRefData();
791 wxJSON_ASSERT(data);
792 int i = (int)data->m_value.VAL_INT;
793
794 wxJSON_ASSERT(IsInt());
795 return i;
796}
797
799
810 wxJSONRefData* data = GetRefData();
811 wxJSON_ASSERT(data);
812 wxJSON_ASSERT(data->m_type == wxJSONTYPE_BOOL);
813 return data->m_value.m_valBool;
814}
815
817
827double wxJSONValue::AsDouble() const {
828 wxJSONRefData* data = GetRefData();
829 wxJSON_ASSERT(data);
830 double d = data->m_value.m_valDouble;
831 wxJSON_ASSERT(IsDouble());
832 return d;
833}
834
836
872wxString wxJSONValue::AsString() const {
873 wxJSONRefData* data = GetRefData();
874 wxJSON_ASSERT(data);
875 wxString s;
876 int size = Size();
877 switch (data->m_type) {
878 case wxJSONTYPE_STRING:
879 s.assign(data->m_valString);
880 break;
881 case wxJSONTYPE_CSTRING:
882 s.assign(data->m_value.m_valCString);
883 break;
884 case wxJSONTYPE_INT:
885#if defined(wxJSON_64BIT_INT)
886 s.Printf("%" compatibleLongLongFmtSpec "i", data->m_value.m_valInt64);
887#else
888 s.Printf("%ld", data->m_value.m_valLong);
889#endif
890 break;
891 case wxJSONTYPE_UINT:
892#if defined(wxJSON_64BIT_INT)
893 s.Printf("%" compatibleLongLongFmtSpec "u", data->m_value.m_valUInt64);
894#else
895 s.Printf("%lu", data->m_value.m_valULong);
896#endif
897 break;
898 case wxJSONTYPE_DOUBLE:
899 s.Printf("%.10g", data->m_value.m_valDouble);
900 break;
901 case wxJSONTYPE_BOOL:
902 s.assign((data->m_value.m_valBool ? "true" : "false"));
903 break;
904 case wxJSONTYPE_NULL:
905 s.assign(_T( "null"));
906 break;
907 case wxJSONTYPE_INVALID:
908 s.assign(_T( "<invalid>"));
909 break;
910 case wxJSONTYPE_ARRAY:
911 s.Printf("[%d]", size);
912 break;
913 case wxJSONTYPE_OBJECT:
914 s.Printf("{%d}", size);
915 break;
916 case wxJSONTYPE_MEMORYBUFF:
917 s = MemoryBuffToString(*(data->m_memBuff), 5);
918 break;
919 default:
920 s.assign(_T( "wxJSONValue::AsString(): Unknown JSON type \'"));
921 s.append(TypeToString(data->m_type));
922 s.append(_T( "\'" ));
923 wxFAIL_MSG(s);
924 break;
925 }
926 return s;
927}
928
930
945const wxChar* wxJSONValue::AsCString() const {
946 const wxChar* s = nullptr;
947 wxJSONRefData* data = GetRefData();
948 wxJSON_ASSERT(data);
949 switch (data->m_type) {
950 case wxJSONTYPE_CSTRING:
951 s = data->m_value.m_valCString;
952 break;
953 case wxJSONTYPE_STRING:
954 s = data->m_valString.c_str();
955 break;
956 default:
957 break;
958 }
959 return s;
960}
961
963
974unsigned int wxJSONValue::AsUInt() const {
975 wxJSONRefData* data = GetRefData();
976 wxJSON_ASSERT(data);
977 unsigned int ui = (unsigned)data->m_value.VAL_UINT;
978
979 wxJSON_ASSERT(IsUInt());
980 return ui;
981}
982
984
995long int wxJSONValue::AsLong() const {
996 long int l;
997 wxJSONRefData* data = GetRefData();
998 wxJSON_ASSERT(data);
999 l = (long)data->m_value.VAL_INT;
1000
1001 wxJSON_ASSERT(IsLong());
1002 return l;
1003}
1004
1006
1017unsigned long int wxJSONValue::AsULong() const {
1018 wxJSONRefData* data = GetRefData();
1019 wxJSON_ASSERT(data);
1020 unsigned long int ul = (unsigned long)data->m_value.VAL_UINT;
1021
1022 wxJSON_ASSERT(IsULong()); // expands only in debug builds
1023 return ul;
1024}
1025
1027
1038short int wxJSONValue::AsShort() const {
1039 short int i;
1040 wxJSONRefData* data = GetRefData();
1041 wxJSON_ASSERT(data);
1042 i = (short)data->m_value.VAL_INT;
1043
1044 wxJSON_ASSERT(IsShort());
1045 return i;
1046}
1047
1049
1060unsigned short wxJSONValue::AsUShort() const {
1061 unsigned short ui;
1062 wxJSONRefData* data = GetRefData();
1063 wxJSON_ASSERT(data);
1064 ui = (unsigned short)data->m_value.VAL_UINT;
1065
1066 wxJSON_ASSERT(IsUShort());
1067 return ui;
1068}
1069
1071
1096bool wxJSONValue::AsInt(int& i) const {
1097 bool r = false;
1098 if (IsInt()) {
1099 i = AsInt();
1100 r = true;
1101 }
1102 return r;
1103}
1104
1105bool wxJSONValue::AsUInt(unsigned int& ui) const {
1106 bool r = false;
1107 if (IsUInt()) {
1108 ui = AsUInt();
1109 r = true;
1110 }
1111 return r;
1112}
1113
1114bool wxJSONValue::AsShort(short int& s) const {
1115 bool r = false;
1116 if (IsShort()) {
1117 s = AsShort();
1118 r = true;
1119 }
1120 return r;
1121}
1122
1123bool wxJSONValue::AsUShort(unsigned short& us) const {
1124 bool r = false;
1125 if (IsUShort()) {
1126 us = AsUShort();
1127 r = true;
1128 }
1129 return r;
1130}
1131
1132bool wxJSONValue::AsLong(long int& l) const {
1133 bool r = false;
1134 if (IsLong()) {
1135 l = AsLong();
1136 r = true;
1137 }
1138 return r;
1139}
1140
1141bool wxJSONValue::AsULong(unsigned long& ul) const {
1142 bool r = false;
1143 if (IsULong()) {
1144 ul = AsULong();
1145 r = true;
1146 }
1147 return r;
1148}
1149
1150bool wxJSONValue::AsBool(bool& b) const {
1151 bool r = false;
1152 if (IsBool()) {
1153 b = AsBool();
1154 r = true;
1155 }
1156 return r;
1157}
1158
1159bool wxJSONValue::AsDouble(double& d) const {
1160 bool r = false;
1161 if (IsDouble()) {
1162 d = AsDouble();
1163 r = true;
1164 }
1165 return r;
1166}
1167
1169
1178bool wxJSONValue::AsString(wxString& str) const {
1179 bool r = IsString();
1180 if (r) {
1181 str = AsString();
1182 }
1183 return r;
1184}
1185
1186bool wxJSONValue::AsCString(wxChar* ch) const {
1187 bool r = IsCString();
1188 if (r) {
1189 ch = (wxChar*)AsCString();
1190 }
1191 return r;
1192}
1193
1195
1213wxMemoryBuffer wxJSONValue::AsMemoryBuff() const {
1214 wxJSONRefData* data = GetRefData();
1215 wxJSON_ASSERT(data);
1216 wxMemoryBuffer buff;
1217 if (data->m_memBuff) {
1218 buff = *(data->m_memBuff);
1219 }
1220
1221 wxJSON_ASSERT(IsMemoryBuff());
1222 return buff;
1223}
1224
1226
1244bool wxJSONValue::AsMemoryBuff(wxMemoryBuffer& buff) const {
1245 bool r = IsMemoryBuff();
1246 if (r) {
1247 buff = AsMemoryBuff();
1248 }
1249 return r;
1250}
1251
1252// internal use
1253
1255
1261const wxJSONInternalMap* wxJSONValue::AsMap() const {
1262 wxJSONRefData* data = GetRefData();
1263 wxJSON_ASSERT(data);
1264
1265 const wxJSONInternalMap* v = nullptr;
1266 if (data->m_type == wxJSONTYPE_OBJECT) {
1267 v = &(data->m_valMap);
1268 }
1269 return v;
1270}
1271
1273
1279const wxJSONInternalArray* wxJSONValue::AsArray() const {
1280 wxJSONRefData* data = GetRefData();
1281 wxJSON_ASSERT(data);
1282
1283 const wxJSONInternalArray* v = nullptr;
1284 if (data->m_type == wxJSONTYPE_ARRAY) {
1285 v = &(data->m_valArray);
1286 }
1287 return v;
1288}
1289
1290// retrieve the members and other info
1291
1293
1296bool wxJSONValue::HasMember(unsigned index) const {
1297 bool r = false;
1298 int size = Size();
1299 if (index < (unsigned)size) {
1300 r = true;
1301 }
1302 return r;
1303}
1304
1306
1309bool wxJSONValue::HasMember(const wxString& key) const {
1310 bool r = false;
1311 wxJSONRefData* data = GetRefData();
1312 wxJSON_ASSERT(data);
1313
1314 if (data && data->m_type == wxJSONTYPE_OBJECT) {
1315 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1316 if (it != data->m_valMap.end()) {
1317 r = true;
1318 }
1319 }
1320 return r;
1321}
1322
1324
1331 wxJSONRefData* data = GetRefData();
1332 wxJSON_ASSERT(data);
1333
1334 int size = -1;
1335 if (data->m_type == wxJSONTYPE_ARRAY) {
1336 size = (int)data->m_valArray.GetCount();
1337 }
1338 if (data->m_type == wxJSONTYPE_OBJECT) {
1339 size = (int)data->m_valMap.size();
1340 }
1341 return size;
1342}
1343
1345
1355wxArrayString wxJSONValue::GetMemberNames() const {
1356 wxJSONRefData* data = GetRefData();
1357 wxJSON_ASSERT(data);
1358 wxJSON_ASSERT(data->m_type == wxJSONTYPE_OBJECT);
1359
1360 wxArrayString arr;
1361 if (data->m_type == wxJSONTYPE_OBJECT) {
1362 wxJSONInternalMap::iterator it;
1363 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
1364 arr.Add(it->first);
1365 }
1366 }
1367 return arr;
1368}
1369
1370// appending items, resizing and deleting items
1371// NOTE: these functions are not 'const' so we have to call
1372// the COW() function before accessing data
1373
1375
1384 wxJSONRefData* data = COW();
1385 wxJSON_ASSERT(data);
1386 if (data->m_type != wxJSONTYPE_ARRAY) {
1387 // we have to change the type of the actual object to the array type
1388 SetType(wxJSONTYPE_ARRAY);
1389 }
1390 // we add the wxJSONValue object to the wxObjArray: note that the
1391 // array makes a copy of the JSON-value object by calling its
1392 // copy ctor thus using reference count
1393 data->m_valArray.Add(value);
1394 wxJSONValue& v = data->m_valArray.Last();
1395 return v;
1396}
1397
1400 wxJSONValue v(i);
1401 wxJSONValue& r = Append(v);
1402 return r;
1403}
1404
1406wxJSONValue& wxJSONValue::Append(short int i) {
1407 wxJSONValue v(i);
1408 wxJSONValue& r = Append(v);
1409 return r;
1410}
1411
1413wxJSONValue& wxJSONValue::Append(long int l) {
1414 wxJSONValue v(l);
1415 wxJSONValue& r = Append(v);
1416 return r;
1417}
1418
1421 wxJSONValue v(b);
1422 wxJSONValue& r = Append(v);
1423 return r;
1424}
1425
1427wxJSONValue& wxJSONValue::Append(unsigned int ui) {
1428 wxJSONValue v(ui);
1429 wxJSONValue& r = Append(v);
1430 return r;
1431}
1432
1434wxJSONValue& wxJSONValue::Append(unsigned short ui) {
1435 wxJSONValue v(ui);
1436 wxJSONValue& r = Append(v);
1437 return r;
1438}
1439
1441wxJSONValue& wxJSONValue::Append(unsigned long ul) {
1442 wxJSONValue v(ul);
1443 wxJSONValue& r = Append(v);
1444 return r;
1445}
1446
1449 wxJSONValue v(d);
1450 wxJSONValue& r = Append(v);
1451 return r;
1452}
1453
1455wxJSONValue& wxJSONValue::Append(const wxChar* str) {
1456 wxJSONValue v(str);
1457 wxJSONValue& r = Append(v);
1458 return r;
1459}
1460
1462wxJSONValue& wxJSONValue::Append(const wxString& str) {
1463 wxJSONValue v(str);
1464 wxJSONValue& r = Append(v);
1465 return r;
1466}
1467
1469wxJSONValue& wxJSONValue::Append(const wxMemoryBuffer& buff) {
1470 wxJSONValue v(buff);
1471 wxJSONValue& r = Append(v);
1472 return r;
1473}
1474
1476wxJSONValue& wxJSONValue::Append(const void* buff, size_t len) {
1477 wxJSONValue v(buff, len);
1478 wxJSONValue& r = Append(v);
1479 return r;
1480}
1481
1483
1491bool wxJSONValue::Cat(const wxString& str) {
1492 wxJSONRefData* data = GetRefData();
1493 wxJSON_ASSERT(data);
1494
1495 bool r = false;
1496 if (data->m_type == wxJSONTYPE_STRING) {
1497 wxJSONRefData* data = COW();
1498 wxJSON_ASSERT(data);
1499 data->m_valString.append(str);
1500 r = true;
1501 }
1502 return r;
1503}
1504
1506
1512bool wxJSONValue::Cat(const wxMemoryBuffer& buff) {
1513 wxJSONRefData* data = GetRefData();
1514 wxJSON_ASSERT(data);
1515
1516 bool r = false;
1517 if (data->m_type == wxJSONTYPE_MEMORYBUFF) {
1518 wxJSONRefData* data = COW();
1519 wxJSON_ASSERT(data);
1520 data->m_memBuff->AppendData(buff.GetData(), buff.GetDataLen());
1521 r = true;
1522 }
1523 return r;
1524}
1525
1527bool wxJSONValue::Cat(const wxChar* str) {
1528 wxJSONRefData* data = GetRefData();
1529 wxJSON_ASSERT(data);
1530
1531 bool r = false;
1532 if (data->m_type == wxJSONTYPE_STRING) {
1533 wxJSONRefData* data = COW();
1534 wxJSON_ASSERT(data);
1535 data->m_valString.append(str);
1536 r = true;
1537 }
1538 return r;
1539}
1540
1542
1549bool wxJSONValue::Remove(int index) {
1550 wxJSONRefData* data = COW();
1551 wxJSON_ASSERT(data);
1552
1553 bool r = false;
1554 if (data->m_type == wxJSONTYPE_ARRAY) {
1555 data->m_valArray.RemoveAt(index);
1556 r = true;
1557 }
1558 return r;
1559}
1560
1562bool wxJSONValue::Remove(const wxString& key) {
1563 wxJSONRefData* data = COW();
1564 wxJSON_ASSERT(data);
1565
1566 bool r = false;
1567 if (data->m_type == wxJSONTYPE_OBJECT) {
1568 wxJSONInternalMap::size_type count = data->m_valMap.erase(key);
1569 if (count > 0) {
1570 r = true;
1571 }
1572 }
1573 return r;
1574}
1575
1577
1583 UnRef();
1584 SetType(wxJSONTYPE_INVALID);
1585}
1586
1587// retrieve an item
1588
1590
1601 wxJSONRefData* data = COW();
1602 wxJSON_ASSERT(data);
1603
1604 if (data->m_type != wxJSONTYPE_ARRAY) {
1605 data = SetType(wxJSONTYPE_ARRAY);
1606 }
1607 int size = Size();
1608 wxJSON_ASSERT(size >= 0);
1609 // if the desired element does not yet exist, we create as many
1610 // elements as needed; the new values will be 'null' values
1611 if (index >= (unsigned)size) {
1612 wxJSONValue v(wxJSONTYPE_NULL);
1613 int missing = index - size + 1;
1614 data->m_valArray.Add(v, missing);
1615 }
1616 return data->m_valArray.Item(index);
1617}
1618
1620
1628wxJSONValue& wxJSONValue::Item(const wxString& key) {
1629 wxLogTrace(traceMask, "(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1630 key.c_str());
1631#if !wxCHECK_VERSION(2, 9, 0)
1632 wxLogTrace(traceMask, "(%s) actual object: %s", __PRETTY_FUNCTION__,
1633 GetInfo().c_str());
1634#endif
1635
1636 wxJSONRefData* data = COW();
1637 wxJSON_ASSERT(data);
1638
1639 if (data->m_type != wxJSONTYPE_OBJECT) {
1640 // deletes the contained value;
1641 data = SetType(wxJSONTYPE_OBJECT);
1642 return data->m_valMap[key];
1643 }
1644 wxLogTrace(traceMask, "(%s) searching key \'%s' in the actual object",
1645 __PRETTY_FUNCTION__, key.c_str());
1646 return data->m_valMap[key];
1647}
1648
1650
1655wxJSONValue wxJSONValue::ItemAt(unsigned index) const {
1656 wxJSONRefData* data = GetRefData();
1657 wxJSON_ASSERT(data);
1658
1659 wxJSONValue v(wxJSONTYPE_INVALID);
1660 if (data->m_type == wxJSONTYPE_ARRAY) {
1661 int size = Size();
1662 wxJSON_ASSERT(size >= 0);
1663 if (index < (unsigned)size) {
1664 v = data->m_valArray.Item(index);
1665 }
1666 }
1667 return v;
1668}
1669
1671
1676wxJSONValue wxJSONValue::ItemAt(const wxString& key) const {
1677 wxLogTrace(traceMask, "(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1678 key.c_str());
1679 wxLogTrace(traceMask, "(%s) actual object: %s", __PRETTY_FUNCTION__,
1680 GetInfo().c_str());
1681
1682 wxJSONRefData* data = GetRefData();
1683 wxJSON_ASSERT(data);
1684
1685 wxJSONValue v(wxJSONTYPE_INVALID);
1686 if (data->m_type == wxJSONTYPE_OBJECT) {
1687 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1688 if (it != data->m_valMap.end()) {
1689 v = it->second;
1690 }
1691 }
1692 return v;
1693}
1694
1696
1706 wxJSONValue& v = Item(index);
1707 return v;
1708}
1709
1711
1720 wxJSONValue& v = Item(key);
1721 return v;
1722}
1723
1724//
1725// assignment operators
1726// note that reference counting is only used if the original
1727// value is a wxJSONValue object
1728// in all other cases, the operator= function deletes the old
1729// content and assigns the new one
1730
1732
1746 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1747 data->m_value.VAL_INT = i;
1748 return *this;
1749}
1750
1753 wxJSONRefData* data = SetType(wxJSONTYPE_BOOL);
1754 data->m_value.m_valBool = b;
1755 return *this;
1756}
1757
1759wxJSONValue& wxJSONValue::operator=(unsigned int ui) {
1760 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1761 data->m_value.VAL_UINT = ui;
1762 return *this;
1763}
1764
1767 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1768 data->m_value.VAL_INT = l;
1769 return *this;
1770}
1771
1773wxJSONValue& wxJSONValue::operator=(unsigned long ul) {
1774 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1775 data->m_value.VAL_UINT = ul;
1776 return *this;
1777}
1778
1781 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1782 data->m_value.VAL_INT = i;
1783 return *this;
1784}
1785
1787wxJSONValue& wxJSONValue::operator=(unsigned short ui) {
1788 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1789 data->m_value.VAL_UINT = ui;
1790 return *this;
1791}
1792
1795 wxJSONRefData* data = SetType(wxJSONTYPE_DOUBLE);
1796 data->m_value.m_valDouble = d;
1797 return *this;
1798}
1799
1801wxJSONValue& wxJSONValue::operator=(const wxChar* str) {
1802 wxJSONRefData* data = SetType(wxJSONTYPE_CSTRING);
1803 data->m_value.m_valCString = str;
1804#if !defined(WXJSON_USE_CSTRING)
1805 data->m_type = wxJSONTYPE_STRING;
1806 data->m_valString.assign(str);
1807#endif
1808 return *this;
1809}
1810
1812wxJSONValue& wxJSONValue::operator=(const wxString& str) {
1813 wxJSONRefData* data = SetType(wxJSONTYPE_STRING);
1814 data->m_valString.assign(str);
1815 return *this;
1816}
1817
1819
1824wxJSONValue& wxJSONValue::operator=(const wxMemoryBuffer& buff) {
1825 wxJSONRefData* data = SetType(wxJSONTYPE_MEMORYBUFF);
1826 data->m_memBuff = new wxMemoryBuffer();
1827 const void* ptr = buff.GetData();
1828 size_t len = buff.GetDataLen();
1829 if (data->m_memBuff && len) {
1830 data->m_memBuff->AppendData(ptr, len);
1831 }
1832 return *this;
1833}
1834
1836
1844 Ref(other);
1845 return *this;
1846}
1847
1848// finding elements
1849
1851
1876wxJSONValue wxJSONValue::Get(const wxString& key,
1877 const wxJSONValue& defaultValue) const {
1878 // NOTE: this function does many wxJSONValue copies.
1879 // so implementing COW is a good thing
1880
1881 // this is the first copy (the default value)
1882 wxJSONValue v(defaultValue);
1883
1884 wxJSONRefData* data = GetRefData();
1885 wxJSON_ASSERT(data);
1886 if (data->m_type == wxJSONTYPE_OBJECT) {
1887 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1888 if (it != data->m_valMap.end()) {
1889 v = it->second;
1890 }
1891 }
1892 return v;
1893}
1894
1895// protected functions
1896
1898
1904wxJSONValue* wxJSONValue::Find(unsigned index) const {
1905 wxJSONRefData* data = GetRefData();
1906 wxJSON_ASSERT(data);
1907
1908 wxJSONValue* vp = nullptr;
1909
1910 if (data->m_type == wxJSONTYPE_ARRAY) {
1911 size_t size = data->m_valArray.GetCount();
1912 if (index < size) {
1913 vp = &(data->m_valArray.Item(index));
1914 }
1915 }
1916 return vp;
1917}
1918
1920
1926wxJSONValue* wxJSONValue::Find(const wxString& key) const {
1927 wxJSONRefData* data = GetRefData();
1928 wxJSON_ASSERT(data);
1929
1930 wxJSONValue* vp = nullptr;
1931
1932 if (data->m_type == wxJSONTYPE_OBJECT) {
1933 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1934 if (it != data->m_valMap.end()) {
1935 vp = &(it->second);
1936 }
1937 }
1938 return vp;
1939}
1940
1942
1952wxString wxJSONValue::TypeToString(wxJSONType type) {
1953 static const wxChar* str[] = {
1954 _T( "wxJSONTYPE_INVALID" ), // 0
1955 _T( "wxJSONTYPE_NULL" ), // 1
1956 _T( "wxJSONTYPE_INT" ), // 2
1957 _T( "wxJSONTYPE_UINT" ), // 3
1958 _T( "wxJSONTYPE_DOUBLE" ), // 4
1959 _T( "wxJSONTYPE_STRING" ), // 5
1960 _T( "wxJSONTYPE_CSTRING" ), // 6
1961 _T( "wxJSONTYPE_BOOL" ), // 7
1962 _T( "wxJSONTYPE_ARRAY" ), // 8
1963 _T( "wxJSONTYPE_OBJECT" ), // 9
1964 _T( "wxJSONTYPE_LONG" ), // 10
1965 _T( "wxJSONTYPE_INT64" ), // 11
1966 _T( "wxJSONTYPE_ULONG" ), // 12
1967 _T( "wxJSONTYPE_UINT64" ), // 13
1968 _T( "wxJSONTYPE_SHORT" ), // 14
1969 _T( "wxJSONTYPE_USHORT" ), // 15
1970 _T( "wxJSONTYPE_MEMORYBUFF" ), // 16
1971 };
1972
1973 wxString s;
1974 int idx = (int)type;
1975 if (idx >= 0 && idx < 17) {
1976 s = str[idx];
1977 }
1978 return s;
1979}
1980
1982
2001wxString wxJSONValue::Dump(bool deep, int indent) const {
2002 wxJSONRefData* data = GetRefData();
2003 wxJSON_ASSERT(data);
2004
2005 wxJSONType type = GetType();
2006
2007 wxString s;
2008 if (indent > 0) {
2009 s.append(indent, ' ');
2010 }
2011
2012 wxString s1;
2013 wxString s2;
2014#if defined(WXJSON_USE_VALUE_COUNTER)
2015 s1.Printf("Object: Progr=%d Type=%s Size=%d comments=%d\n", m_progr,
2016 TypeToString(type).c_str(), Size(), data->m_comments.GetCount());
2017 s2.Printf(" : RefData=%p Progr=%d Num shares=%d\n", data, data->m_progr,
2018 data->GetRefCount());
2019#else
2020 s1.Printf("Object: Type=%s Size=%d comments=%d\n", TypeToString(type).c_str(),
2021 Size(), data->m_comments.GetCount());
2022 s2.Printf(" : RefData=%p Num shares=%d\n", data, data->GetRefCount());
2023#endif
2024 s.append(s1);
2025 if (indent > 0) {
2026 s.append(indent, ' ');
2027 }
2028 s.append(s2);
2029
2030 wxString sub;
2031
2032 // if we have to do a deep dump, we call the Dump() function for
2033 // every sub-item
2034 if (deep) {
2035 indent += 3;
2036 const wxJSONInternalMap* map;
2037 int size;
2038 ;
2039 wxJSONInternalMap::const_iterator it;
2040 switch (type) {
2041 case wxJSONTYPE_OBJECT:
2042 map = AsMap();
2043 size = Size();
2044 for (it = map->begin(); it != map->end(); ++it) {
2045 const wxJSONValue& v = it->second;
2046 sub = v.Dump(true, indent);
2047 s.append(sub);
2048 }
2049 break;
2050 case wxJSONTYPE_ARRAY:
2051 size = Size();
2052 for (int i = 0; i < size; i++) {
2053 const wxJSONValue* v = Find(i);
2054 wxJSON_ASSERT(v);
2055 sub = v->Dump(true, indent);
2056 s.append(sub);
2057 }
2058 break;
2059 default:
2060 break;
2061 }
2062 }
2063 return s;
2064}
2065
2067
2072wxString wxJSONValue::GetInfo() const {
2073 wxJSONRefData* data = GetRefData();
2074 wxJSON_ASSERT(data);
2075
2076 wxString s;
2077#if defined(WXJSON_USE_VALUE_CONTER)
2078 s.Printf("Object: Progr=%d Type=%s Size=%d comments=%d\n", data->m_progr,
2079 wxJSONValue::TypeToString(data->m_type).c_str(), Size(),
2080 data->m_comments.GetCount());
2081#else
2082 s.Printf("Object: Type=%s Size=%d comments=%d\n",
2083 wxJSONValue::TypeToString(data->m_type).c_str(), Size(),
2084 data->m_comments.GetCount());
2085#endif
2086 if (data->m_type == wxJSONTYPE_OBJECT) {
2087 wxArrayString arr = GetMemberNames();
2088 for (unsigned int i = 0; i < arr.size(); i++) {
2089 s.append(" Member name: ");
2090 s.append(arr[i]);
2091 s.append("\n");
2092 }
2093 }
2094 return s;
2095}
2096
2098
2123bool wxJSONValue::IsSameAs(const wxJSONValue& other) const {
2124 // this is a recursive function: it calls itself
2125 // for every 'value' object in an array or map
2126 bool r = false;
2127
2128 // some variables used in the switch statement
2129 int size;
2130 wxJSONInternalMap::const_iterator it;
2131
2132 // get the referenced data for the two objects
2133 wxJSONRefData* data = GetRefData();
2134 wxJSONRefData* otherData = other.GetRefData();
2135
2136 if (data == otherData) {
2137 wxLogTrace(compareTraceMask,
2138 "(%s) objects share the same referenced data - r=TRUE",
2139 __PRETTY_FUNCTION__);
2140 return true;
2141 }
2142
2143 // if the type does not match the function compares the values if
2144 // they are of compatible types such as INT, UINT and DOUBLE
2145 if (data->m_type != otherData->m_type) {
2146 // if the types are not compatible, returns false
2147 // otherwise compares the compatible types: INT, UINT and DOUBLE
2148 double val;
2149 switch (data->m_type) {
2150 case wxJSONTYPE_INT:
2151 if (otherData->m_type == wxJSONTYPE_UINT) {
2152 // compare the bits and returns true if value is between 0 and
2153 // LLONG_MAX
2154 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2155 (data->m_value.VAL_UINT == otherData->m_value.VAL_UINT)) {
2156 r = true;
2157 }
2158 } else if (otherData->m_type == wxJSONTYPE_DOUBLE) {
2159 val = data->m_value.VAL_INT;
2160 if (val == otherData->m_value.m_valDouble) {
2161 r = true;
2162 }
2163 } else {
2164 r = false;
2165 }
2166 break;
2167 case wxJSONTYPE_UINT:
2168 if (otherData->m_type == wxJSONTYPE_INT) {
2169 // compare the bits and returns true if value is between 0 and
2170 // LLONG_MAX
2171 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2172 (data->m_value.VAL_UINT == otherData->m_value.VAL_UINT)) {
2173 r = true;
2174 }
2175 } else if (otherData->m_type == wxJSONTYPE_DOUBLE) {
2176 val = data->m_value.VAL_UINT;
2177 if (val == otherData->m_value.m_valDouble) {
2178 r = true;
2179 }
2180 } else {
2181 r = false;
2182 }
2183 break;
2184 case wxJSONTYPE_DOUBLE:
2185 if (otherData->m_type == wxJSONTYPE_INT) {
2186 val = otherData->m_value.VAL_INT;
2187 if (val == data->m_value.m_valDouble) {
2188 r = true;
2189 }
2190 } else if (otherData->m_type == wxJSONTYPE_UINT) {
2191 val = otherData->m_value.VAL_UINT;
2192 if (val == data->m_value.m_valDouble) {
2193 r = true;
2194 }
2195 } else {
2196 r = false;
2197 }
2198 break;
2199 default:
2200 r = false;
2201 break;
2202 }
2203 return r;
2204 }
2205
2206 // the two objects have the same 'm_type'
2207
2208 // for comparing wxJSONTYPE_CSTRING we use two temporary wxString
2209 // objects: this is to avoid using strcmp() and wcscmp() which
2210 // may not be available on all platforms
2211 wxString s1, s2;
2212 r = true;
2213 int r1;
2214
2215 switch (data->m_type) {
2216 case wxJSONTYPE_INVALID:
2217 case wxJSONTYPE_NULL:
2218 // there is no need to compare the values
2219 break;
2220 case wxJSONTYPE_INT:
2221 if (data->m_value.VAL_INT != otherData->m_value.VAL_INT) {
2222 r = false;
2223 }
2224 break;
2225 case wxJSONTYPE_UINT:
2226 if (data->m_value.VAL_UINT != otherData->m_value.VAL_UINT) {
2227 r = false;
2228 }
2229 break;
2230 case wxJSONTYPE_DOUBLE:
2231 if (data->m_value.m_valDouble != otherData->m_value.m_valDouble) {
2232 r = false;
2233 }
2234 break;
2235 case wxJSONTYPE_CSTRING:
2236 s1 = wxString(data->m_value.m_valCString);
2237 s2 = wxString(otherData->m_value.m_valCString);
2238 if (s1 != s2) {
2239 r = false;
2240 }
2241 break;
2242 case wxJSONTYPE_BOOL:
2243 if (data->m_value.m_valBool != otherData->m_value.m_valBool) {
2244 r = false;
2245 }
2246 break;
2247 case wxJSONTYPE_STRING:
2248 if (data->m_valString != otherData->m_valString) {
2249 r = false;
2250 }
2251 break;
2252 case wxJSONTYPE_MEMORYBUFF:
2253 // we cannot simply use the operator ==; we need a deep comparison
2254 r1 = CompareMemoryBuff(*(data->m_memBuff), *(otherData->m_memBuff));
2255 if (r1 != 0) {
2256 r = false;
2257 }
2258 break;
2259 case wxJSONTYPE_ARRAY:
2260 size = Size();
2261 wxLogTrace(compareTraceMask, "(%s) Comparing an array object - size=%d",
2262 __PRETTY_FUNCTION__, size);
2263
2264 if (size != other.Size()) {
2265 wxLogTrace(compareTraceMask, "(%s) Sizes does not match",
2266 __PRETTY_FUNCTION__);
2267 return false;
2268 }
2269 // compares every element in this object with the element of
2270 // the same index in the 'other' object
2271 for (int i = 0; i < size; i++) {
2272 wxLogTrace(compareTraceMask, "(%s) Comparing array element=%d",
2273 __PRETTY_FUNCTION__, i);
2274 wxJSONValue v1 = ItemAt(i);
2275 wxJSONValue v2 = other.ItemAt(i);
2276
2277 if (!v1.IsSameAs(v2)) {
2278 return false;
2279 }
2280 }
2281 break;
2282 case wxJSONTYPE_OBJECT:
2283 size = Size();
2284 wxLogTrace(compareTraceMask, "(%s) Comparing a map obejct - size=%d",
2285 __PRETTY_FUNCTION__, size);
2286
2287 if (size != other.Size()) {
2288 wxLogTrace(compareTraceMask,
2289 "(%s) Comparison failed - sizes does not match",
2290 __PRETTY_FUNCTION__);
2291 return false;
2292 }
2293 // for every key calls itself on the value found in
2294 // the other object. if 'key' does no exist, returns FALSE
2295 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
2296 wxString key = it->first;
2297 wxLogTrace(compareTraceMask, "(%s) Comparing map object - key=%s",
2298 __PRETTY_FUNCTION__, key.c_str());
2299 wxJSONValue otherVal = other.ItemAt(key);
2300 bool isSame = it->second.IsSameAs(otherVal);
2301 if (!isSame) {
2302 wxLogTrace(compareTraceMask,
2303 "(%s) Comparison failed for the last object",
2304 __PRETTY_FUNCTION__);
2305 return false;
2306 }
2307 }
2308 break;
2309 default:
2310 // should never happen
2311 wxFAIL_MSG("wxJSONValue::IsSameAs() unexpected wxJSONType");
2312 break;
2313 }
2314 return r;
2315}
2316
2318
2342int wxJSONValue::AddComment(const wxString& str, int position) {
2343 wxJSONRefData* data = COW();
2344 wxJSON_ASSERT(data);
2345
2346 wxLogTrace(traceMask, "(%s) comment=%s", __PRETTY_FUNCTION__, str.c_str());
2347 int r = -1;
2348 int len = str.length();
2349 if (len < 2) {
2350 wxLogTrace(traceMask, " error: len < 2");
2351 return -1;
2352 }
2353 if (str[0] != '/') {
2354 wxLogTrace(traceMask, " error: does not start with\'/\'");
2355 return -1;
2356 }
2357 if (str[1] == '/') { // a C++ comment: check that it ends with '\n'
2358 wxLogTrace(traceMask, _T(" C++ comment" ));
2359 if (str.GetChar(len - 1) != '\n') {
2360 wxString temp(str);
2361 temp.append(1, '\n');
2362 data->m_comments.Add(temp);
2363 wxLogTrace(traceMask, " C++ comment: LF added");
2364 } else {
2365 data->m_comments.Add(str);
2366 }
2367 r = data->m_comments.size();
2368 } else if (str[1] ==
2369 '*') { // a C-style comment: check that it ends with '*/'
2370 wxLogTrace(traceMask, " C-style comment");
2371 int lastPos = len - 1;
2372 wxChar ch = str.GetChar(lastPos);
2373 // skip leading whitespaces
2374 while (ch == ' ' || ch == '\n' || ch == '\t') {
2375 --lastPos;
2376 ch = str.GetChar(lastPos);
2377 }
2378 if (str.GetChar(lastPos) == '/' && str.GetChar(lastPos - 1) == '*') {
2379 data->m_comments.Add(str);
2380 r = data->m_comments.size();
2381 }
2382 } else {
2383 wxLogTrace(traceMask, " error: is not a valid comment string");
2384 r = -1;
2385 }
2386 // if the comment was stored, store the position
2387 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2388 data->m_commentPos = position;
2389 }
2390 return r;
2391}
2392
2394
2400int wxJSONValue::AddComment(const wxArrayString& comments, int position) {
2401 int siz = comments.GetCount();
2402 int r = 0;
2403 for (int i = 0; i < siz; i++) {
2404 int r2 = AddComment(comments[i], position);
2405 if (r2 >= 0) {
2406 ++r;
2407 }
2408 }
2409 return r;
2410}
2411
2413
2419wxString wxJSONValue::GetComment(int idx) const {
2420 wxJSONRefData* data = GetRefData();
2421 wxJSON_ASSERT(data);
2422
2423 wxString s;
2424 int size = data->m_comments.GetCount();
2425 if (idx < 0) {
2426 for (int i = 0; i < size; i++) {
2427 s.append(data->m_comments[i]);
2428 }
2429 } else if (idx < size) {
2430 s = data->m_comments[idx];
2431 }
2432 return s;
2433}
2434
2437 wxJSONRefData* data = GetRefData();
2438 wxJSON_ASSERT(data);
2439
2440 int d = data->m_comments.GetCount();
2441 wxLogTrace(traceMask, "(%s) comment count=%d", __PRETTY_FUNCTION__, d);
2442 return d;
2443}
2444
2447 wxJSONRefData* data = GetRefData();
2448 wxJSON_ASSERT(data);
2449 return data->m_commentPos;
2450}
2451
2453const wxArrayString& wxJSONValue::GetCommentArray() const {
2454 wxJSONRefData* data = GetRefData();
2455 wxJSON_ASSERT(data);
2456
2457 return data->m_comments;
2458}
2459
2462 wxJSONRefData* data = COW();
2463 wxJSON_ASSERT(data);
2464
2465 data->m_comments.clear();
2466}
2467
2469
2531 wxJSONRefData* data = GetRefData();
2532 wxJSONType oldType = GetType();
2533
2534 // check that type is within the allowed range
2535 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2536 (type <= wxJSONTYPE_MEMORYBUFF));
2537 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2538 type = wxJSONTYPE_INVALID;
2539 }
2540
2541 // the function unshares the referenced data but does not delete the
2542 // structure. This is because the wxJSON reader stores comments
2543 // that apear before the value in a temporary value of type wxJSONTYPE_INVALID
2544 // which is invalid and, next, it stores the JSON value in the same
2545 // wxJSONValue object.
2546 // If we would delete the structure using 'Unref()' we loose the
2547 // comments
2548 data = COW();
2549
2550 // do nothing if the actual type is the same as 'type'
2551 if (type == oldType) {
2552 return data;
2553 }
2554
2555 // change the type of the referened structure
2556 // NOTE: integer types are always stored as the generic integer types
2557 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2558 type == wxJSONTYPE_SHORT) {
2559 type = wxJSONTYPE_INT;
2560 }
2561 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2562 type == wxJSONTYPE_USHORT) {
2563 type = wxJSONTYPE_UINT;
2564 }
2565
2566 wxJSON_ASSERT(data);
2567 data->m_type = type;
2568
2569 // clears complex objects of the old type
2570 switch (oldType) {
2571 case wxJSONTYPE_STRING:
2572 data->m_valString.clear();
2573 break;
2574 case wxJSONTYPE_ARRAY:
2575 data->m_valArray.Clear();
2576 break;
2577 case wxJSONTYPE_OBJECT:
2578 data->m_valMap.clear();
2579 break;
2580 case wxJSONTYPE_MEMORYBUFF:
2581 // we first have to delete the actual memory buffer, if any
2582 if (data->m_memBuff) {
2583 delete data->m_memBuff;
2584 data->m_memBuff = 0;
2585 }
2586 break;
2587 default:
2588 // there is not need to clear primitive types
2589 break;
2590 }
2591
2592 // if the WXJSON_USE_CSTRING macro is not defined, the class forces
2593 // C-string to be stored as wxString objects
2594#if !defined(WXJSON_USE_CSTRING)
2595 if (data->m_type == wxJSONTYPE_CSTRING) {
2596 data->m_type = wxJSONTYPE_STRING;
2597 }
2598#endif
2599 return data;
2600}
2601
2603
2613 // return ZERO if there is not a referenced data structure
2614 int n = 0;
2615 wxJSONRefData* data = GetRefData();
2616 if (data != 0) {
2617 n = data->m_lineNo;
2618 }
2619 return n;
2620}
2621
2624 wxJSONRefData* data = COW();
2625 wxJSON_ASSERT(data);
2626 data->m_lineNo = num;
2627}
2628
2631
2633void wxJSONValue::Ref(const wxJSONValue& clone) {
2634 // nothing to be done
2635 if (m_refData == clone.m_refData) return;
2636
2637 // delete reference to old data
2638 UnRef();
2639
2640 // reference new data
2641 if (clone.m_refData) {
2642 m_refData = clone.m_refData;
2643 ++(m_refData->m_refCount);
2644 }
2645}
2646
2648
2654 if (m_refData) {
2655 wxASSERT_MSG(m_refData->m_refCount > 0, "invalid ref data count");
2656
2657 if (--m_refData->m_refCount == 0) {
2658 delete m_refData;
2659 m_refData = nullptr;
2660 }
2661 }
2662}
2663
2666
2668
2673 UnRef();
2674 wxJSONRefData* data = CloneRefData(other.m_refData);
2675 SetRefData(data);
2676}
2677
2680 wxJSONRefData* data = m_refData;
2681 return data;
2682}
2683
2685
2694 wxJSON_ASSERT(otherData);
2695
2696 // make a static cast to pointer-to-wxJSONRefData
2697 const wxJSONRefData* other = otherData;
2698
2699 // allocate a new instance of wxJSONRefData using the default
2700 // ctor; we cannot use the copy ctor of a wxJSONRefData
2701 wxJSONRefData* data = new wxJSONRefData();
2702
2703 // copy the referenced data structure's data members
2704 data->m_type = other->m_type;
2705 data->m_value = other->m_value;
2706 data->m_commentPos = other->m_commentPos;
2707 data->m_comments = other->m_comments;
2708 data->m_lineNo = other->m_lineNo;
2709 data->m_valString = other->m_valString;
2710 data->m_valArray = other->m_valArray;
2711 data->m_valMap = other->m_valMap;
2712
2713 // if the data contains a wxMemoryBuffer object, then we have
2714 // to make a deep copy of the buffer by allocating a new one because
2715 // wxMemoryBuffer is not a copy-on-write structure
2716 if (other->m_memBuff) {
2717 data->m_memBuff = new wxMemoryBuffer();
2718 const void* ptr = data->m_memBuff->GetData();
2719 size_t len = data->m_memBuff->GetDataLen();
2720 if (data->m_memBuff && len) {
2721 data->m_memBuff->AppendData(ptr, len);
2722 }
2723 }
2724
2725 wxLogTrace(cowTraceMask, "(%s) CloneRefData() PROGR: other=%d data=%d",
2726 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2727
2728 return data;
2729}
2730
2732
2739 wxJSONRefData* data = new wxJSONRefData();
2740 data->m_type = wxJSONTYPE_INVALID;
2741 return data;
2742}
2743
2745
2752 wxJSONRefData* data = GetRefData();
2753 wxLogTrace(cowTraceMask, "(%s) COW() START data=%p data->m_count=%d",
2754 __PRETTY_FUNCTION__, data, data->GetRefCount());
2755 UnShare();
2756 data = GetRefData();
2757 wxLogTrace(cowTraceMask, "(%s) COW() END data=%p data->m_count=%d",
2758 __PRETTY_FUNCTION__, data, data->GetRefCount());
2759 return GetRefData();
2760}
2761
2764 if (!m_refData) {
2766 } else if (m_refData->GetRefCount() > 1) {
2767 // note that ref is not going to be destroyed in this case
2768 const wxJSONRefData* ref = m_refData;
2769 UnRef();
2770
2771 // ... so we can still access it
2772 m_refData = CloneRefData(ref);
2773 }
2774 // else: ref count is 1, we are exclusive owners of m_refData anyhow
2775
2776 wxASSERT_MSG(m_refData && m_refData->GetRefCount() == 1,
2777 "wxObject::AllocExclusive() failed.");
2778}
2779
2781/*/
2782 The fucntion returns a string representation of the data contained in the
2783 memory buffer object \c buff.
2784 The string is conposed of two hexadecimal digits for every byte contained
2785 in the memory buffer; bytes are separated by a space character.
2786 The string starts with the actual lenght of the data enclosed in parenthesis.
2787 The string will contain \c len bytes if \c len is less than the length
2788 of the actual data in \c buff.
2789 Note that the (len) printed in the output referes to the length of the buffer
2790 which may be greater than the length that has to be printed.
2791
2792 \b Example:
2793 This is an example of printing a memory buffer object that contains 10 bytes:
2794 \code
2795 0x80974653 (10) 00 01 02 03 04 05 06 07 08 09
2796 \endcode
2797*/
2798wxString wxJSONValue::MemoryBuffToString(const wxMemoryBuffer& buff,
2799 size_t len) {
2800 size_t buffLen = buff.GetDataLen();
2801 void* ptr = buff.GetData();
2802 wxString s = MemoryBuffToString(ptr, MIN(buffLen, len), buffLen);
2803 return s;
2804}
2805
2807/*/
2808 The function returns a string representation of the data contained in the
2809 binary memory buffer pointed to by \c buff for \c len bytes.
2810 The string is composed of two hexadecimal digits for every byte contained
2811 in the memory buffer; bytes are separated by a space character.
2812 The string starts with pointer to binary data followed by the lenght of the
2813 data enclosed in parenthesis.
2814
2815 \b Example:
2816 This is an example of printing ten bytes from a memory buffer:
2817 \code
2818 0x80974653 (10) 00 01 02 03 04 05 06 07 08 09
2819 \endcode
2820
2821 @param buff the pointer to the memory buffer data
2822 @len the length of the data that has to be printed
2823 @actualLen the real lenght of the memory buffer that has to be printed
2824 just afetr the pointer; may be greater than \c len. If this parameter
2825 is -1 then it is equal to \c len
2826*/
2827wxString wxJSONValue::MemoryBuffToString(const void* buff, size_t len,
2828 size_t actualLen) {
2829 wxString s;
2830 size_t buffLen = actualLen;
2831 if (buffLen == (size_t)-1) {
2832 buffLen = len;
2833 }
2834 s.Printf("%p (%u) ", buff, buffLen);
2835 unsigned char* ptr = (unsigned char*)buff;
2836 for (unsigned int i = 0; i < len; i++) {
2837 unsigned char c = *ptr;
2838 ++ptr;
2839 // now convert the character
2840 char c1 = c / 16;
2841 char c2 = c % 16;
2842 c1 += '0';
2843 c2 += '0';
2844 if (c1 > '9') {
2845 c1 += 7;
2846 }
2847 if (c2 > '9') {
2848 c2 += 7;
2849 }
2850 s.Append(c1, 1);
2851 s.Append(c2, 1);
2852 s.Append(' ', 1); // a space separates the bytes
2853 }
2854 return s;
2855}
2856
2858
2882int wxJSONValue::CompareMemoryBuff(const wxMemoryBuffer& buff1,
2883 const wxMemoryBuffer& buff2) {
2884 int r;
2885 size_t buff1Len = buff1.GetDataLen();
2886 size_t buff2Len = buff2.GetDataLen();
2887 if (buff1Len > buff2Len) {
2888 r = 1;
2889 } else if (buff1Len < buff2Len) {
2890 r = -1;
2891 } else {
2892 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2893 }
2894 return r;
2895}
2896
2898
2909int wxJSONValue::CompareMemoryBuff(const wxMemoryBuffer& buff1,
2910 const void* buff2) {
2911 int r;
2912 size_t buff1Len = buff1.GetDataLen();
2913 r = memcmp(buff1.GetData(), buff2, buff1Len);
2914 return r;
2915}
2916
2918
2938wxMemoryBuffer wxJSONValue::ArrayToMemoryBuff(const wxJSONValue& value) {
2939 wxMemoryBuffer buff;
2940 if (value.IsArray()) {
2941 int len = value.Size();
2942 for (int i = 0; i < len; i++) {
2943 short int byte;
2944 unsigned char c;
2945 // we do not use opertaor [] because it is not const
2946 // bool r = value[i].AsShort( byte );
2947 bool r = value.ItemAt(i).AsShort(byte);
2948 if (r && (byte >= 0 && byte <= 255)) {
2949 c = (unsigned char)byte;
2950 buff.AppendByte(c);
2951 }
2952 }
2953 }
2954 return buff;
2955}
2956
2957/*************************************************************************
2958
2959 64-bits integer support
2960
2961*************************************************************************/
2962
2963#if defined(wxJSON_64BIT_INT)
2964
2966wxJSONValue::wxJSONValue(wxInt64 i) {
2967 m_refData = nullptr;
2968 wxJSONRefData* data = Init(wxJSONTYPE_INT);
2969 wxJSON_ASSERT(data);
2970 if (data != 0) {
2971 data->m_value.VAL_INT = i;
2972 }
2973}
2974
2976wxJSONValue::wxJSONValue(wxUint64 ui) {
2977 m_refData = nullptr;
2978 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
2979 wxJSON_ASSERT(data);
2980 if (data != 0) {
2981 data->m_value.VAL_UINT = ui;
2982 }
2983}
2984
2986
2994bool wxJSONValue::IsInt32() const {
2995 bool r = IsLong();
2996 return r;
2997}
2998
3000
3008bool wxJSONValue::IsUInt32() const {
3009 bool r = IsULong();
3010 return r;
3011}
3012
3014
3023bool wxJSONValue::IsInt64() const {
3024 wxJSONRefData* data = GetRefData();
3025 wxJSON_ASSERT(data);
3026 bool r = false;
3027 if (data->m_type == wxJSONTYPE_INT) {
3028 r = true;
3029 }
3030 return r;
3031}
3032
3034
3043bool wxJSONValue::IsUInt64() const {
3044 wxJSONRefData* data = GetRefData();
3045 wxJSON_ASSERT(data);
3046 bool r = false;
3047 if (data->m_type == wxJSONTYPE_UINT) {
3048 r = true;
3049 }
3050 return r;
3051}
3052
3054
3065wxInt32 wxJSONValue::AsInt32() const {
3066 wxInt32 i;
3067 i = (wxInt32)AsLong();
3068 return i;
3069}
3070
3072
3083wxUint32 wxJSONValue::AsUInt32() const {
3084 wxUint32 ui;
3085 ui = (wxUint32)AsULong();
3086 return ui;
3087}
3088
3090
3103wxInt64 wxJSONValue::AsInt64() const {
3104 wxJSONRefData* data = GetRefData();
3105 wxJSON_ASSERT(data);
3106 wxInt64 i64 = data->m_value.m_valInt64;
3107
3108 wxJSON_ASSERT(IsInt64()); // exapnds only in debug builds
3109 return i64;
3110}
3111
3113
3126wxUint64 wxJSONValue::AsUInt64() const {
3127 wxJSONRefData* data = GetRefData();
3128 wxJSON_ASSERT(data);
3129 wxUint64 ui64 = data->m_value.m_valUInt64;
3130
3131 wxJSON_ASSERT(IsUInt64()); // exapnds only in debug builds
3132 return ui64;
3133}
3134
3135bool wxJSONValue::AsInt32(wxInt32& i32) const {
3136 bool r = IsInt32();
3137 if (r) {
3138 i32 = AsInt32();
3139 }
3140 return r;
3141}
3142
3143bool wxJSONValue::AsUInt32(wxUint32& ui32) const {
3144 bool r = IsUInt32();
3145 if (r) {
3146 ui32 = AsUInt32();
3147 }
3148 return r;
3149}
3150
3151bool wxJSONValue::AsInt64(wxInt64& i64) const {
3152 bool r = IsInt64();
3153 if (r) {
3154 i64 = AsInt64();
3155 }
3156 return r;
3157}
3158
3159bool wxJSONValue::AsUInt64(wxUint64& ui64) const {
3160 bool r = IsUInt64();
3161 if (r) {
3162 ui64 = AsUInt64();
3163 }
3164 return r;
3165}
3166
3168wxJSONValue& wxJSONValue::Append(wxInt64 i) {
3169 wxJSONValue v(i);
3170 wxJSONValue& r = Append(v);
3171 return r;
3172}
3173
3175wxJSONValue& wxJSONValue::Append(wxUint64 ui) {
3176 wxJSONValue v(ui);
3177 wxJSONValue& r = Append(v);
3178 return r;
3179}
3180
3183 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
3184 data->m_value.VAL_INT = i;
3185 return *this;
3186}
3187
3189wxJSONValue& wxJSONValue::operator=(wxUint64 ui) {
3190 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
3191 data->m_value.VAL_UINT = ui;
3192 return *this;
3193}
3194
3195#endif // defined( wxJSON_64BIT_INT )
3196
3197/*
3198{
3199}
3200*/
The reference counted JSON value data (internal use).
Definition jsonval.h:350
wxMemoryBuffer * m_memBuff
The pointer to the memory buffer object.
Definition jsonval.h:415
wxJSONInternalMap m_valMap
The JSON object value.
Definition jsonval.h:385
int m_commentPos
The position of the comment line(s), if any.
Definition jsonval.h:394
int m_refCount
the references count
Definition jsonval.h:364
wxJSONInternalArray m_valArray
The JSON array value.
Definition jsonval.h:382
wxJSONType m_type
The actual type of the value held by this object.
Definition jsonval.h:367
int m_lineNo
The line number when this value was read.
Definition jsonval.h:407
wxJSONRefData()
Constructor.
Definition jsonval.cpp:72
wxString m_valString
The JSON string value.
Definition jsonval.h:379
wxJSONValueHolder m_value
The JSON value held by this object.
Definition jsonval.h:376
wxArrayString m_comments
The array of comment lines; may be empty.
Definition jsonval.h:397
The JSON value class implementation.
Definition jsonval.h:84
bool IsSameAs(const wxJSONValue &other) const
The comparison function.
Definition jsonval.cpp:2123
void Ref(const wxJSONValue &clone)
Increments the referenced data counter.
Definition jsonval.cpp:2633
wxArrayString GetMemberNames() const
Return the array of keys of this JSON object.
Definition jsonval.cpp:1355
bool IsArray() const
Return TRUE if the type of the value stored is an array type.
Definition jsonval.cpp:746
bool IsCString() const
Return TRUE if the type of the value stored is a pointer to a static C string.
Definition jsonval.cpp:736
void UnShare()
Makes an exclusive copy of shared data.
Definition jsonval.cpp:2665
bool Remove(int index)
Remove the item at the specified index or key.
Definition jsonval.cpp:1549
int AddComment(const wxString &str, int position=wxJSONVALUE_COMMENT_DEFAULT)
Add a comment to this JSON value object.
Definition jsonval.cpp:2342
virtual wxJSONRefData * CloneRefData(const wxJSONRefData *data) const
Make a copy of the referenced data.
Definition jsonval.cpp:2693
bool IsUInt() const
Return TRUE if the type of the value stored is a unsigned int.
Definition jsonval.cpp:613
wxString Dump(bool deep=false, int mode=0) const
Returns informations about the object.
Definition jsonval.cpp:2001
wxJSONRefData * Init(wxJSONType type)
Initialize the JSON value class.
Definition jsonval.cpp:196
long int AsLong() const
Returns the value as a long integer.
Definition jsonval.cpp:995
bool IsLong() const
Return TRUE if the stored value is an integer which fits in a long int.
Definition jsonval.cpp:663
int Size() const
Return the size of the array or map stored in this value.
Definition jsonval.cpp:1330
int GetCommentCount() const
Return the number of comment strings.
Definition jsonval.cpp:2436
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
Definition jsonval.cpp:1296
bool IsDouble() const
Return TRUE if the type of the value stored is a double.
Definition jsonval.cpp:707
bool IsInt() const
Return TRUE if the type of the value stored is integer.
Definition jsonval.cpp:552
static wxString MemoryBuffToString(const wxMemoryBuffer &buff, size_t len=-1)
Convert memory buffer object to a string representation.
Definition jsonval.cpp:2798
bool IsShort() const
Return TRUE if the type of the value stored is 16-bit integer.
Definition jsonval.cpp:581
wxJSONValue Get(const wxString &key, const wxJSONValue &defaultValue) const
Return a value or a default value.
Definition jsonval.cpp:1876
double AsDouble() const
Return the stored value as a double.
Definition jsonval.cpp:827
virtual wxJSONRefData * CreateRefData() const
Create a new data structure.
Definition jsonval.cpp:2738
wxJSONType GetType() const
Return the type of the value stored in the object.
Definition jsonval.cpp:458
void UnRef()
Unreferences the shared data.
Definition jsonval.cpp:2653
wxJSONValue * Find(unsigned index) const
Find an element.
Definition jsonval.cpp:1904
void DeepCopy(const wxJSONValue &other)
Do a deep copy of the other object.
Definition jsonval.cpp:2672
static wxMemoryBuffer ArrayToMemoryBuff(const wxJSONValue &value)
Converts an array of INTs to a memory buffer.
Definition jsonval.cpp:2938
wxJSONValue ItemAt(unsigned index) const
Return the item at the specified index.
Definition jsonval.cpp:1655
wxJSONRefData * COW()
Make sure the referenced data is unique.
Definition jsonval.cpp:2751
wxString GetComment(int idx=-1) const
Return a comment string.
Definition jsonval.cpp:2419
void SetRefData(wxJSONRefData *data)
Set the pointer to the referenced data.
Definition jsonval.cpp:2630
bool IsString() const
Return TRUE if the type of the value stored is a wxString object.
Definition jsonval.cpp:717
void ClearComments()
Clear all comment strings.
Definition jsonval.cpp:2461
bool IsUShort() const
Return TRUE if the type of the value stored is a unsigned short.
Definition jsonval.cpp:640
const wxJSONInternalMap * AsMap() const
Return the stored value as a map object.
Definition jsonval.cpp:1261
const wxChar * AsCString() const
Return the stored value as a pointer to a static C string.
Definition jsonval.cpp:945
wxJSONValue & operator[](unsigned index)
Return the item at the specified index.
Definition jsonval.cpp:1705
static int CompareMemoryBuff(const wxMemoryBuffer &buff1, const wxMemoryBuffer &buff2)
Compares two memory buffer objects.
Definition jsonval.cpp:2882
wxJSONValue & Append(const wxJSONValue &value)
Append the specified value in the array.
Definition jsonval.cpp:1383
bool IsBool() const
Return TRUE if the type of the value stored is a boolean.
Definition jsonval.cpp:697
unsigned int AsUInt() const
Return the stored value as a unsigned int.
Definition jsonval.cpp:974
unsigned short AsUShort() const
Returns the value as a unsigned short integer.
Definition jsonval.cpp:1060
void AllocExclusive()
Makes a private copy of the referenced data.
Definition jsonval.cpp:2763
wxJSONValue()
Constructors.
Definition jsonval.cpp:183
bool IsULong() const
Return TRUE if the stored value is an integer which fits in a unsigned long int.
Definition jsonval.cpp:687
wxString AsString() const
Return the stored value as a wxWidget's string.
Definition jsonval.cpp:872
void Clear()
Clear the object value.
Definition jsonval.cpp:1582
int GetLineNo() const
Return the line number of this JSON value object.
Definition jsonval.cpp:2612
bool IsValid() const
Return TRUE if the value stored is valid.
Definition jsonval.cpp:521
bool IsMemoryBuff() const
Return TRUE if the type of this value is a binary memory buffer.
Definition jsonval.cpp:766
short AsShort() const
Returns the value as a short integer.
Definition jsonval.cpp:1038
wxString GetInfo() const
Returns informations about the object.
Definition jsonval.cpp:2072
bool IsNull() const
Return TRUE if the type of the value is wxJSONTYPE_NULL.
Definition jsonval.cpp:500
void SetLineNo(int num)
Set the line number of this JSON value object.
Definition jsonval.cpp:2623
bool IsObject() const
Return TRUE if the type of this value is a key/value map.
Definition jsonval.cpp:756
unsigned long AsULong() const
Returns the value as a unsigned long integer.
Definition jsonval.cpp:1017
bool AsBool() const
Return the stored value as a boolean.
Definition jsonval.cpp:809
wxJSONRefData * SetType(wxJSONType type)
Set the type of the stored value.
Definition jsonval.cpp:2530
int GetCommentPos() const
Return the comment position.
Definition jsonval.cpp:2446
wxJSONRefData * m_refData
the referenced data
Definition jsonval.h:287
virtual ~wxJSONValue()
Dtor - calls UnRef().
Definition jsonval.cpp:403
wxJSONValue & operator=(int i)
Assign the specified value to this object replacing the old value.
Definition jsonval.cpp:1745
wxJSONValue & Item(unsigned index)
Return the item at the specified index.
Definition jsonval.cpp:1600
int AsInt() const
Return the stored value as an integer.
Definition jsonval.cpp:789
const wxJSONInternalArray * AsArray() const
Return the stored value as an array object.
Definition jsonval.cpp:1279
wxMemoryBuffer AsMemoryBuff() const
Returns the value as a memory buffer.
Definition jsonval.cpp:1213
const wxArrayString & GetCommentArray() const
Get the comment string's array.
Definition jsonval.cpp:2453
wxJSONRefData * GetRefData() const
Return the pointer to the referenced data structure.
Definition jsonval.cpp:2679
static wxString TypeToString(wxJSONType type)
Return a string description of the type.
Definition jsonval.cpp:1952