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
17#ifdef NDEBUG
18// make wxLogTrace a noop if no debug set, it's really slow
19// must be defined before including debug.h
20#define wxDEBUG_LEVEL 0
21#endif
22
23// For compilers that support precompilation, includes "wx.h".
24#include "wx/wxprec.h"
25
26#ifdef __BORLANDC__
27#pragma hdrstop
28#endif
29
30#include <wx/log.h>
31#include <wx/debug.h>
32#include <wx/arrimpl.cpp>
33
34#include "jsonval.h"
35
36WX_DEFINE_OBJARRAY(wxJSONInternalArray);
37
38#if wxCHECK_VERSION(3, 0, 0)
39#define compatibleLongLongFmtSpec _T(wxLongLongFmtSpec)
40#else
41#define compatibleLongLongFmtSpec wxLongLongFmtSpec
42#endif
43
44// the trace mask used in wxLogTrace() function
45// static const wxChar* traceMask = "jsonval";
46#if wxDEBUG_LEVEL > 0
47static const wxChar* traceMask = "jsonval";
48static const wxChar* compareTraceMask = "sameas";
49static const wxChar* cowTraceMask = _T("traceCOW" );
50#endif
51
52/*******************************************************************
53
54 class wxJSONRefData
55
56*******************************************************************/
57
69#if defined(WXJSON_USE_VALUE_COUNTER)
70// The progressive counter (used for debugging only)
71int wxJSONRefData::sm_progr = 1;
72#endif
73
76 m_lineNo = -1;
77 m_refCount = 1;
78 m_memBuff = nullptr;
79
80#if defined(WXJSON_USE_VALUE_COUNTER)
81 m_progr = sm_progr;
82 ++sm_progr;
83 wxLogTrace(traceMask, "(%s) JSON refData ctor progr=%d", __PRETTY_FUNCTION__,
84 m_progr);
85#endif
86}
87
88// Dtor
89wxJSONRefData::~wxJSONRefData() {
90 if (m_memBuff) {
91 delete m_memBuff;
92 }
93}
94
95// Return the number of objects that reference this data.
96int wxJSONRefData::GetRefCount() const { return m_refCount; }
97
98/*******************************************************************
99
100 class wxJSONValue
101
102*******************************************************************/
103
163#if defined(WXJSON_USE_VALUE_COUNTER)
164// The progressive counter (used for debugging only)
165int wxJSONValue::sm_progr = 1;
166#endif
167
169
187 m_refData = nullptr;
188 Init(wxJSONTYPE_NULL);
189}
190
192
200 wxJSONRefData* data = GetRefData();
201 if (data != 0) {
202 UnRef();
203 }
204
205 // we allocate a new instance of the referenced data
206 data = new wxJSONRefData();
207 wxJSON_ASSERT(data);
208
209 // in release builds we do not have ASSERT so we check 'data' before
210 // using it
211 if (data) {
212 data->m_type = type;
213 data->m_commentPos = wxJSONVALUE_COMMENT_BEFORE;
214 }
215 SetRefData(data);
216
217#if defined(WXJSON_USE_VALUE_COUNTER)
218 m_progr = sm_progr;
219 ++sm_progr;
220 wxLogTrace(cowTraceMask, "(%s) Init a new object progr=%d",
221 __PRETTY_FUNCTION__, m_progr);
222#endif
223 return data;
224}
225
227wxJSONValue::wxJSONValue(wxJSONType type) {
228 m_refData = nullptr;
229 Init(type);
230}
231
234 m_refData = nullptr;
235 wxJSONRefData* data = Init(wxJSONTYPE_INT);
236 wxJSON_ASSERT(data);
237 if (data != 0) {
238 // the 'VAL_INT' macro expands to 'm_valLong' or 'm_valInt64' depending
239 // on 64-bits integer support being enabled on not
240 data->m_value.VAL_INT = i;
241 }
242}
243
245wxJSONValue::wxJSONValue(unsigned int ui) {
246 m_refData = nullptr;
247 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
248 wxJSON_ASSERT(data);
249 if (data != 0) {
250 // the 'VAL_UINT' macro expands to 'm_valULong' or 'm_valUInt64' depending
251 // on 64-bits integer support being enabled on not
252 data->m_value.VAL_UINT = ui;
253 }
254}
255
257wxJSONValue::wxJSONValue(short int i) {
258 m_refData = nullptr;
259 wxJSONRefData* data = Init(wxJSONTYPE_INT);
260 wxJSON_ASSERT(data);
261 if (data != 0) {
262 // the 'VAL_INT' macro expands to 'm_valLong' or 'm_valInt64' depending
263 // on 64-bits integer support being enabled on not
264 data->m_value.VAL_INT = i;
265 }
266}
267
269wxJSONValue::wxJSONValue(unsigned short ui) {
270 m_refData = nullptr;
271 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
272 wxJSON_ASSERT(data);
273 if (data != 0) {
274 // the 'VAL_UINT' macro expands to 'm_valULong' or 'm_valUInt64' depending
275 // on 64-bits integer support being enabled on not
276 data->m_value.VAL_UINT = ui;
277 }
278}
279
282 m_refData = nullptr;
283 wxJSONRefData* data = Init(wxJSONTYPE_BOOL);
284 wxJSON_ASSERT(data);
285 if (data != 0) {
286 data->m_value.m_valBool = b;
287 }
288}
289
291wxJSONValue::wxJSONValue(double d) {
292 m_refData = nullptr;
293 wxJSONRefData* data = Init(wxJSONTYPE_DOUBLE);
294 wxJSON_ASSERT(data);
295 if (data != 0) {
296 data->m_value.m_valDouble = d;
297 }
298}
299
301wxJSONValue::wxJSONValue(const wxChar* str) {
302 m_refData = nullptr;
303 wxJSONRefData* data = Init(wxJSONTYPE_CSTRING);
304 wxJSON_ASSERT(data);
305 if (data != 0) {
306#if !defined(WXJSON_USE_CSTRING)
307 data->m_type = wxJSONTYPE_STRING;
308 data->m_valString.assign(str);
309#else
310 data->m_value.m_valCString = str;
311#endif
312 }
313}
314
316wxJSONValue::wxJSONValue(const wxString& str) {
317 m_refData = nullptr;
318 wxJSONRefData* data = Init(wxJSONTYPE_STRING);
319 wxJSON_ASSERT(data);
320 if (data != 0) {
321 data->m_valString.assign(str);
322 }
323}
324
326wxJSONValue::wxJSONValue(long int l) {
327 m_refData = nullptr;
328 wxJSONRefData* data = Init(wxJSONTYPE_INT);
329 wxJSON_ASSERT(data);
330 if (data != 0) {
331 data->m_value.VAL_INT = l;
332 }
333}
334
336wxJSONValue::wxJSONValue(unsigned long int ul) {
337 m_refData = nullptr;
338 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
339 wxJSON_ASSERT(data);
340 if (data != 0) {
341 data->m_value.VAL_UINT = ul;
342 }
343}
344
346
351wxJSONValue::wxJSONValue(const wxMemoryBuffer& buff) {
352 m_refData = nullptr;
353 wxJSONRefData* data = Init(wxJSONTYPE_MEMORYBUFF);
354 wxJSON_ASSERT(data);
355 if (data != 0) {
356 data->m_memBuff = new wxMemoryBuffer();
357 const void* ptr = buff.GetData();
358 size_t buffLen = buff.GetDataLen();
359 if (buffLen > 0) {
360 data->m_memBuff->AppendData(ptr, buffLen);
361 }
362 }
363}
364
366
371wxJSONValue::wxJSONValue(const void* buff, size_t len) {
372 m_refData = nullptr;
373 wxJSONRefData* data = Init(wxJSONTYPE_MEMORYBUFF);
374 wxJSON_ASSERT(data);
375 if (data != 0 && len > 0) {
376 data->m_memBuff = new wxMemoryBuffer();
377 data->m_memBuff->AppendData(buff, len);
378 }
379}
380
382
390 m_refData = nullptr;
391 Ref(other);
392
393 // the progressive counter of the ctor is not copied from
394 // the other wxJSONValue object: only data is shared, the
395 // progressive counter is not shared because this object
396 // is a copy of 'other' and it has its own progressive
397#if defined(WXJSON_USE_VALUE_COUNTER)
398 m_progr = sm_progr;
399 ++sm_progr;
400 wxLogTrace(cowTraceMask, "(%s) Copy ctor - progr=%d other progr=%d",
401 __PRETTY_FUNCTION__, m_progr, other.m_progr);
402#endif
403}
404
407
408// functions for retreiving the value type: they are all 'const'
409
411
461wxJSONType wxJSONValue::GetType() const {
462 wxJSONRefData* data = GetRefData();
463 wxJSONType type = wxJSONTYPE_INVALID;
464 if (data) {
465 type = data->m_type;
466
467 // for integers and unsigned ints check the storage requirements
468 // note that ints are stored as 'long' or as 'long long'
469 switch (type) {
470 case wxJSONTYPE_INT:
471 // check if the integer fits in a SHORT INT
472 if (data->m_value.VAL_INT >= SHORT_MIN &&
473 data->m_value.VAL_INT <= SHORT_MAX) {
474 type = wxJSONTYPE_SHORT;
475 }
476 // check if the value fits in LONG INT
477 else if (data->m_value.VAL_INT >= LONG_MIN &&
478 data->m_value.VAL_INT <= LONG_MAX) {
479 type = wxJSONTYPE_LONG;
480 } else {
481 type = wxJSONTYPE_INT64;
482 }
483 break;
484
485 case wxJSONTYPE_UINT:
486 if (data->m_value.VAL_UINT <= USHORT_MAX) {
487 type = wxJSONTYPE_USHORT;
488 } else if (data->m_value.VAL_UINT <= ULONG_MAX) {
489 type = wxJSONTYPE_ULONG;
490 } else {
491 type = wxJSONTYPE_UINT64;
492 }
493 break;
494
495 default:
496 break;
497 }
498 }
499 return type;
500}
501
504 wxJSONType type = GetType();
505 bool r = false;
506 if (type == wxJSONTYPE_NULL) {
507 r = true;
508 }
509 return r;
510}
511
513
525 wxJSONType type = GetType();
526 bool r = false;
527 if (type != wxJSONTYPE_INVALID) {
528 r = true;
529 }
530 return r;
531}
532
534
555bool wxJSONValue::IsInt() const {
556 wxJSONType type = GetType();
557 bool r = false;
558 // if the type is SHORT the value fits into an INT, too
559 if (type == wxJSONTYPE_SHORT) {
560 r = true;
561 } else if (type == wxJSONTYPE_LONG) {
562 // in case of LONG, check if the bit width is the same
563 if (INT_MAX == LONG_MAX) {
564 r = true;
565 }
566 }
567 return r;
568}
569
571
585 wxJSONType type = GetType();
586 bool r = false;
587 if (type == wxJSONTYPE_SHORT) {
588 r = true;
589 }
590 return r;
591}
592
594
617 wxJSONType type = GetType();
618 bool r = false;
619 if (type == wxJSONTYPE_USHORT) {
620 r = true;
621 } else if (type == wxJSONTYPE_ULONG) {
622 if (INT_MAX == LONG_MAX) {
623 r = true;
624 }
625 }
626 return r;
627}
628
630
644 wxJSONType type = GetType();
645 bool r = false;
646 if (type == wxJSONTYPE_USHORT) {
647 r = true;
648 }
649 return r;
650}
651
653
667 wxJSONType type = GetType();
668 bool r = false;
669 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_SHORT) {
670 r = true;
671 }
672 return r;
673}
674
677
691 wxJSONType type = GetType();
692 bool r = false;
693 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_USHORT) {
694 r = true;
695 }
696 return r;
697}
698
701 wxJSONType type = GetType();
702 bool r = false;
703 if (type == wxJSONTYPE_BOOL) {
704 r = true;
705 }
706 return r;
707}
708
711 wxJSONType type = GetType();
712 bool r = false;
713 if (type == wxJSONTYPE_DOUBLE) {
714 r = true;
715 }
716 return r;
717}
718
721 wxJSONType type = GetType();
722 bool r = false;
723 if (type == wxJSONTYPE_STRING) {
724 r = true;
725 }
726 return r;
727}
728
731
740 wxJSONType type = GetType();
741 bool r = false;
742 if (type == wxJSONTYPE_CSTRING) {
743 r = true;
744 }
745 return r;
746}
747
750 wxJSONType type = GetType();
751 bool r = false;
752 if (type == wxJSONTYPE_ARRAY) {
753 r = true;
754 }
755 return r;
756}
757
760 wxJSONType type = GetType();
761 bool r = false;
762 if (type == wxJSONTYPE_OBJECT) {
763 r = true;
764 }
765 return r;
766}
767
770 wxJSONType type = GetType();
771 bool r = false;
772 if (type == wxJSONTYPE_MEMORYBUFF) {
773 r = true;
774 }
775 return r;
776}
777
778// get the stored value; all these functions are 'const'
779
781
793 wxJSONRefData* data = GetRefData();
794 wxJSON_ASSERT(data);
795 int i = (int)data->m_value.VAL_INT;
796
797 wxJSON_ASSERT(IsInt());
798 return i;
799}
800
802
813 wxJSONRefData* data = GetRefData();
814 wxJSON_ASSERT(data);
815 wxJSON_ASSERT(data->m_type == wxJSONTYPE_BOOL);
816 return data->m_value.m_valBool;
817}
818
820
830double wxJSONValue::AsDouble() const {
831 wxJSONRefData* data = GetRefData();
832 wxJSON_ASSERT(data);
833 double d = data->m_value.m_valDouble;
834 wxJSON_ASSERT(IsDouble());
835 return d;
836}
837
839
875wxString wxJSONValue::AsString() const {
876 wxJSONRefData* data = GetRefData();
877 wxJSON_ASSERT(data);
878 wxString s;
879 int size = Size();
880 switch (data->m_type) {
881 case wxJSONTYPE_STRING:
882 s.assign(data->m_valString);
883 break;
884 case wxJSONTYPE_CSTRING:
885 s.assign(data->m_value.m_valCString);
886 break;
887 case wxJSONTYPE_INT:
888#if defined(wxJSON_64BIT_INT)
889 s.Printf("%" compatibleLongLongFmtSpec "i", data->m_value.m_valInt64);
890#else
891 s.Printf("%ld", data->m_value.m_valLong);
892#endif
893 break;
894 case wxJSONTYPE_UINT:
895#if defined(wxJSON_64BIT_INT)
896 s.Printf("%" compatibleLongLongFmtSpec "u", data->m_value.m_valUInt64);
897#else
898 s.Printf("%lu", data->m_value.m_valULong);
899#endif
900 break;
901 case wxJSONTYPE_DOUBLE:
902 s.Printf("%.10g", data->m_value.m_valDouble);
903 break;
904 case wxJSONTYPE_BOOL:
905 s.assign((data->m_value.m_valBool ? "true" : "false"));
906 break;
907 case wxJSONTYPE_NULL:
908 s.assign(_T( "null"));
909 break;
910 case wxJSONTYPE_INVALID:
911 s.assign(_T( "<invalid>"));
912 break;
913 case wxJSONTYPE_ARRAY:
914 s.Printf("[%d]", size);
915 break;
916 case wxJSONTYPE_OBJECT:
917 s.Printf("{%d}", size);
918 break;
919 case wxJSONTYPE_MEMORYBUFF:
920 s = MemoryBuffToString(*(data->m_memBuff), 5);
921 break;
922 default:
923 s.assign(_T( "wxJSONValue::AsString(): Unknown JSON type \'"));
924 s.append(TypeToString(data->m_type));
925 s.append(_T( "\'" ));
926 wxFAIL_MSG(s);
927 break;
928 }
929 return s;
930}
931
933
948const wxChar* wxJSONValue::AsCString() const {
949 const wxChar* s = nullptr;
950 wxJSONRefData* data = GetRefData();
951 wxJSON_ASSERT(data);
952 switch (data->m_type) {
953 case wxJSONTYPE_CSTRING:
954 s = data->m_value.m_valCString;
955 break;
956 case wxJSONTYPE_STRING:
957 s = data->m_valString.c_str();
958 break;
959 default:
960 break;
961 }
962 return s;
963}
964
966
977unsigned int wxJSONValue::AsUInt() const {
978 wxJSONRefData* data = GetRefData();
979 wxJSON_ASSERT(data);
980 unsigned int ui = (unsigned)data->m_value.VAL_UINT;
981
982 wxJSON_ASSERT(IsUInt());
983 return ui;
984}
985
987
998long int wxJSONValue::AsLong() const {
999 long int l;
1000 wxJSONRefData* data = GetRefData();
1001 wxJSON_ASSERT(data);
1002 l = (long)data->m_value.VAL_INT;
1003
1004 wxJSON_ASSERT(IsLong());
1005 return l;
1006}
1007
1009
1020unsigned long int wxJSONValue::AsULong() const {
1021 wxJSONRefData* data = GetRefData();
1022 wxJSON_ASSERT(data);
1023 unsigned long int ul = (unsigned long)data->m_value.VAL_UINT;
1024
1025 wxJSON_ASSERT(IsULong()); // expands only in debug builds
1026 return ul;
1027}
1028
1030
1041short int wxJSONValue::AsShort() const {
1042 short int i;
1043 wxJSONRefData* data = GetRefData();
1044 wxJSON_ASSERT(data);
1045 i = (short)data->m_value.VAL_INT;
1046
1047 wxJSON_ASSERT(IsShort());
1048 return i;
1049}
1050
1052
1063unsigned short wxJSONValue::AsUShort() const {
1064 unsigned short ui;
1065 wxJSONRefData* data = GetRefData();
1066 wxJSON_ASSERT(data);
1067 ui = (unsigned short)data->m_value.VAL_UINT;
1068
1069 wxJSON_ASSERT(IsUShort());
1070 return ui;
1071}
1072
1074
1099bool wxJSONValue::AsInt(int& i) const {
1100 bool r = false;
1101 if (IsInt()) {
1102 i = AsInt();
1103 r = true;
1104 }
1105 return r;
1106}
1107
1108bool wxJSONValue::AsUInt(unsigned int& ui) const {
1109 bool r = false;
1110 if (IsUInt()) {
1111 ui = AsUInt();
1112 r = true;
1113 }
1114 return r;
1115}
1116
1117bool wxJSONValue::AsShort(short int& s) const {
1118 bool r = false;
1119 if (IsShort()) {
1120 s = AsShort();
1121 r = true;
1122 }
1123 return r;
1124}
1125
1126bool wxJSONValue::AsUShort(unsigned short& us) const {
1127 bool r = false;
1128 if (IsUShort()) {
1129 us = AsUShort();
1130 r = true;
1131 }
1132 return r;
1133}
1134
1135bool wxJSONValue::AsLong(long int& l) const {
1136 bool r = false;
1137 if (IsLong()) {
1138 l = AsLong();
1139 r = true;
1140 }
1141 return r;
1142}
1143
1144bool wxJSONValue::AsULong(unsigned long& ul) const {
1145 bool r = false;
1146 if (IsULong()) {
1147 ul = AsULong();
1148 r = true;
1149 }
1150 return r;
1151}
1152
1153bool wxJSONValue::AsBool(bool& b) const {
1154 bool r = false;
1155 if (IsBool()) {
1156 b = AsBool();
1157 r = true;
1158 }
1159 return r;
1160}
1161
1162bool wxJSONValue::AsDouble(double& d) const {
1163 bool r = false;
1164 if (IsDouble()) {
1165 d = AsDouble();
1166 r = true;
1167 }
1168 return r;
1169}
1170
1172
1181bool wxJSONValue::AsString(wxString& str) const {
1182 bool r = IsString();
1183 if (r) {
1184 str = AsString();
1185 }
1186 return r;
1187}
1188
1189bool wxJSONValue::AsCString(wxChar* ch) const {
1190 bool r = IsCString();
1191 if (r) {
1192 ch = (wxChar*)AsCString();
1193 }
1194 return r;
1195}
1196
1198
1216wxMemoryBuffer wxJSONValue::AsMemoryBuff() const {
1217 wxJSONRefData* data = GetRefData();
1218 wxJSON_ASSERT(data);
1219 wxMemoryBuffer buff;
1220 if (data->m_memBuff) {
1221 buff = *(data->m_memBuff);
1222 }
1223
1224 wxJSON_ASSERT(IsMemoryBuff());
1225 return buff;
1226}
1227
1229
1247bool wxJSONValue::AsMemoryBuff(wxMemoryBuffer& buff) const {
1248 bool r = IsMemoryBuff();
1249 if (r) {
1250 buff = AsMemoryBuff();
1251 }
1252 return r;
1253}
1254
1255// internal use
1256
1258
1264const wxJSONInternalMap* wxJSONValue::AsMap() const {
1265 wxJSONRefData* data = GetRefData();
1266 wxJSON_ASSERT(data);
1267
1268 const wxJSONInternalMap* v = nullptr;
1269 if (data->m_type == wxJSONTYPE_OBJECT) {
1270 v = &(data->m_valMap);
1271 }
1272 return v;
1273}
1274
1276
1282const wxJSONInternalArray* wxJSONValue::AsArray() const {
1283 wxJSONRefData* data = GetRefData();
1284 wxJSON_ASSERT(data);
1285
1286 const wxJSONInternalArray* v = nullptr;
1287 if (data->m_type == wxJSONTYPE_ARRAY) {
1288 v = &(data->m_valArray);
1289 }
1290 return v;
1291}
1292
1293// retrieve the members and other info
1294
1296
1299bool wxJSONValue::HasMember(unsigned index) const {
1300 bool r = false;
1301 int size = Size();
1302 if (index < (unsigned)size) {
1303 r = true;
1304 }
1305 return r;
1306}
1307
1309
1312bool wxJSONValue::HasMember(const wxString& key) const {
1313 bool r = false;
1314 wxJSONRefData* data = GetRefData();
1315 wxJSON_ASSERT(data);
1316
1317 if (data && data->m_type == wxJSONTYPE_OBJECT) {
1318 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1319 if (it != data->m_valMap.end()) {
1320 r = true;
1321 }
1322 }
1323 return r;
1324}
1325
1327
1334 wxJSONRefData* data = GetRefData();
1335 wxJSON_ASSERT(data);
1336
1337 int size = -1;
1338 if (data->m_type == wxJSONTYPE_ARRAY) {
1339 size = (int)data->m_valArray.GetCount();
1340 }
1341 if (data->m_type == wxJSONTYPE_OBJECT) {
1342 size = (int)data->m_valMap.size();
1343 }
1344 return size;
1345}
1346
1348
1358wxArrayString wxJSONValue::GetMemberNames() const {
1359 wxJSONRefData* data = GetRefData();
1360 wxJSON_ASSERT(data);
1361 wxJSON_ASSERT(data->m_type == wxJSONTYPE_OBJECT);
1362
1363 wxArrayString arr;
1364 if (data->m_type == wxJSONTYPE_OBJECT) {
1365 wxJSONInternalMap::iterator it;
1366 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
1367 arr.Add(it->first);
1368 }
1369 }
1370 return arr;
1371}
1372
1373// appending items, resizing and deleting items
1374// NOTE: these functions are not 'const' so we have to call
1375// the COW() function before accessing data
1376
1378
1387 wxJSONRefData* data = COW();
1388 wxJSON_ASSERT(data);
1389 if (data->m_type != wxJSONTYPE_ARRAY) {
1390 // we have to change the type of the actual object to the array type
1391 SetType(wxJSONTYPE_ARRAY);
1392 }
1393 // we add the wxJSONValue object to the wxObjArray: note that the
1394 // array makes a copy of the JSON-value object by calling its
1395 // copy ctor thus using reference count
1396 data->m_valArray.Add(value);
1397 wxJSONValue& v = data->m_valArray.Last();
1398 return v;
1399}
1400
1403 wxJSONValue v(i);
1404 wxJSONValue& r = Append(v);
1405 return r;
1406}
1407
1409wxJSONValue& wxJSONValue::Append(short int i) {
1410 wxJSONValue v(i);
1411 wxJSONValue& r = Append(v);
1412 return r;
1413}
1414
1416wxJSONValue& wxJSONValue::Append(long int l) {
1417 wxJSONValue v(l);
1418 wxJSONValue& r = Append(v);
1419 return r;
1420}
1421
1424 wxJSONValue v(b);
1425 wxJSONValue& r = Append(v);
1426 return r;
1427}
1428
1430wxJSONValue& wxJSONValue::Append(unsigned int ui) {
1431 wxJSONValue v(ui);
1432 wxJSONValue& r = Append(v);
1433 return r;
1434}
1435
1437wxJSONValue& wxJSONValue::Append(unsigned short ui) {
1438 wxJSONValue v(ui);
1439 wxJSONValue& r = Append(v);
1440 return r;
1441}
1442
1444wxJSONValue& wxJSONValue::Append(unsigned long ul) {
1445 wxJSONValue v(ul);
1446 wxJSONValue& r = Append(v);
1447 return r;
1448}
1449
1452 wxJSONValue v(d);
1453 wxJSONValue& r = Append(v);
1454 return r;
1455}
1456
1458wxJSONValue& wxJSONValue::Append(const wxChar* str) {
1459 wxJSONValue v(str);
1460 wxJSONValue& r = Append(v);
1461 return r;
1462}
1463
1465wxJSONValue& wxJSONValue::Append(const wxString& str) {
1466 wxJSONValue v(str);
1467 wxJSONValue& r = Append(v);
1468 return r;
1469}
1470
1472wxJSONValue& wxJSONValue::Append(const wxMemoryBuffer& buff) {
1473 wxJSONValue v(buff);
1474 wxJSONValue& r = Append(v);
1475 return r;
1476}
1477
1479wxJSONValue& wxJSONValue::Append(const void* buff, size_t len) {
1480 wxJSONValue v(buff, len);
1481 wxJSONValue& r = Append(v);
1482 return r;
1483}
1484
1486
1494bool wxJSONValue::Cat(const wxString& str) {
1495 wxJSONRefData* data = GetRefData();
1496 wxJSON_ASSERT(data);
1497
1498 bool r = false;
1499 if (data->m_type == wxJSONTYPE_STRING) {
1500 wxJSONRefData* data = COW();
1501 wxJSON_ASSERT(data);
1502 data->m_valString.append(str);
1503 r = true;
1504 }
1505 return r;
1506}
1507
1509
1515bool wxJSONValue::Cat(const wxMemoryBuffer& buff) {
1516 wxJSONRefData* data = GetRefData();
1517 wxJSON_ASSERT(data);
1518
1519 bool r = false;
1520 if (data->m_type == wxJSONTYPE_MEMORYBUFF) {
1521 wxJSONRefData* data = COW();
1522 wxJSON_ASSERT(data);
1523 data->m_memBuff->AppendData(buff.GetData(), buff.GetDataLen());
1524 r = true;
1525 }
1526 return r;
1527}
1528
1530bool wxJSONValue::Cat(const wxChar* str) {
1531 wxJSONRefData* data = GetRefData();
1532 wxJSON_ASSERT(data);
1533
1534 bool r = false;
1535 if (data->m_type == wxJSONTYPE_STRING) {
1536 wxJSONRefData* data = COW();
1537 wxJSON_ASSERT(data);
1538 data->m_valString.append(str);
1539 r = true;
1540 }
1541 return r;
1542}
1543
1545
1552bool wxJSONValue::Remove(int index) {
1553 wxJSONRefData* data = COW();
1554 wxJSON_ASSERT(data);
1555
1556 bool r = false;
1557 if (data->m_type == wxJSONTYPE_ARRAY) {
1558 data->m_valArray.RemoveAt(index);
1559 r = true;
1560 }
1561 return r;
1562}
1563
1565bool wxJSONValue::Remove(const wxString& key) {
1566 wxJSONRefData* data = COW();
1567 wxJSON_ASSERT(data);
1568
1569 bool r = false;
1570 if (data->m_type == wxJSONTYPE_OBJECT) {
1571 wxJSONInternalMap::size_type count = data->m_valMap.erase(key);
1572 if (count > 0) {
1573 r = true;
1574 }
1575 }
1576 return r;
1577}
1578
1580
1586 UnRef();
1587 SetType(wxJSONTYPE_INVALID);
1588}
1589
1590// retrieve an item
1591
1593
1604 wxJSONRefData* data = COW();
1605 wxJSON_ASSERT(data);
1606
1607 if (data->m_type != wxJSONTYPE_ARRAY) {
1608 data = SetType(wxJSONTYPE_ARRAY);
1609 }
1610 int size = Size();
1611 wxJSON_ASSERT(size >= 0);
1612 // if the desired element does not yet exist, we create as many
1613 // elements as needed; the new values will be 'null' values
1614 if (index >= (unsigned)size) {
1615 wxJSONValue v(wxJSONTYPE_NULL);
1616 int missing = index - size + 1;
1617 data->m_valArray.Add(v, missing);
1618 }
1619 return data->m_valArray.Item(index);
1620}
1621
1623
1631wxJSONValue& wxJSONValue::Item(const wxString& key) {
1632 wxLogTrace(traceMask, "(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1633 key.c_str());
1634#if !wxCHECK_VERSION(2, 9, 0)
1635 wxLogTrace(traceMask, "(%s) actual object: %s", __PRETTY_FUNCTION__,
1636 GetInfo().c_str());
1637#endif
1638
1639 wxJSONRefData* data = COW();
1640 wxJSON_ASSERT(data);
1641
1642 if (data->m_type != wxJSONTYPE_OBJECT) {
1643 // deletes the contained value;
1644 data = SetType(wxJSONTYPE_OBJECT);
1645 return data->m_valMap[key];
1646 }
1647 wxLogTrace(traceMask, "(%s) searching key \'%s' in the actual object",
1648 __PRETTY_FUNCTION__, key.c_str());
1649 return data->m_valMap[key];
1650}
1651
1653
1658wxJSONValue wxJSONValue::ItemAt(unsigned index) const {
1659 wxJSONRefData* data = GetRefData();
1660 wxJSON_ASSERT(data);
1661
1662 wxJSONValue v(wxJSONTYPE_INVALID);
1663 if (data->m_type == wxJSONTYPE_ARRAY) {
1664 int size = Size();
1665 wxJSON_ASSERT(size >= 0);
1666 if (index < (unsigned)size) {
1667 v = data->m_valArray.Item(index);
1668 }
1669 }
1670 return v;
1671}
1672
1674
1679wxJSONValue wxJSONValue::ItemAt(const wxString& key) const {
1680 wxLogTrace(traceMask, "(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1681 key.c_str());
1682 wxLogTrace(traceMask, "(%s) actual object: %s", __PRETTY_FUNCTION__,
1683 GetInfo().c_str());
1684
1685 wxJSONRefData* data = GetRefData();
1686 wxJSON_ASSERT(data);
1687
1688 wxJSONValue v(wxJSONTYPE_INVALID);
1689 if (data->m_type == wxJSONTYPE_OBJECT) {
1690 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1691 if (it != data->m_valMap.end()) {
1692 v = it->second;
1693 }
1694 }
1695 return v;
1696}
1697
1699
1709 wxJSONValue& v = Item(index);
1710 return v;
1711}
1712
1714
1723 wxJSONValue& v = Item(key);
1724 return v;
1725}
1726
1727//
1728// assignment operators
1729// note that reference counting is only used if the original
1730// value is a wxJSONValue object
1731// in all other cases, the operator= function deletes the old
1732// content and assigns the new one
1733
1735
1749 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1750 data->m_value.VAL_INT = i;
1751 return *this;
1752}
1753
1756 wxJSONRefData* data = SetType(wxJSONTYPE_BOOL);
1757 data->m_value.m_valBool = b;
1758 return *this;
1759}
1760
1762wxJSONValue& wxJSONValue::operator=(unsigned int ui) {
1763 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1764 data->m_value.VAL_UINT = ui;
1765 return *this;
1766}
1767
1770 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1771 data->m_value.VAL_INT = l;
1772 return *this;
1773}
1774
1776wxJSONValue& wxJSONValue::operator=(unsigned long ul) {
1777 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1778 data->m_value.VAL_UINT = ul;
1779 return *this;
1780}
1781
1784 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1785 data->m_value.VAL_INT = i;
1786 return *this;
1787}
1788
1790wxJSONValue& wxJSONValue::operator=(unsigned short ui) {
1791 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1792 data->m_value.VAL_UINT = ui;
1793 return *this;
1794}
1795
1798 wxJSONRefData* data = SetType(wxJSONTYPE_DOUBLE);
1799 data->m_value.m_valDouble = d;
1800 return *this;
1801}
1802
1804wxJSONValue& wxJSONValue::operator=(const wxChar* str) {
1805 wxJSONRefData* data = SetType(wxJSONTYPE_CSTRING);
1806 data->m_value.m_valCString = str;
1807#if !defined(WXJSON_USE_CSTRING)
1808 data->m_type = wxJSONTYPE_STRING;
1809 data->m_valString.assign(str);
1810#endif
1811 return *this;
1812}
1813
1815wxJSONValue& wxJSONValue::operator=(const wxString& str) {
1816 wxJSONRefData* data = SetType(wxJSONTYPE_STRING);
1817 data->m_valString.assign(str);
1818 return *this;
1819}
1820
1822
1827wxJSONValue& wxJSONValue::operator=(const wxMemoryBuffer& buff) {
1828 wxJSONRefData* data = SetType(wxJSONTYPE_MEMORYBUFF);
1829 data->m_memBuff = new wxMemoryBuffer();
1830 const void* ptr = buff.GetData();
1831 size_t len = buff.GetDataLen();
1832 if (data->m_memBuff && len) {
1833 data->m_memBuff->AppendData(ptr, len);
1834 }
1835 return *this;
1836}
1837
1839
1847 Ref(other);
1848 return *this;
1849}
1850
1851// finding elements
1852
1854
1879wxJSONValue wxJSONValue::Get(const wxString& key,
1880 const wxJSONValue& defaultValue) const {
1881 // NOTE: this function does many wxJSONValue copies.
1882 // so implementing COW is a good thing
1883
1884 // this is the first copy (the default value)
1885 wxJSONValue v(defaultValue);
1886
1887 wxJSONRefData* data = GetRefData();
1888 wxJSON_ASSERT(data);
1889 if (data->m_type == wxJSONTYPE_OBJECT) {
1890 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1891 if (it != data->m_valMap.end()) {
1892 v = it->second;
1893 }
1894 }
1895 return v;
1896}
1897
1898// protected functions
1899
1901
1907wxJSONValue* wxJSONValue::Find(unsigned index) const {
1908 wxJSONRefData* data = GetRefData();
1909 wxJSON_ASSERT(data);
1910
1911 wxJSONValue* vp = nullptr;
1912
1913 if (data->m_type == wxJSONTYPE_ARRAY) {
1914 size_t size = data->m_valArray.GetCount();
1915 if (index < size) {
1916 vp = &(data->m_valArray.Item(index));
1917 }
1918 }
1919 return vp;
1920}
1921
1923
1929wxJSONValue* wxJSONValue::Find(const wxString& key) const {
1930 wxJSONRefData* data = GetRefData();
1931 wxJSON_ASSERT(data);
1932
1933 wxJSONValue* vp = nullptr;
1934
1935 if (data->m_type == wxJSONTYPE_OBJECT) {
1936 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1937 if (it != data->m_valMap.end()) {
1938 vp = &(it->second);
1939 }
1940 }
1941 return vp;
1942}
1943
1945
1955wxString wxJSONValue::TypeToString(wxJSONType type) {
1956 static const wxChar* str[] = {
1957 _T( "wxJSONTYPE_INVALID" ), // 0
1958 _T( "wxJSONTYPE_NULL" ), // 1
1959 _T( "wxJSONTYPE_INT" ), // 2
1960 _T( "wxJSONTYPE_UINT" ), // 3
1961 _T( "wxJSONTYPE_DOUBLE" ), // 4
1962 _T( "wxJSONTYPE_STRING" ), // 5
1963 _T( "wxJSONTYPE_CSTRING" ), // 6
1964 _T( "wxJSONTYPE_BOOL" ), // 7
1965 _T( "wxJSONTYPE_ARRAY" ), // 8
1966 _T( "wxJSONTYPE_OBJECT" ), // 9
1967 _T( "wxJSONTYPE_LONG" ), // 10
1968 _T( "wxJSONTYPE_INT64" ), // 11
1969 _T( "wxJSONTYPE_ULONG" ), // 12
1970 _T( "wxJSONTYPE_UINT64" ), // 13
1971 _T( "wxJSONTYPE_SHORT" ), // 14
1972 _T( "wxJSONTYPE_USHORT" ), // 15
1973 _T( "wxJSONTYPE_MEMORYBUFF" ), // 16
1974 };
1975
1976 wxString s;
1977 int idx = (int)type;
1978 if (idx >= 0 && idx < 17) {
1979 s = str[idx];
1980 }
1981 return s;
1982}
1983
1985
2004wxString wxJSONValue::Dump(bool deep, int indent) const {
2005 wxJSONRefData* data = GetRefData();
2006 wxJSON_ASSERT(data);
2007
2008 wxJSONType type = GetType();
2009
2010 wxString s;
2011 if (indent > 0) {
2012 s.append(indent, ' ');
2013 }
2014
2015 wxString s1;
2016 wxString s2;
2017#if defined(WXJSON_USE_VALUE_COUNTER)
2018 s1.Printf("Object: Progr=%d Type=%s Size=%d comments=%d\n", m_progr,
2019 TypeToString(type).c_str(), Size(), data->m_comments.GetCount());
2020 s2.Printf(" : RefData=%p Progr=%d Num shares=%d\n", data, data->m_progr,
2021 data->GetRefCount());
2022#else
2023 s1.Printf("Object: Type=%s Size=%d comments=%d\n", TypeToString(type).c_str(),
2024 Size(), data->m_comments.GetCount());
2025 s2.Printf(" : RefData=%p Num shares=%d\n", data, data->GetRefCount());
2026#endif
2027 s.append(s1);
2028 if (indent > 0) {
2029 s.append(indent, ' ');
2030 }
2031 s.append(s2);
2032
2033 wxString sub;
2034
2035 // if we have to do a deep dump, we call the Dump() function for
2036 // every sub-item
2037 if (deep) {
2038 indent += 3;
2039 const wxJSONInternalMap* map;
2040 int size;
2041 ;
2042 wxJSONInternalMap::const_iterator it;
2043 switch (type) {
2044 case wxJSONTYPE_OBJECT:
2045 map = AsMap();
2046 size = Size();
2047 for (it = map->begin(); it != map->end(); ++it) {
2048 const wxJSONValue& v = it->second;
2049 sub = v.Dump(true, indent);
2050 s.append(sub);
2051 }
2052 break;
2053 case wxJSONTYPE_ARRAY:
2054 size = Size();
2055 for (int i = 0; i < size; i++) {
2056 const wxJSONValue* v = Find(i);
2057 wxJSON_ASSERT(v);
2058 sub = v->Dump(true, indent);
2059 s.append(sub);
2060 }
2061 break;
2062 default:
2063 break;
2064 }
2065 }
2066 return s;
2067}
2068
2070
2075wxString wxJSONValue::GetInfo() const {
2076 wxJSONRefData* data = GetRefData();
2077 wxJSON_ASSERT(data);
2078
2079 wxString s;
2080#if defined(WXJSON_USE_VALUE_CONTER)
2081 s.Printf("Object: Progr=%d Type=%s Size=%d comments=%d\n", data->m_progr,
2082 wxJSONValue::TypeToString(data->m_type).c_str(), Size(),
2083 data->m_comments.GetCount());
2084#else
2085 s.Printf("Object: Type=%s Size=%d comments=%d\n",
2086 wxJSONValue::TypeToString(data->m_type).c_str(), Size(),
2087 data->m_comments.GetCount());
2088#endif
2089 if (data->m_type == wxJSONTYPE_OBJECT) {
2090 wxArrayString arr = GetMemberNames();
2091 for (unsigned int i = 0; i < arr.size(); i++) {
2092 s.append(" Member name: ");
2093 s.append(arr[i]);
2094 s.append("\n");
2095 }
2096 }
2097 return s;
2098}
2099
2101
2126bool wxJSONValue::IsSameAs(const wxJSONValue& other) const {
2127 // this is a recursive function: it calls itself
2128 // for every 'value' object in an array or map
2129 bool r = false;
2130
2131 // some variables used in the switch statement
2132 int size;
2133 wxJSONInternalMap::const_iterator it;
2134
2135 // get the referenced data for the two objects
2136 wxJSONRefData* data = GetRefData();
2137 wxJSONRefData* otherData = other.GetRefData();
2138
2139 if (data == otherData) {
2140 wxLogTrace(compareTraceMask,
2141 "(%s) objects share the same referenced data - r=TRUE",
2142 __PRETTY_FUNCTION__);
2143 return true;
2144 }
2145
2146 // if the type does not match the function compares the values if
2147 // they are of compatible types such as INT, UINT and DOUBLE
2148 if (data->m_type != otherData->m_type) {
2149 // if the types are not compatible, returns false
2150 // otherwise compares the compatible types: INT, UINT and DOUBLE
2151 double val;
2152 switch (data->m_type) {
2153 case wxJSONTYPE_INT:
2154 if (otherData->m_type == wxJSONTYPE_UINT) {
2155 // compare the bits and returns true if value is between 0 and
2156 // LLONG_MAX
2157 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2158 (data->m_value.VAL_UINT == otherData->m_value.VAL_UINT)) {
2159 r = true;
2160 }
2161 } else if (otherData->m_type == wxJSONTYPE_DOUBLE) {
2162 val = data->m_value.VAL_INT;
2163 if (val == otherData->m_value.m_valDouble) {
2164 r = true;
2165 }
2166 } else {
2167 r = false;
2168 }
2169 break;
2170 case wxJSONTYPE_UINT:
2171 if (otherData->m_type == wxJSONTYPE_INT) {
2172 // compare the bits and returns true if value is between 0 and
2173 // LLONG_MAX
2174 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2175 (data->m_value.VAL_UINT == otherData->m_value.VAL_UINT)) {
2176 r = true;
2177 }
2178 } else if (otherData->m_type == wxJSONTYPE_DOUBLE) {
2179 val = data->m_value.VAL_UINT;
2180 if (val == otherData->m_value.m_valDouble) {
2181 r = true;
2182 }
2183 } else {
2184 r = false;
2185 }
2186 break;
2187 case wxJSONTYPE_DOUBLE:
2188 if (otherData->m_type == wxJSONTYPE_INT) {
2189 val = otherData->m_value.VAL_INT;
2190 if (val == data->m_value.m_valDouble) {
2191 r = true;
2192 }
2193 } else if (otherData->m_type == wxJSONTYPE_UINT) {
2194 val = otherData->m_value.VAL_UINT;
2195 if (val == data->m_value.m_valDouble) {
2196 r = true;
2197 }
2198 } else {
2199 r = false;
2200 }
2201 break;
2202 default:
2203 r = false;
2204 break;
2205 }
2206 return r;
2207 }
2208
2209 // the two objects have the same 'm_type'
2210
2211 // for comparing wxJSONTYPE_CSTRING we use two temporary wxString
2212 // objects: this is to avoid using strcmp() and wcscmp() which
2213 // may not be available on all platforms
2214 wxString s1, s2;
2215 r = true;
2216 int r1;
2217
2218 switch (data->m_type) {
2219 case wxJSONTYPE_INVALID:
2220 case wxJSONTYPE_NULL:
2221 // there is no need to compare the values
2222 break;
2223 case wxJSONTYPE_INT:
2224 if (data->m_value.VAL_INT != otherData->m_value.VAL_INT) {
2225 r = false;
2226 }
2227 break;
2228 case wxJSONTYPE_UINT:
2229 if (data->m_value.VAL_UINT != otherData->m_value.VAL_UINT) {
2230 r = false;
2231 }
2232 break;
2233 case wxJSONTYPE_DOUBLE:
2234 if (data->m_value.m_valDouble != otherData->m_value.m_valDouble) {
2235 r = false;
2236 }
2237 break;
2238 case wxJSONTYPE_CSTRING:
2239 s1 = wxString(data->m_value.m_valCString);
2240 s2 = wxString(otherData->m_value.m_valCString);
2241 if (s1 != s2) {
2242 r = false;
2243 }
2244 break;
2245 case wxJSONTYPE_BOOL:
2246 if (data->m_value.m_valBool != otherData->m_value.m_valBool) {
2247 r = false;
2248 }
2249 break;
2250 case wxJSONTYPE_STRING:
2251 if (data->m_valString != otherData->m_valString) {
2252 r = false;
2253 }
2254 break;
2255 case wxJSONTYPE_MEMORYBUFF:
2256 // we cannot simply use the operator ==; we need a deep comparison
2257 r1 = CompareMemoryBuff(*(data->m_memBuff), *(otherData->m_memBuff));
2258 if (r1 != 0) {
2259 r = false;
2260 }
2261 break;
2262 case wxJSONTYPE_ARRAY:
2263 size = Size();
2264 wxLogTrace(compareTraceMask, "(%s) Comparing an array object - size=%d",
2265 __PRETTY_FUNCTION__, size);
2266
2267 if (size != other.Size()) {
2268 wxLogTrace(compareTraceMask, "(%s) Sizes does not match",
2269 __PRETTY_FUNCTION__);
2270 return false;
2271 }
2272 // compares every element in this object with the element of
2273 // the same index in the 'other' object
2274 for (int i = 0; i < size; i++) {
2275 wxLogTrace(compareTraceMask, "(%s) Comparing array element=%d",
2276 __PRETTY_FUNCTION__, i);
2277 wxJSONValue v1 = ItemAt(i);
2278 wxJSONValue v2 = other.ItemAt(i);
2279
2280 if (!v1.IsSameAs(v2)) {
2281 return false;
2282 }
2283 }
2284 break;
2285 case wxJSONTYPE_OBJECT:
2286 size = Size();
2287 wxLogTrace(compareTraceMask, "(%s) Comparing a map obejct - size=%d",
2288 __PRETTY_FUNCTION__, size);
2289
2290 if (size != other.Size()) {
2291 wxLogTrace(compareTraceMask,
2292 "(%s) Comparison failed - sizes does not match",
2293 __PRETTY_FUNCTION__);
2294 return false;
2295 }
2296 // for every key calls itself on the value found in
2297 // the other object. if 'key' does no exist, returns FALSE
2298 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
2299 wxString key = it->first;
2300 wxLogTrace(compareTraceMask, "(%s) Comparing map object - key=%s",
2301 __PRETTY_FUNCTION__, key.c_str());
2302 wxJSONValue otherVal = other.ItemAt(key);
2303 bool isSame = it->second.IsSameAs(otherVal);
2304 if (!isSame) {
2305 wxLogTrace(compareTraceMask,
2306 "(%s) Comparison failed for the last object",
2307 __PRETTY_FUNCTION__);
2308 return false;
2309 }
2310 }
2311 break;
2312 default:
2313 // should never happen
2314 wxFAIL_MSG("wxJSONValue::IsSameAs() unexpected wxJSONType");
2315 break;
2316 }
2317 return r;
2318}
2319
2321
2345int wxJSONValue::AddComment(const wxString& str, int position) {
2346 wxJSONRefData* data = COW();
2347 wxJSON_ASSERT(data);
2348
2349 wxLogTrace(traceMask, "(%s) comment=%s", __PRETTY_FUNCTION__, str.c_str());
2350 int r = -1;
2351 int len = str.length();
2352 if (len < 2) {
2353 wxLogTrace(traceMask, " error: len < 2");
2354 return -1;
2355 }
2356 if (str[0] != '/') {
2357 wxLogTrace(traceMask, " error: does not start with\'/\'");
2358 return -1;
2359 }
2360 if (str[1] == '/') { // a C++ comment: check that it ends with '\n'
2361 wxLogTrace(traceMask, _T(" C++ comment" ));
2362 if (str.GetChar(len - 1) != '\n') {
2363 wxString temp(str);
2364 temp.append(1, '\n');
2365 data->m_comments.Add(temp);
2366 wxLogTrace(traceMask, " C++ comment: LF added");
2367 } else {
2368 data->m_comments.Add(str);
2369 }
2370 r = data->m_comments.size();
2371 } else if (str[1] ==
2372 '*') { // a C-style comment: check that it ends with '*/'
2373 wxLogTrace(traceMask, " C-style comment");
2374 int lastPos = len - 1;
2375 wxChar ch = str.GetChar(lastPos);
2376 // skip leading whitespaces
2377 while (ch == ' ' || ch == '\n' || ch == '\t') {
2378 --lastPos;
2379 ch = str.GetChar(lastPos);
2380 }
2381 if (str.GetChar(lastPos) == '/' && str.GetChar(lastPos - 1) == '*') {
2382 data->m_comments.Add(str);
2383 r = data->m_comments.size();
2384 }
2385 } else {
2386 wxLogTrace(traceMask, " error: is not a valid comment string");
2387 r = -1;
2388 }
2389 // if the comment was stored, store the position
2390 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2391 data->m_commentPos = position;
2392 }
2393 return r;
2394}
2395
2397
2403int wxJSONValue::AddComment(const wxArrayString& comments, int position) {
2404 int siz = comments.GetCount();
2405 int r = 0;
2406 for (int i = 0; i < siz; i++) {
2407 int r2 = AddComment(comments[i], position);
2408 if (r2 >= 0) {
2409 ++r;
2410 }
2411 }
2412 return r;
2413}
2414
2416
2422wxString wxJSONValue::GetComment(int idx) const {
2423 wxJSONRefData* data = GetRefData();
2424 wxJSON_ASSERT(data);
2425
2426 wxString s;
2427 int size = data->m_comments.GetCount();
2428 if (idx < 0) {
2429 for (int i = 0; i < size; i++) {
2430 s.append(data->m_comments[i]);
2431 }
2432 } else if (idx < size) {
2433 s = data->m_comments[idx];
2434 }
2435 return s;
2436}
2437
2440 wxJSONRefData* data = GetRefData();
2441 wxJSON_ASSERT(data);
2442
2443 int d = data->m_comments.GetCount();
2444 wxLogTrace(traceMask, "(%s) comment count=%d", __PRETTY_FUNCTION__, d);
2445 return d;
2446}
2447
2450 wxJSONRefData* data = GetRefData();
2451 wxJSON_ASSERT(data);
2452 return data->m_commentPos;
2453}
2454
2456const wxArrayString& wxJSONValue::GetCommentArray() const {
2457 wxJSONRefData* data = GetRefData();
2458 wxJSON_ASSERT(data);
2459
2460 return data->m_comments;
2461}
2462
2465 wxJSONRefData* data = COW();
2466 wxJSON_ASSERT(data);
2467
2468 data->m_comments.clear();
2469}
2470
2472
2534 wxJSONRefData* data = GetRefData();
2535 wxJSONType oldType = GetType();
2536
2537 // check that type is within the allowed range
2538 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2539 (type <= wxJSONTYPE_MEMORYBUFF));
2540 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2541 type = wxJSONTYPE_INVALID;
2542 }
2543
2544 // the function unshares the referenced data but does not delete the
2545 // structure. This is because the wxJSON reader stores comments
2546 // that apear before the value in a temporary value of type wxJSONTYPE_INVALID
2547 // which is invalid and, next, it stores the JSON value in the same
2548 // wxJSONValue object.
2549 // If we would delete the structure using 'Unref()' we loose the
2550 // comments
2551 data = COW();
2552
2553 // do nothing if the actual type is the same as 'type'
2554 if (type == oldType) {
2555 return data;
2556 }
2557
2558 // change the type of the referened structure
2559 // NOTE: integer types are always stored as the generic integer types
2560 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2561 type == wxJSONTYPE_SHORT) {
2562 type = wxJSONTYPE_INT;
2563 }
2564 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2565 type == wxJSONTYPE_USHORT) {
2566 type = wxJSONTYPE_UINT;
2567 }
2568
2569 wxJSON_ASSERT(data);
2570 data->m_type = type;
2571
2572 // clears complex objects of the old type
2573 switch (oldType) {
2574 case wxJSONTYPE_STRING:
2575 data->m_valString.clear();
2576 break;
2577 case wxJSONTYPE_ARRAY:
2578 data->m_valArray.Clear();
2579 break;
2580 case wxJSONTYPE_OBJECT:
2581 data->m_valMap.clear();
2582 break;
2583 case wxJSONTYPE_MEMORYBUFF:
2584 // we first have to delete the actual memory buffer, if any
2585 if (data->m_memBuff) {
2586 delete data->m_memBuff;
2587 data->m_memBuff = 0;
2588 }
2589 break;
2590 default:
2591 // there is not need to clear primitive types
2592 break;
2593 }
2594
2595 // if the WXJSON_USE_CSTRING macro is not defined, the class forces
2596 // C-string to be stored as wxString objects
2597#if !defined(WXJSON_USE_CSTRING)
2598 if (data->m_type == wxJSONTYPE_CSTRING) {
2599 data->m_type = wxJSONTYPE_STRING;
2600 }
2601#endif
2602 return data;
2603}
2604
2606
2616 // return ZERO if there is not a referenced data structure
2617 int n = 0;
2618 wxJSONRefData* data = GetRefData();
2619 if (data != 0) {
2620 n = data->m_lineNo;
2621 }
2622 return n;
2623}
2624
2627 wxJSONRefData* data = COW();
2628 wxJSON_ASSERT(data);
2629 data->m_lineNo = num;
2630}
2631
2634
2636void wxJSONValue::Ref(const wxJSONValue& clone) {
2637 // nothing to be done
2638 if (m_refData == clone.m_refData) return;
2639
2640 // delete reference to old data
2641 UnRef();
2642
2643 // reference new data
2644 if (clone.m_refData) {
2645 m_refData = clone.m_refData;
2646 ++(m_refData->m_refCount);
2647 }
2648}
2649
2651
2657 if (m_refData) {
2658 wxASSERT_MSG(m_refData->m_refCount > 0, "invalid ref data count");
2659
2660 if (--m_refData->m_refCount == 0) {
2661 delete m_refData;
2662 m_refData = nullptr;
2663 }
2664 }
2665}
2666
2669
2671
2676 UnRef();
2677 wxJSONRefData* data = CloneRefData(other.m_refData);
2678 SetRefData(data);
2679}
2680
2683 wxJSONRefData* data = m_refData;
2684 return data;
2685}
2686
2688
2697 wxJSON_ASSERT(otherData);
2698
2699 // make a static cast to pointer-to-wxJSONRefData
2700 const wxJSONRefData* other = otherData;
2701
2702 // allocate a new instance of wxJSONRefData using the default
2703 // ctor; we cannot use the copy ctor of a wxJSONRefData
2704 wxJSONRefData* data = new wxJSONRefData();
2705
2706 // copy the referenced data structure's data members
2707 data->m_type = other->m_type;
2708 data->m_value = other->m_value;
2709 data->m_commentPos = other->m_commentPos;
2710 data->m_comments = other->m_comments;
2711 data->m_lineNo = other->m_lineNo;
2712 data->m_valString = other->m_valString;
2713 data->m_valArray = other->m_valArray;
2714 data->m_valMap = other->m_valMap;
2715
2716 // if the data contains a wxMemoryBuffer object, then we have
2717 // to make a deep copy of the buffer by allocating a new one because
2718 // wxMemoryBuffer is not a copy-on-write structure
2719 if (other->m_memBuff) {
2720 data->m_memBuff = new wxMemoryBuffer();
2721 const void* ptr = data->m_memBuff->GetData();
2722 size_t len = data->m_memBuff->GetDataLen();
2723 if (data->m_memBuff && len) {
2724 data->m_memBuff->AppendData(ptr, len);
2725 }
2726 }
2727
2728 wxLogTrace(cowTraceMask, "(%s) CloneRefData() PROGR: other=%d data=%d",
2729 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2730
2731 return data;
2732}
2733
2735
2742 wxJSONRefData* data = new wxJSONRefData();
2743 data->m_type = wxJSONTYPE_INVALID;
2744 return data;
2745}
2746
2748
2755 wxJSONRefData* data = GetRefData();
2756 wxLogTrace(cowTraceMask, "(%s) COW() START data=%p data->m_count=%d",
2757 __PRETTY_FUNCTION__, data, data->GetRefCount());
2758 UnShare();
2759 data = GetRefData();
2760 wxLogTrace(cowTraceMask, "(%s) COW() END data=%p data->m_count=%d",
2761 __PRETTY_FUNCTION__, data, data->GetRefCount());
2762 return GetRefData();
2763}
2764
2767 if (!m_refData) {
2769 } else if (m_refData->GetRefCount() > 1) {
2770 // note that ref is not going to be destroyed in this case
2771 const wxJSONRefData* ref = m_refData;
2772 UnRef();
2773
2774 // ... so we can still access it
2775 m_refData = CloneRefData(ref);
2776 }
2777 // else: ref count is 1, we are exclusive owners of m_refData anyhow
2778
2779 wxASSERT_MSG(m_refData && m_refData->GetRefCount() == 1,
2780 "wxObject::AllocExclusive() failed.");
2781}
2782
2784/*/
2785 The fucntion returns a string representation of the data contained in the
2786 memory buffer object \c buff.
2787 The string is conposed of two hexadecimal digits for every byte contained
2788 in the memory buffer; bytes are separated by a space character.
2789 The string starts with the actual lenght of the data enclosed in parenthesis.
2790 The string will contain \c len bytes if \c len is less than the length
2791 of the actual data in \c buff.
2792 Note that the (len) printed in the output referes to the length of the buffer
2793 which may be greater than the length that has to be printed.
2794
2795 \b Example:
2796 This is an example of printing a memory buffer object that contains 10 bytes:
2797 \code
2798 0x80974653 (10) 00 01 02 03 04 05 06 07 08 09
2799 \endcode
2800*/
2801wxString wxJSONValue::MemoryBuffToString(const wxMemoryBuffer& buff,
2802 size_t len) {
2803 size_t buffLen = buff.GetDataLen();
2804 void* ptr = buff.GetData();
2805 wxString s = MemoryBuffToString(ptr, MIN(buffLen, len), buffLen);
2806 return s;
2807}
2808
2810/*/
2811 The function returns a string representation of the data contained in the
2812 binary memory buffer pointed to by \c buff for \c len bytes.
2813 The string is composed of two hexadecimal digits for every byte contained
2814 in the memory buffer; bytes are separated by a space character.
2815 The string starts with pointer to binary data followed by the lenght of the
2816 data enclosed in parenthesis.
2817
2818 \b Example:
2819 This is an example of printing ten bytes from a memory buffer:
2820 \code
2821 0x80974653 (10) 00 01 02 03 04 05 06 07 08 09
2822 \endcode
2823
2824 @param buff the pointer to the memory buffer data
2825 @len the length of the data that has to be printed
2826 @actualLen the real lenght of the memory buffer that has to be printed
2827 just afetr the pointer; may be greater than \c len. If this parameter
2828 is -1 then it is equal to \c len
2829*/
2830wxString wxJSONValue::MemoryBuffToString(const void* buff, size_t len,
2831 size_t actualLen) {
2832 wxString s;
2833 size_t buffLen = actualLen;
2834 if (buffLen == (size_t)-1) {
2835 buffLen = len;
2836 }
2837 s.Printf("%p (%u) ", buff, buffLen);
2838 unsigned char* ptr = (unsigned char*)buff;
2839 for (unsigned int i = 0; i < len; i++) {
2840 unsigned char c = *ptr;
2841 ++ptr;
2842 // now convert the character
2843 char c1 = c / 16;
2844 char c2 = c % 16;
2845 c1 += '0';
2846 c2 += '0';
2847 if (c1 > '9') {
2848 c1 += 7;
2849 }
2850 if (c2 > '9') {
2851 c2 += 7;
2852 }
2853 s.Append(c1, 1);
2854 s.Append(c2, 1);
2855 s.Append(' ', 1); // a space separates the bytes
2856 }
2857 return s;
2858}
2859
2861
2885int wxJSONValue::CompareMemoryBuff(const wxMemoryBuffer& buff1,
2886 const wxMemoryBuffer& buff2) {
2887 int r;
2888 size_t buff1Len = buff1.GetDataLen();
2889 size_t buff2Len = buff2.GetDataLen();
2890 if (buff1Len > buff2Len) {
2891 r = 1;
2892 } else if (buff1Len < buff2Len) {
2893 r = -1;
2894 } else {
2895 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2896 }
2897 return r;
2898}
2899
2901
2912int wxJSONValue::CompareMemoryBuff(const wxMemoryBuffer& buff1,
2913 const void* buff2) {
2914 int r;
2915 size_t buff1Len = buff1.GetDataLen();
2916 r = memcmp(buff1.GetData(), buff2, buff1Len);
2917 return r;
2918}
2919
2921
2941wxMemoryBuffer wxJSONValue::ArrayToMemoryBuff(const wxJSONValue& value) {
2942 wxMemoryBuffer buff;
2943 if (value.IsArray()) {
2944 int len = value.Size();
2945 for (int i = 0; i < len; i++) {
2946 short int byte;
2947 unsigned char c;
2948 // we do not use opertaor [] because it is not const
2949 // bool r = value[i].AsShort( byte );
2950 bool r = value.ItemAt(i).AsShort(byte);
2951 if (r && (byte >= 0 && byte <= 255)) {
2952 c = (unsigned char)byte;
2953 buff.AppendByte(c);
2954 }
2955 }
2956 }
2957 return buff;
2958}
2959
2960/*************************************************************************
2961
2962 64-bits integer support
2963
2964*************************************************************************/
2965
2966#if defined(wxJSON_64BIT_INT)
2967
2969wxJSONValue::wxJSONValue(wxInt64 i) {
2970 m_refData = nullptr;
2971 wxJSONRefData* data = Init(wxJSONTYPE_INT);
2972 wxJSON_ASSERT(data);
2973 if (data != 0) {
2974 data->m_value.VAL_INT = i;
2975 }
2976}
2977
2979wxJSONValue::wxJSONValue(wxUint64 ui) {
2980 m_refData = nullptr;
2981 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
2982 wxJSON_ASSERT(data);
2983 if (data != 0) {
2984 data->m_value.VAL_UINT = ui;
2985 }
2986}
2987
2989
2997bool wxJSONValue::IsInt32() const {
2998 bool r = IsLong();
2999 return r;
3000}
3001
3003
3011bool wxJSONValue::IsUInt32() const {
3012 bool r = IsULong();
3013 return r;
3014}
3015
3017
3026bool wxJSONValue::IsInt64() const {
3027 wxJSONRefData* data = GetRefData();
3028 wxJSON_ASSERT(data);
3029 bool r = false;
3030 if (data->m_type == wxJSONTYPE_INT) {
3031 r = true;
3032 }
3033 return r;
3034}
3035
3037
3046bool wxJSONValue::IsUInt64() const {
3047 wxJSONRefData* data = GetRefData();
3048 wxJSON_ASSERT(data);
3049 bool r = false;
3050 if (data->m_type == wxJSONTYPE_UINT) {
3051 r = true;
3052 }
3053 return r;
3054}
3055
3057
3068wxInt32 wxJSONValue::AsInt32() const {
3069 wxInt32 i;
3070 i = (wxInt32)AsLong();
3071 return i;
3072}
3073
3075
3086wxUint32 wxJSONValue::AsUInt32() const {
3087 wxUint32 ui;
3088 ui = (wxUint32)AsULong();
3089 return ui;
3090}
3091
3093
3106wxInt64 wxJSONValue::AsInt64() const {
3107 wxJSONRefData* data = GetRefData();
3108 wxJSON_ASSERT(data);
3109 wxInt64 i64 = data->m_value.m_valInt64;
3110
3111 wxJSON_ASSERT(IsInt64()); // exapnds only in debug builds
3112 return i64;
3113}
3114
3116
3129wxUint64 wxJSONValue::AsUInt64() const {
3130 wxJSONRefData* data = GetRefData();
3131 wxJSON_ASSERT(data);
3132 wxUint64 ui64 = data->m_value.m_valUInt64;
3133
3134 wxJSON_ASSERT(IsUInt64()); // exapnds only in debug builds
3135 return ui64;
3136}
3137
3138bool wxJSONValue::AsInt32(wxInt32& i32) const {
3139 bool r = IsInt32();
3140 if (r) {
3141 i32 = AsInt32();
3142 }
3143 return r;
3144}
3145
3146bool wxJSONValue::AsUInt32(wxUint32& ui32) const {
3147 bool r = IsUInt32();
3148 if (r) {
3149 ui32 = AsUInt32();
3150 }
3151 return r;
3152}
3153
3154bool wxJSONValue::AsInt64(wxInt64& i64) const {
3155 bool r = IsInt64();
3156 if (r) {
3157 i64 = AsInt64();
3158 }
3159 return r;
3160}
3161
3162bool wxJSONValue::AsUInt64(wxUint64& ui64) const {
3163 bool r = IsUInt64();
3164 if (r) {
3165 ui64 = AsUInt64();
3166 }
3167 return r;
3168}
3169
3171wxJSONValue& wxJSONValue::Append(wxInt64 i) {
3172 wxJSONValue v(i);
3173 wxJSONValue& r = Append(v);
3174 return r;
3175}
3176
3178wxJSONValue& wxJSONValue::Append(wxUint64 ui) {
3179 wxJSONValue v(ui);
3180 wxJSONValue& r = Append(v);
3181 return r;
3182}
3183
3186 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
3187 data->m_value.VAL_INT = i;
3188 return *this;
3189}
3190
3192wxJSONValue& wxJSONValue::operator=(wxUint64 ui) {
3193 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
3194 data->m_value.VAL_UINT = ui;
3195 return *this;
3196}
3197
3198#endif // defined( wxJSON_64BIT_INT )
3199
3200/*
3201{
3202}
3203*/
The reference counted JSON value data (internal use).
Definition jsonval.h:345
wxMemoryBuffer * m_memBuff
The pointer to the memory buffer object.
Definition jsonval.h:410
wxJSONInternalMap m_valMap
The JSON object value.
Definition jsonval.h:380
int m_commentPos
The position of the comment line(s), if any.
Definition jsonval.h:389
int m_refCount
the references count
Definition jsonval.h:359
wxJSONInternalArray m_valArray
The JSON array value.
Definition jsonval.h:377
wxJSONType m_type
The actual type of the value held by this object.
Definition jsonval.h:362
int m_lineNo
The line number when this value was read.
Definition jsonval.h:402
wxJSONRefData()
Constructor.
Definition jsonval.cpp:75
wxString m_valString
The JSON string value.
Definition jsonval.h:374
wxJSONValueHolder m_value
The JSON value held by this object.
Definition jsonval.h:371
wxArrayString m_comments
The array of comment lines; may be empty.
Definition jsonval.h:392
The JSON value class implementation.
Definition jsonval.h:79
bool IsSameAs(const wxJSONValue &other) const
The comparison function.
Definition jsonval.cpp:2126
void Ref(const wxJSONValue &clone)
Increments the referenced data counter.
Definition jsonval.cpp:2636
wxArrayString GetMemberNames() const
Return the array of keys of this JSON object.
Definition jsonval.cpp:1358
bool IsArray() const
Return TRUE if the type of the value stored is an array type.
Definition jsonval.cpp:749
bool IsCString() const
Return TRUE if the type of the value stored is a pointer to a static C string.
Definition jsonval.cpp:739
void UnShare()
Makes an exclusive copy of shared data.
Definition jsonval.cpp:2668
bool Remove(int index)
Remove the item at the specified index or key.
Definition jsonval.cpp:1552
int AddComment(const wxString &str, int position=wxJSONVALUE_COMMENT_DEFAULT)
Add a comment to this JSON value object.
Definition jsonval.cpp:2345
virtual wxJSONRefData * CloneRefData(const wxJSONRefData *data) const
Make a copy of the referenced data.
Definition jsonval.cpp:2696
bool IsUInt() const
Return TRUE if the type of the value stored is a unsigned int.
Definition jsonval.cpp:616
wxString Dump(bool deep=false, int mode=0) const
Returns informations about the object.
Definition jsonval.cpp:2004
wxJSONRefData * Init(wxJSONType type)
Initialize the JSON value class.
Definition jsonval.cpp:199
long int AsLong() const
Returns the value as a long integer.
Definition jsonval.cpp:998
bool IsLong() const
Return TRUE if the stored value is an integer which fits in a long int.
Definition jsonval.cpp:666
int Size() const
Return the size of the array or map stored in this value.
Definition jsonval.cpp:1333
int GetCommentCount() const
Return the number of comment strings.
Definition jsonval.cpp:2439
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
Definition jsonval.cpp:1299
bool IsDouble() const
Return TRUE if the type of the value stored is a double.
Definition jsonval.cpp:710
bool IsInt() const
Return TRUE if the type of the value stored is integer.
Definition jsonval.cpp:555
static wxString MemoryBuffToString(const wxMemoryBuffer &buff, size_t len=-1)
Convert memory buffer object to a string representation.
Definition jsonval.cpp:2801
bool IsShort() const
Return TRUE if the type of the value stored is 16-bit integer.
Definition jsonval.cpp:584
wxJSONValue Get(const wxString &key, const wxJSONValue &defaultValue) const
Return a value or a default value.
Definition jsonval.cpp:1879
double AsDouble() const
Return the stored value as a double.
Definition jsonval.cpp:830
virtual wxJSONRefData * CreateRefData() const
Create a new data structure.
Definition jsonval.cpp:2741
wxJSONType GetType() const
Return the type of the value stored in the object.
Definition jsonval.cpp:461
void UnRef()
Unreferences the shared data.
Definition jsonval.cpp:2656
wxJSONValue * Find(unsigned index) const
Find an element.
Definition jsonval.cpp:1907
void DeepCopy(const wxJSONValue &other)
Do a deep copy of the other object.
Definition jsonval.cpp:2675
static wxMemoryBuffer ArrayToMemoryBuff(const wxJSONValue &value)
Converts an array of INTs to a memory buffer.
Definition jsonval.cpp:2941
wxJSONValue ItemAt(unsigned index) const
Return the item at the specified index.
Definition jsonval.cpp:1658
wxJSONRefData * COW()
Make sure the referenced data is unique.
Definition jsonval.cpp:2754
wxString GetComment(int idx=-1) const
Return a comment string.
Definition jsonval.cpp:2422
void SetRefData(wxJSONRefData *data)
Set the pointer to the referenced data.
Definition jsonval.cpp:2633
bool IsString() const
Return TRUE if the type of the value stored is a wxString object.
Definition jsonval.cpp:720
void ClearComments()
Clear all comment strings.
Definition jsonval.cpp:2464
bool IsUShort() const
Return TRUE if the type of the value stored is a unsigned short.
Definition jsonval.cpp:643
const wxJSONInternalMap * AsMap() const
Return the stored value as a map object.
Definition jsonval.cpp:1264
const wxChar * AsCString() const
Return the stored value as a pointer to a static C string.
Definition jsonval.cpp:948
wxJSONValue & operator[](unsigned index)
Return the item at the specified index.
Definition jsonval.cpp:1708
static int CompareMemoryBuff(const wxMemoryBuffer &buff1, const wxMemoryBuffer &buff2)
Compares two memory buffer objects.
Definition jsonval.cpp:2885
wxJSONValue & Append(const wxJSONValue &value)
Append the specified value in the array.
Definition jsonval.cpp:1386
bool IsBool() const
Return TRUE if the type of the value stored is a boolean.
Definition jsonval.cpp:700
unsigned int AsUInt() const
Return the stored value as a unsigned int.
Definition jsonval.cpp:977
unsigned short AsUShort() const
Returns the value as a unsigned short integer.
Definition jsonval.cpp:1063
void AllocExclusive()
Makes a private copy of the referenced data.
Definition jsonval.cpp:2766
wxJSONValue()
Constructors.
Definition jsonval.cpp:186
bool IsULong() const
Return TRUE if the stored value is an integer which fits in a unsigned long int.
Definition jsonval.cpp:690
wxString AsString() const
Return the stored value as a wxWidget's string.
Definition jsonval.cpp:875
void Clear()
Clear the object value.
Definition jsonval.cpp:1585
int GetLineNo() const
Return the line number of this JSON value object.
Definition jsonval.cpp:2615
bool IsValid() const
Return TRUE if the value stored is valid.
Definition jsonval.cpp:524
bool IsMemoryBuff() const
Return TRUE if the type of this value is a binary memory buffer.
Definition jsonval.cpp:769
short AsShort() const
Returns the value as a short integer.
Definition jsonval.cpp:1041
wxString GetInfo() const
Returns informations about the object.
Definition jsonval.cpp:2075
bool IsNull() const
Return TRUE if the type of the value is wxJSONTYPE_NULL.
Definition jsonval.cpp:503
void SetLineNo(int num)
Set the line number of this JSON value object.
Definition jsonval.cpp:2626
bool IsObject() const
Return TRUE if the type of this value is a key/value map.
Definition jsonval.cpp:759
unsigned long AsULong() const
Returns the value as a unsigned long integer.
Definition jsonval.cpp:1020
bool AsBool() const
Return the stored value as a boolean.
Definition jsonval.cpp:812
wxJSONRefData * SetType(wxJSONType type)
Set the type of the stored value.
Definition jsonval.cpp:2533
int GetCommentPos() const
Return the comment position.
Definition jsonval.cpp:2449
wxJSONRefData * m_refData
the referenced data
Definition jsonval.h:282
virtual ~wxJSONValue()
Dtor - calls UnRef().
Definition jsonval.cpp:406
wxJSONValue & operator=(int i)
Assign the specified value to this object replacing the old value.
Definition jsonval.cpp:1748
wxJSONValue & Item(unsigned index)
Return the item at the specified index.
Definition jsonval.cpp:1603
int AsInt() const
Return the stored value as an integer.
Definition jsonval.cpp:792
const wxJSONInternalArray * AsArray() const
Return the stored value as an array object.
Definition jsonval.cpp:1282
wxMemoryBuffer AsMemoryBuff() const
Returns the value as a memory buffer.
Definition jsonval.cpp:1216
const wxArrayString & GetCommentArray() const
Get the comment string's array.
Definition jsonval.cpp:2456
wxJSONRefData * GetRefData() const
Return the pointer to the referenced data structure.
Definition jsonval.cpp:2682
static wxString TypeToString(wxJSONType type)
Return a string description of the type.
Definition jsonval.cpp:1955