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 = _T("jsonval");
43#if wxDEBUG_LEVEL > 0
44static const wxChar* traceMask = _T("jsonval");
45static const wxChar* compareTraceMask = _T("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, _T("(%s) JSON refData ctor progr=%d"),
81 __PRETTY_FUNCTION__, 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, _T("(%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, _T("(%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(_T("%") compatibleLongLongFmtSpec _T("i"),
887 data->m_value.m_valInt64);
888#else
889 s.Printf(_T("%ld"), data->m_value.m_valLong);
890#endif
891 break;
892 case wxJSONTYPE_UINT:
893#if defined(wxJSON_64BIT_INT)
894 s.Printf(_T("%") compatibleLongLongFmtSpec _T("u"),
895 data->m_value.m_valUInt64);
896#else
897 s.Printf(_T("%lu"), data->m_value.m_valULong);
898#endif
899 break;
900 case wxJSONTYPE_DOUBLE:
901 s.Printf(_T("%.10g"), data->m_value.m_valDouble);
902 break;
903 case wxJSONTYPE_BOOL:
904 s.assign((data->m_value.m_valBool ? _T("true") : _T("false")));
905 break;
906 case wxJSONTYPE_NULL:
907 s.assign(_T( "null"));
908 break;
909 case wxJSONTYPE_INVALID:
910 s.assign(_T( "<invalid>"));
911 break;
912 case wxJSONTYPE_ARRAY:
913 s.Printf(_T("[%d]"), size);
914 break;
915 case wxJSONTYPE_OBJECT:
916 s.Printf(_T("{%d}"), size);
917 break;
918 case wxJSONTYPE_MEMORYBUFF:
919 s = MemoryBuffToString(*(data->m_memBuff), 5);
920 break;
921 default:
922 s.assign(_T( "wxJSONValue::AsString(): Unknown JSON type \'"));
923 s.append(TypeToString(data->m_type));
924 s.append(_T( "\'" ));
925 wxFAIL_MSG(s);
926 break;
927 }
928 return s;
929}
930
932
947const wxChar* wxJSONValue::AsCString() const {
948 const wxChar* s = nullptr;
949 wxJSONRefData* data = GetRefData();
950 wxJSON_ASSERT(data);
951 switch (data->m_type) {
952 case wxJSONTYPE_CSTRING:
953 s = data->m_value.m_valCString;
954 break;
955 case wxJSONTYPE_STRING:
956 s = data->m_valString.c_str();
957 break;
958 default:
959 break;
960 }
961 return s;
962}
963
965
976unsigned int wxJSONValue::AsUInt() const {
977 wxJSONRefData* data = GetRefData();
978 wxJSON_ASSERT(data);
979 unsigned int ui = (unsigned)data->m_value.VAL_UINT;
980
981 wxJSON_ASSERT(IsUInt());
982 return ui;
983}
984
986
997long int wxJSONValue::AsLong() const {
998 long int l;
999 wxJSONRefData* data = GetRefData();
1000 wxJSON_ASSERT(data);
1001 l = (long)data->m_value.VAL_INT;
1002
1003 wxJSON_ASSERT(IsLong());
1004 return l;
1005}
1006
1008
1019unsigned long int wxJSONValue::AsULong() const {
1020 wxJSONRefData* data = GetRefData();
1021 wxJSON_ASSERT(data);
1022 unsigned long int ul = (unsigned long)data->m_value.VAL_UINT;
1023
1024 wxJSON_ASSERT(IsULong()); // expands only in debug builds
1025 return ul;
1026}
1027
1029
1040short int wxJSONValue::AsShort() const {
1041 short int i;
1042 wxJSONRefData* data = GetRefData();
1043 wxJSON_ASSERT(data);
1044 i = (short)data->m_value.VAL_INT;
1045
1046 wxJSON_ASSERT(IsShort());
1047 return i;
1048}
1049
1051
1062unsigned short wxJSONValue::AsUShort() const {
1063 unsigned short ui;
1064 wxJSONRefData* data = GetRefData();
1065 wxJSON_ASSERT(data);
1066 ui = (unsigned short)data->m_value.VAL_UINT;
1067
1068 wxJSON_ASSERT(IsUShort());
1069 return ui;
1070}
1071
1073
1098bool wxJSONValue::AsInt(int& i) const {
1099 bool r = false;
1100 if (IsInt()) {
1101 i = AsInt();
1102 r = true;
1103 }
1104 return r;
1105}
1106
1107bool wxJSONValue::AsUInt(unsigned int& ui) const {
1108 bool r = false;
1109 if (IsUInt()) {
1110 ui = AsUInt();
1111 r = true;
1112 }
1113 return r;
1114}
1115
1116bool wxJSONValue::AsShort(short int& s) const {
1117 bool r = false;
1118 if (IsShort()) {
1119 s = AsShort();
1120 r = true;
1121 }
1122 return r;
1123}
1124
1125bool wxJSONValue::AsUShort(unsigned short& us) const {
1126 bool r = false;
1127 if (IsUShort()) {
1128 us = AsUShort();
1129 r = true;
1130 }
1131 return r;
1132}
1133
1134bool wxJSONValue::AsLong(long int& l) const {
1135 bool r = false;
1136 if (IsLong()) {
1137 l = AsLong();
1138 r = true;
1139 }
1140 return r;
1141}
1142
1143bool wxJSONValue::AsULong(unsigned long& ul) const {
1144 bool r = false;
1145 if (IsULong()) {
1146 ul = AsULong();
1147 r = true;
1148 }
1149 return r;
1150}
1151
1152bool wxJSONValue::AsBool(bool& b) const {
1153 bool r = false;
1154 if (IsBool()) {
1155 b = AsBool();
1156 r = true;
1157 }
1158 return r;
1159}
1160
1161bool wxJSONValue::AsDouble(double& d) const {
1162 bool r = false;
1163 if (IsDouble()) {
1164 d = AsDouble();
1165 r = true;
1166 }
1167 return r;
1168}
1169
1171
1180bool wxJSONValue::AsString(wxString& str) const {
1181 bool r = IsString();
1182 if (r) {
1183 str = AsString();
1184 }
1185 return r;
1186}
1187
1188bool wxJSONValue::AsCString(wxChar* ch) const {
1189 bool r = IsCString();
1190 if (r) {
1191 ch = (wxChar*)AsCString();
1192 }
1193 return r;
1194}
1195
1197
1215wxMemoryBuffer wxJSONValue::AsMemoryBuff() const {
1216 wxJSONRefData* data = GetRefData();
1217 wxJSON_ASSERT(data);
1218 wxMemoryBuffer buff;
1219 if (data->m_memBuff) {
1220 buff = *(data->m_memBuff);
1221 }
1222
1223 wxJSON_ASSERT(IsMemoryBuff());
1224 return buff;
1225}
1226
1228
1246bool wxJSONValue::AsMemoryBuff(wxMemoryBuffer& buff) const {
1247 bool r = IsMemoryBuff();
1248 if (r) {
1249 buff = AsMemoryBuff();
1250 }
1251 return r;
1252}
1253
1254// internal use
1255
1257
1263const wxJSONInternalMap* wxJSONValue::AsMap() const {
1264 wxJSONRefData* data = GetRefData();
1265 wxJSON_ASSERT(data);
1266
1267 const wxJSONInternalMap* v = nullptr;
1268 if (data->m_type == wxJSONTYPE_OBJECT) {
1269 v = &(data->m_valMap);
1270 }
1271 return v;
1272}
1273
1275
1281const wxJSONInternalArray* wxJSONValue::AsArray() const {
1282 wxJSONRefData* data = GetRefData();
1283 wxJSON_ASSERT(data);
1284
1285 const wxJSONInternalArray* v = nullptr;
1286 if (data->m_type == wxJSONTYPE_ARRAY) {
1287 v = &(data->m_valArray);
1288 }
1289 return v;
1290}
1291
1292// retrieve the members and other info
1293
1295
1298bool wxJSONValue::HasMember(unsigned index) const {
1299 bool r = false;
1300 int size = Size();
1301 if (index < (unsigned)size) {
1302 r = true;
1303 }
1304 return r;
1305}
1306
1308
1311bool wxJSONValue::HasMember(const wxString& key) const {
1312 bool r = false;
1313 wxJSONRefData* data = GetRefData();
1314 wxJSON_ASSERT(data);
1315
1316 if (data && data->m_type == wxJSONTYPE_OBJECT) {
1317 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1318 if (it != data->m_valMap.end()) {
1319 r = true;
1320 }
1321 }
1322 return r;
1323}
1324
1326
1333 wxJSONRefData* data = GetRefData();
1334 wxJSON_ASSERT(data);
1335
1336 int size = -1;
1337 if (data->m_type == wxJSONTYPE_ARRAY) {
1338 size = (int)data->m_valArray.GetCount();
1339 }
1340 if (data->m_type == wxJSONTYPE_OBJECT) {
1341 size = (int)data->m_valMap.size();
1342 }
1343 return size;
1344}
1345
1347
1357wxArrayString wxJSONValue::GetMemberNames() const {
1358 wxJSONRefData* data = GetRefData();
1359 wxJSON_ASSERT(data);
1360 wxJSON_ASSERT(data->m_type == wxJSONTYPE_OBJECT);
1361
1362 wxArrayString arr;
1363 if (data->m_type == wxJSONTYPE_OBJECT) {
1364 wxJSONInternalMap::iterator it;
1365 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
1366 arr.Add(it->first);
1367 }
1368 }
1369 return arr;
1370}
1371
1372// appending items, resizing and deleting items
1373// NOTE: these functions are not 'const' so we have to call
1374// the COW() function before accessing data
1375
1377
1386 wxJSONRefData* data = COW();
1387 wxJSON_ASSERT(data);
1388 if (data->m_type != wxJSONTYPE_ARRAY) {
1389 // we have to change the type of the actual object to the array type
1390 SetType(wxJSONTYPE_ARRAY);
1391 }
1392 // we add the wxJSONValue object to the wxObjArray: note that the
1393 // array makes a copy of the JSON-value object by calling its
1394 // copy ctor thus using reference count
1395 data->m_valArray.Add(value);
1396 wxJSONValue& v = data->m_valArray.Last();
1397 return v;
1398}
1399
1402 wxJSONValue v(i);
1403 wxJSONValue& r = Append(v);
1404 return r;
1405}
1406
1408wxJSONValue& wxJSONValue::Append(short int i) {
1409 wxJSONValue v(i);
1410 wxJSONValue& r = Append(v);
1411 return r;
1412}
1413
1415wxJSONValue& wxJSONValue::Append(long int l) {
1416 wxJSONValue v(l);
1417 wxJSONValue& r = Append(v);
1418 return r;
1419}
1420
1423 wxJSONValue v(b);
1424 wxJSONValue& r = Append(v);
1425 return r;
1426}
1427
1429wxJSONValue& wxJSONValue::Append(unsigned int ui) {
1430 wxJSONValue v(ui);
1431 wxJSONValue& r = Append(v);
1432 return r;
1433}
1434
1436wxJSONValue& wxJSONValue::Append(unsigned short ui) {
1437 wxJSONValue v(ui);
1438 wxJSONValue& r = Append(v);
1439 return r;
1440}
1441
1443wxJSONValue& wxJSONValue::Append(unsigned long ul) {
1444 wxJSONValue v(ul);
1445 wxJSONValue& r = Append(v);
1446 return r;
1447}
1448
1451 wxJSONValue v(d);
1452 wxJSONValue& r = Append(v);
1453 return r;
1454}
1455
1457wxJSONValue& wxJSONValue::Append(const wxChar* str) {
1458 wxJSONValue v(str);
1459 wxJSONValue& r = Append(v);
1460 return r;
1461}
1462
1464wxJSONValue& wxJSONValue::Append(const wxString& str) {
1465 wxJSONValue v(str);
1466 wxJSONValue& r = Append(v);
1467 return r;
1468}
1469
1471wxJSONValue& wxJSONValue::Append(const wxMemoryBuffer& buff) {
1472 wxJSONValue v(buff);
1473 wxJSONValue& r = Append(v);
1474 return r;
1475}
1476
1478wxJSONValue& wxJSONValue::Append(const void* buff, size_t len) {
1479 wxJSONValue v(buff, len);
1480 wxJSONValue& r = Append(v);
1481 return r;
1482}
1483
1485
1493bool wxJSONValue::Cat(const wxString& str) {
1494 wxJSONRefData* data = GetRefData();
1495 wxJSON_ASSERT(data);
1496
1497 bool r = false;
1498 if (data->m_type == wxJSONTYPE_STRING) {
1499 wxJSONRefData* data = COW();
1500 wxJSON_ASSERT(data);
1501 data->m_valString.append(str);
1502 r = true;
1503 }
1504 return r;
1505}
1506
1508
1514bool wxJSONValue::Cat(const wxMemoryBuffer& buff) {
1515 wxJSONRefData* data = GetRefData();
1516 wxJSON_ASSERT(data);
1517
1518 bool r = false;
1519 if (data->m_type == wxJSONTYPE_MEMORYBUFF) {
1520 wxJSONRefData* data = COW();
1521 wxJSON_ASSERT(data);
1522 data->m_memBuff->AppendData(buff.GetData(), buff.GetDataLen());
1523 r = true;
1524 }
1525 return r;
1526}
1527
1529bool wxJSONValue::Cat(const wxChar* str) {
1530 wxJSONRefData* data = GetRefData();
1531 wxJSON_ASSERT(data);
1532
1533 bool r = false;
1534 if (data->m_type == wxJSONTYPE_STRING) {
1535 wxJSONRefData* data = COW();
1536 wxJSON_ASSERT(data);
1537 data->m_valString.append(str);
1538 r = true;
1539 }
1540 return r;
1541}
1542
1544
1551bool wxJSONValue::Remove(int index) {
1552 wxJSONRefData* data = COW();
1553 wxJSON_ASSERT(data);
1554
1555 bool r = false;
1556 if (data->m_type == wxJSONTYPE_ARRAY) {
1557 data->m_valArray.RemoveAt(index);
1558 r = true;
1559 }
1560 return r;
1561}
1562
1564bool wxJSONValue::Remove(const wxString& key) {
1565 wxJSONRefData* data = COW();
1566 wxJSON_ASSERT(data);
1567
1568 bool r = false;
1569 if (data->m_type == wxJSONTYPE_OBJECT) {
1570 wxJSONInternalMap::size_type count = data->m_valMap.erase(key);
1571 if (count > 0) {
1572 r = true;
1573 }
1574 }
1575 return r;
1576}
1577
1579
1585 UnRef();
1586 SetType(wxJSONTYPE_INVALID);
1587}
1588
1589// retrieve an item
1590
1592
1603 wxJSONRefData* data = COW();
1604 wxJSON_ASSERT(data);
1605
1606 if (data->m_type != wxJSONTYPE_ARRAY) {
1607 data = SetType(wxJSONTYPE_ARRAY);
1608 }
1609 int size = Size();
1610 wxJSON_ASSERT(size >= 0);
1611 // if the desired element does not yet exist, we create as many
1612 // elements as needed; the new values will be 'null' values
1613 if (index >= (unsigned)size) {
1614 wxJSONValue v(wxJSONTYPE_NULL);
1615 int missing = index - size + 1;
1616 data->m_valArray.Add(v, missing);
1617 }
1618 return data->m_valArray.Item(index);
1619}
1620
1622
1630wxJSONValue& wxJSONValue::Item(const wxString& key) {
1631 wxLogTrace(traceMask, _T("(%s) searched key=\'%s\'"), __PRETTY_FUNCTION__,
1632 key.c_str());
1633#if !wxCHECK_VERSION(2, 9, 0)
1634 wxLogTrace(traceMask, _T("(%s) actual object: %s"), __PRETTY_FUNCTION__,
1635 GetInfo().c_str());
1636#endif
1637
1638 wxJSONRefData* data = COW();
1639 wxJSON_ASSERT(data);
1640
1641 if (data->m_type != wxJSONTYPE_OBJECT) {
1642 // deletes the contained value;
1643 data = SetType(wxJSONTYPE_OBJECT);
1644 return data->m_valMap[key];
1645 }
1646 wxLogTrace(traceMask, _T("(%s) searching key \'%s' in the actual object"),
1647 __PRETTY_FUNCTION__, key.c_str());
1648 return data->m_valMap[key];
1649}
1650
1652
1657wxJSONValue wxJSONValue::ItemAt(unsigned index) const {
1658 wxJSONRefData* data = GetRefData();
1659 wxJSON_ASSERT(data);
1660
1661 wxJSONValue v(wxJSONTYPE_INVALID);
1662 if (data->m_type == wxJSONTYPE_ARRAY) {
1663 int size = Size();
1664 wxJSON_ASSERT(size >= 0);
1665 if (index < (unsigned)size) {
1666 v = data->m_valArray.Item(index);
1667 }
1668 }
1669 return v;
1670}
1671
1673
1678wxJSONValue wxJSONValue::ItemAt(const wxString& key) const {
1679 wxLogTrace(traceMask, _T("(%s) searched key=\'%s\'"), __PRETTY_FUNCTION__,
1680 key.c_str());
1681 wxLogTrace(traceMask, _T("(%s) actual object: %s"), __PRETTY_FUNCTION__,
1682 GetInfo().c_str());
1683
1684 wxJSONRefData* data = GetRefData();
1685 wxJSON_ASSERT(data);
1686
1687 wxJSONValue v(wxJSONTYPE_INVALID);
1688 if (data->m_type == wxJSONTYPE_OBJECT) {
1689 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1690 if (it != data->m_valMap.end()) {
1691 v = it->second;
1692 }
1693 }
1694 return v;
1695}
1696
1698
1708 wxJSONValue& v = Item(index);
1709 return v;
1710}
1711
1713
1722 wxJSONValue& v = Item(key);
1723 return v;
1724}
1725
1726//
1727// assignment operators
1728// note that reference counting is only used if the original
1729// value is a wxJSONValue object
1730// in all other cases, the operator= function deletes the old
1731// content and assigns the new one
1732
1734
1748 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1749 data->m_value.VAL_INT = i;
1750 return *this;
1751}
1752
1755 wxJSONRefData* data = SetType(wxJSONTYPE_BOOL);
1756 data->m_value.m_valBool = b;
1757 return *this;
1758}
1759
1761wxJSONValue& wxJSONValue::operator=(unsigned int ui) {
1762 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1763 data->m_value.VAL_UINT = ui;
1764 return *this;
1765}
1766
1769 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1770 data->m_value.VAL_INT = l;
1771 return *this;
1772}
1773
1775wxJSONValue& wxJSONValue::operator=(unsigned long ul) {
1776 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1777 data->m_value.VAL_UINT = ul;
1778 return *this;
1779}
1780
1783 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
1784 data->m_value.VAL_INT = i;
1785 return *this;
1786}
1787
1789wxJSONValue& wxJSONValue::operator=(unsigned short ui) {
1790 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
1791 data->m_value.VAL_UINT = ui;
1792 return *this;
1793}
1794
1797 wxJSONRefData* data = SetType(wxJSONTYPE_DOUBLE);
1798 data->m_value.m_valDouble = d;
1799 return *this;
1800}
1801
1803wxJSONValue& wxJSONValue::operator=(const wxChar* str) {
1804 wxJSONRefData* data = SetType(wxJSONTYPE_CSTRING);
1805 data->m_value.m_valCString = str;
1806#if !defined(WXJSON_USE_CSTRING)
1807 data->m_type = wxJSONTYPE_STRING;
1808 data->m_valString.assign(str);
1809#endif
1810 return *this;
1811}
1812
1814wxJSONValue& wxJSONValue::operator=(const wxString& str) {
1815 wxJSONRefData* data = SetType(wxJSONTYPE_STRING);
1816 data->m_valString.assign(str);
1817 return *this;
1818}
1819
1821
1826wxJSONValue& wxJSONValue::operator=(const wxMemoryBuffer& buff) {
1827 wxJSONRefData* data = SetType(wxJSONTYPE_MEMORYBUFF);
1828 data->m_memBuff = new wxMemoryBuffer();
1829 const void* ptr = buff.GetData();
1830 size_t len = buff.GetDataLen();
1831 if (data->m_memBuff && len) {
1832 data->m_memBuff->AppendData(ptr, len);
1833 }
1834 return *this;
1835}
1836
1838
1846 Ref(other);
1847 return *this;
1848}
1849
1850// finding elements
1851
1853
1878wxJSONValue wxJSONValue::Get(const wxString& key,
1879 const wxJSONValue& defaultValue) const {
1880 // NOTE: this function does many wxJSONValue copies.
1881 // so implementing COW is a good thing
1882
1883 // this is the first copy (the default value)
1884 wxJSONValue v(defaultValue);
1885
1886 wxJSONRefData* data = GetRefData();
1887 wxJSON_ASSERT(data);
1888 if (data->m_type == wxJSONTYPE_OBJECT) {
1889 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1890 if (it != data->m_valMap.end()) {
1891 v = it->second;
1892 }
1893 }
1894 return v;
1895}
1896
1897// protected functions
1898
1900
1906wxJSONValue* wxJSONValue::Find(unsigned index) const {
1907 wxJSONRefData* data = GetRefData();
1908 wxJSON_ASSERT(data);
1909
1910 wxJSONValue* vp = nullptr;
1911
1912 if (data->m_type == wxJSONTYPE_ARRAY) {
1913 size_t size = data->m_valArray.GetCount();
1914 if (index < size) {
1915 vp = &(data->m_valArray.Item(index));
1916 }
1917 }
1918 return vp;
1919}
1920
1922
1928wxJSONValue* wxJSONValue::Find(const wxString& key) const {
1929 wxJSONRefData* data = GetRefData();
1930 wxJSON_ASSERT(data);
1931
1932 wxJSONValue* vp = nullptr;
1933
1934 if (data->m_type == wxJSONTYPE_OBJECT) {
1935 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1936 if (it != data->m_valMap.end()) {
1937 vp = &(it->second);
1938 }
1939 }
1940 return vp;
1941}
1942
1944
1954wxString wxJSONValue::TypeToString(wxJSONType type) {
1955 static const wxChar* str[] = {
1956 _T( "wxJSONTYPE_INVALID" ), // 0
1957 _T( "wxJSONTYPE_NULL" ), // 1
1958 _T( "wxJSONTYPE_INT" ), // 2
1959 _T( "wxJSONTYPE_UINT" ), // 3
1960 _T( "wxJSONTYPE_DOUBLE" ), // 4
1961 _T( "wxJSONTYPE_STRING" ), // 5
1962 _T( "wxJSONTYPE_CSTRING" ), // 6
1963 _T( "wxJSONTYPE_BOOL" ), // 7
1964 _T( "wxJSONTYPE_ARRAY" ), // 8
1965 _T( "wxJSONTYPE_OBJECT" ), // 9
1966 _T( "wxJSONTYPE_LONG" ), // 10
1967 _T( "wxJSONTYPE_INT64" ), // 11
1968 _T( "wxJSONTYPE_ULONG" ), // 12
1969 _T( "wxJSONTYPE_UINT64" ), // 13
1970 _T( "wxJSONTYPE_SHORT" ), // 14
1971 _T( "wxJSONTYPE_USHORT" ), // 15
1972 _T( "wxJSONTYPE_MEMORYBUFF" ), // 16
1973 };
1974
1975 wxString s;
1976 int idx = (int)type;
1977 if (idx >= 0 && idx < 17) {
1978 s = str[idx];
1979 }
1980 return s;
1981}
1982
1984
2003wxString wxJSONValue::Dump(bool deep, int indent) const {
2004 wxJSONRefData* data = GetRefData();
2005 wxJSON_ASSERT(data);
2006
2007 wxJSONType type = GetType();
2008
2009 wxString s;
2010 if (indent > 0) {
2011 s.append(indent, ' ');
2012 }
2013
2014 wxString s1;
2015 wxString s2;
2016#if defined(WXJSON_USE_VALUE_COUNTER)
2017 s1.Printf(_T("Object: Progr=%d Type=%s Size=%d comments=%d\n"), m_progr,
2018 TypeToString(type).c_str(), Size(), data->m_comments.GetCount());
2019 s2.Printf(_T(" : RefData=%p Progr=%d Num shares=%d\n"), data,
2020 data->m_progr, data->GetRefCount());
2021#else
2022 s1.Printf(_T("Object: Type=%s Size=%d comments=%d\n"),
2023 TypeToString(type).c_str(), Size(), data->m_comments.GetCount());
2024 s2.Printf(_T(" : RefData=%p Num shares=%d\n"), data,
2025 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(_T("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(_T("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(_T(" Member name: "));
2093 s.append(arr[i]);
2094 s.append(_T("\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 _T("(%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,
2265 _T("(%s) Comparing an array object - size=%d"),
2266 __PRETTY_FUNCTION__, size);
2267
2268 if (size != other.Size()) {
2269 wxLogTrace(compareTraceMask, _T("(%s) Sizes does not match"),
2270 __PRETTY_FUNCTION__);
2271 return false;
2272 }
2273 // compares every element in this object with the element of
2274 // the same index in the 'other' object
2275 for (int i = 0; i < size; i++) {
2276 wxLogTrace(compareTraceMask, _T("(%s) Comparing array element=%d"),
2277 __PRETTY_FUNCTION__, i);
2278 wxJSONValue v1 = ItemAt(i);
2279 wxJSONValue v2 = other.ItemAt(i);
2280
2281 if (!v1.IsSameAs(v2)) {
2282 return false;
2283 }
2284 }
2285 break;
2286 case wxJSONTYPE_OBJECT:
2287 size = Size();
2288 wxLogTrace(compareTraceMask, _T("(%s) Comparing a map obejct - size=%d"),
2289 __PRETTY_FUNCTION__, size);
2290
2291 if (size != other.Size()) {
2292 wxLogTrace(compareTraceMask,
2293 _T("(%s) Comparison failed - sizes does not match"),
2294 __PRETTY_FUNCTION__);
2295 return false;
2296 }
2297 // for every key calls itself on the value found in
2298 // the other object. if 'key' does no exist, returns FALSE
2299 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
2300 wxString key = it->first;
2301 wxLogTrace(compareTraceMask, _T("(%s) Comparing map object - key=%s"),
2302 __PRETTY_FUNCTION__, key.c_str());
2303 wxJSONValue otherVal = other.ItemAt(key);
2304 bool isSame = it->second.IsSameAs(otherVal);
2305 if (!isSame) {
2306 wxLogTrace(compareTraceMask,
2307 _T("(%s) Comparison failed for the last object"),
2308 __PRETTY_FUNCTION__);
2309 return false;
2310 }
2311 }
2312 break;
2313 default:
2314 // should never happen
2315 wxFAIL_MSG(_T("wxJSONValue::IsSameAs() unexpected wxJSONType"));
2316 break;
2317 }
2318 return r;
2319}
2320
2322
2346int wxJSONValue::AddComment(const wxString& str, int position) {
2347 wxJSONRefData* data = COW();
2348 wxJSON_ASSERT(data);
2349
2350 wxLogTrace(traceMask, _T("(%s) comment=%s"), __PRETTY_FUNCTION__,
2351 str.c_str());
2352 int r = -1;
2353 int len = str.length();
2354 if (len < 2) {
2355 wxLogTrace(traceMask, _T(" error: len < 2"));
2356 return -1;
2357 }
2358 if (str[0] != '/') {
2359 wxLogTrace(traceMask, _T(" error: does not start with\'/\'"));
2360 return -1;
2361 }
2362 if (str[1] == '/') { // a C++ comment: check that it ends with '\n'
2363 wxLogTrace(traceMask, _T(" C++ comment" ));
2364 if (str.GetChar(len - 1) != '\n') {
2365 wxString temp(str);
2366 temp.append(1, '\n');
2367 data->m_comments.Add(temp);
2368 wxLogTrace(traceMask, _T(" C++ comment: LF added"));
2369 } else {
2370 data->m_comments.Add(str);
2371 }
2372 r = data->m_comments.size();
2373 } else if (str[1] ==
2374 '*') { // a C-style comment: check that it ends with '*/'
2375 wxLogTrace(traceMask, _T(" C-style comment"));
2376 int lastPos = len - 1;
2377 wxChar ch = str.GetChar(lastPos);
2378 // skip leading whitespaces
2379 while (ch == ' ' || ch == '\n' || ch == '\t') {
2380 --lastPos;
2381 ch = str.GetChar(lastPos);
2382 }
2383 if (str.GetChar(lastPos) == '/' && str.GetChar(lastPos - 1) == '*') {
2384 data->m_comments.Add(str);
2385 r = data->m_comments.size();
2386 }
2387 } else {
2388 wxLogTrace(traceMask, _T(" error: is not a valid comment string"));
2389 r = -1;
2390 }
2391 // if the comment was stored, store the position
2392 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2393 data->m_commentPos = position;
2394 }
2395 return r;
2396}
2397
2399
2405int wxJSONValue::AddComment(const wxArrayString& comments, int position) {
2406 int siz = comments.GetCount();
2407 int r = 0;
2408 for (int i = 0; i < siz; i++) {
2409 int r2 = AddComment(comments[i], position);
2410 if (r2 >= 0) {
2411 ++r;
2412 }
2413 }
2414 return r;
2415}
2416
2418
2424wxString wxJSONValue::GetComment(int idx) const {
2425 wxJSONRefData* data = GetRefData();
2426 wxJSON_ASSERT(data);
2427
2428 wxString s;
2429 int size = data->m_comments.GetCount();
2430 if (idx < 0) {
2431 for (int i = 0; i < size; i++) {
2432 s.append(data->m_comments[i]);
2433 }
2434 } else if (idx < size) {
2435 s = data->m_comments[idx];
2436 }
2437 return s;
2438}
2439
2442 wxJSONRefData* data = GetRefData();
2443 wxJSON_ASSERT(data);
2444
2445 int d = data->m_comments.GetCount();
2446 wxLogTrace(traceMask, _T("(%s) comment count=%d"), __PRETTY_FUNCTION__, d);
2447 return d;
2448}
2449
2452 wxJSONRefData* data = GetRefData();
2453 wxJSON_ASSERT(data);
2454 return data->m_commentPos;
2455}
2456
2458const wxArrayString& wxJSONValue::GetCommentArray() const {
2459 wxJSONRefData* data = GetRefData();
2460 wxJSON_ASSERT(data);
2461
2462 return data->m_comments;
2463}
2464
2467 wxJSONRefData* data = COW();
2468 wxJSON_ASSERT(data);
2469
2470 data->m_comments.clear();
2471}
2472
2474
2536 wxJSONRefData* data = GetRefData();
2537 wxJSONType oldType = GetType();
2538
2539 // check that type is within the allowed range
2540 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2541 (type <= wxJSONTYPE_MEMORYBUFF));
2542 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2543 type = wxJSONTYPE_INVALID;
2544 }
2545
2546 // the function unshares the referenced data but does not delete the
2547 // structure. This is because the wxJSON reader stores comments
2548 // that apear before the value in a temporary value of type wxJSONTYPE_INVALID
2549 // which is invalid and, next, it stores the JSON value in the same
2550 // wxJSONValue object.
2551 // If we would delete the structure using 'Unref()' we loose the
2552 // comments
2553 data = COW();
2554
2555 // do nothing if the actual type is the same as 'type'
2556 if (type == oldType) {
2557 return data;
2558 }
2559
2560 // change the type of the referened structure
2561 // NOTE: integer types are always stored as the generic integer types
2562 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2563 type == wxJSONTYPE_SHORT) {
2564 type = wxJSONTYPE_INT;
2565 }
2566 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2567 type == wxJSONTYPE_USHORT) {
2568 type = wxJSONTYPE_UINT;
2569 }
2570
2571 wxJSON_ASSERT(data);
2572 data->m_type = type;
2573
2574 // clears complex objects of the old type
2575 switch (oldType) {
2576 case wxJSONTYPE_STRING:
2577 data->m_valString.clear();
2578 break;
2579 case wxJSONTYPE_ARRAY:
2580 data->m_valArray.Clear();
2581 break;
2582 case wxJSONTYPE_OBJECT:
2583 data->m_valMap.clear();
2584 break;
2585 case wxJSONTYPE_MEMORYBUFF:
2586 // we first have to delete the actual memory buffer, if any
2587 if (data->m_memBuff) {
2588 delete data->m_memBuff;
2589 data->m_memBuff = 0;
2590 }
2591 break;
2592 default:
2593 // there is not need to clear primitive types
2594 break;
2595 }
2596
2597 // if the WXJSON_USE_CSTRING macro is not defined, the class forces
2598 // C-string to be stored as wxString objects
2599#if !defined(WXJSON_USE_CSTRING)
2600 if (data->m_type == wxJSONTYPE_CSTRING) {
2601 data->m_type = wxJSONTYPE_STRING;
2602 }
2603#endif
2604 return data;
2605}
2606
2608
2618 // return ZERO if there is not a referenced data structure
2619 int n = 0;
2620 wxJSONRefData* data = GetRefData();
2621 if (data != 0) {
2622 n = data->m_lineNo;
2623 }
2624 return n;
2625}
2626
2629 wxJSONRefData* data = COW();
2630 wxJSON_ASSERT(data);
2631 data->m_lineNo = num;
2632}
2633
2636
2638void wxJSONValue::Ref(const wxJSONValue& clone) {
2639 // nothing to be done
2640 if (m_refData == clone.m_refData) return;
2641
2642 // delete reference to old data
2643 UnRef();
2644
2645 // reference new data
2646 if (clone.m_refData) {
2647 m_refData = clone.m_refData;
2648 ++(m_refData->m_refCount);
2649 }
2650}
2651
2653
2659 if (m_refData) {
2660 wxASSERT_MSG(m_refData->m_refCount > 0, _T("invalid ref data count"));
2661
2662 if (--m_refData->m_refCount == 0) {
2663 delete m_refData;
2664 m_refData = nullptr;
2665 }
2666 }
2667}
2668
2671
2673
2678 UnRef();
2679 wxJSONRefData* data = CloneRefData(other.m_refData);
2680 SetRefData(data);
2681}
2682
2685 wxJSONRefData* data = m_refData;
2686 return data;
2687}
2688
2690
2699 wxJSON_ASSERT(otherData);
2700
2701 // make a static cast to pointer-to-wxJSONRefData
2702 const wxJSONRefData* other = otherData;
2703
2704 // allocate a new instance of wxJSONRefData using the default
2705 // ctor; we cannot use the copy ctor of a wxJSONRefData
2706 wxJSONRefData* data = new wxJSONRefData();
2707
2708 // copy the referenced data structure's data members
2709 data->m_type = other->m_type;
2710 data->m_value = other->m_value;
2711 data->m_commentPos = other->m_commentPos;
2712 data->m_comments = other->m_comments;
2713 data->m_lineNo = other->m_lineNo;
2714 data->m_valString = other->m_valString;
2715 data->m_valArray = other->m_valArray;
2716 data->m_valMap = other->m_valMap;
2717
2718 // if the data contains a wxMemoryBuffer object, then we have
2719 // to make a deep copy of the buffer by allocating a new one because
2720 // wxMemoryBuffer is not a copy-on-write structure
2721 if (other->m_memBuff) {
2722 data->m_memBuff = new wxMemoryBuffer();
2723 const void* ptr = data->m_memBuff->GetData();
2724 size_t len = data->m_memBuff->GetDataLen();
2725 if (data->m_memBuff && len) {
2726 data->m_memBuff->AppendData(ptr, len);
2727 }
2728 }
2729
2730 wxLogTrace(cowTraceMask, _T("(%s) CloneRefData() PROGR: other=%d data=%d"),
2731 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2732
2733 return data;
2734}
2735
2737
2744 wxJSONRefData* data = new wxJSONRefData();
2745 data->m_type = wxJSONTYPE_INVALID;
2746 return data;
2747}
2748
2750
2757 wxJSONRefData* data = GetRefData();
2758 wxLogTrace(cowTraceMask, _T("(%s) COW() START data=%p data->m_count=%d"),
2759 __PRETTY_FUNCTION__, data, data->GetRefCount());
2760 UnShare();
2761 data = GetRefData();
2762 wxLogTrace(cowTraceMask, _T("(%s) COW() END data=%p data->m_count=%d"),
2763 __PRETTY_FUNCTION__, data, data->GetRefCount());
2764 return GetRefData();
2765}
2766
2769 if (!m_refData) {
2771 } else if (m_refData->GetRefCount() > 1) {
2772 // note that ref is not going to be destroyed in this case
2773 const wxJSONRefData* ref = m_refData;
2774 UnRef();
2775
2776 // ... so we can still access it
2777 m_refData = CloneRefData(ref);
2778 }
2779 // else: ref count is 1, we are exclusive owners of m_refData anyhow
2780
2781 wxASSERT_MSG(m_refData && m_refData->GetRefCount() == 1,
2782 _T("wxObject::AllocExclusive() failed."));
2783}
2784
2786/*/
2787 The fucntion returns a string representation of the data contained in the
2788 memory buffer object \c buff.
2789 The string is conposed of two hexadecimal digits for every byte contained
2790 in the memory buffer; bytes are separated by a space character.
2791 The string starts with the actual lenght of the data enclosed in parenthesis.
2792 The string will contain \c len bytes if \c len is less than the length
2793 of the actual data in \c buff.
2794 Note that the (len) printed in the output referes to the length of the buffer
2795 which may be greater than the length that has to be printed.
2796
2797 \b Example:
2798 This is an example of printing a memory buffer object that contains 10 bytes:
2799 \code
2800 0x80974653 (10) 00 01 02 03 04 05 06 07 08 09
2801 \endcode
2802*/
2803wxString wxJSONValue::MemoryBuffToString(const wxMemoryBuffer& buff,
2804 size_t len) {
2805 size_t buffLen = buff.GetDataLen();
2806 void* ptr = buff.GetData();
2807 wxString s = MemoryBuffToString(ptr, MIN(buffLen, len), buffLen);
2808 return s;
2809}
2810
2812/*/
2813 The function returns a string representation of the data contained in the
2814 binary memory buffer pointed to by \c buff for \c len bytes.
2815 The string is composed of two hexadecimal digits for every byte contained
2816 in the memory buffer; bytes are separated by a space character.
2817 The string starts with pointer to binary data followed by the lenght of the
2818 data enclosed in parenthesis.
2819
2820 \b Example:
2821 This is an example of printing ten bytes from a memory buffer:
2822 \code
2823 0x80974653 (10) 00 01 02 03 04 05 06 07 08 09
2824 \endcode
2825
2826 @param buff the pointer to the memory buffer data
2827 @len the length of the data that has to be printed
2828 @actualLen the real lenght of the memory buffer that has to be printed
2829 just afetr the pointer; may be greater than \c len. If this parameter
2830 is -1 then it is equal to \c len
2831*/
2832wxString wxJSONValue::MemoryBuffToString(const void* buff, size_t len,
2833 size_t actualLen) {
2834 wxString s;
2835 size_t buffLen = actualLen;
2836 if (buffLen == (size_t)-1) {
2837 buffLen = len;
2838 }
2839 s.Printf(_T("%p (%u) "), buff, buffLen);
2840 unsigned char* ptr = (unsigned char*)buff;
2841 for (unsigned int i = 0; i < len; i++) {
2842 unsigned char c = *ptr;
2843 ++ptr;
2844 // now convert the character
2845 char c1 = c / 16;
2846 char c2 = c % 16;
2847 c1 += '0';
2848 c2 += '0';
2849 if (c1 > '9') {
2850 c1 += 7;
2851 }
2852 if (c2 > '9') {
2853 c2 += 7;
2854 }
2855 s.Append(c1, 1);
2856 s.Append(c2, 1);
2857 s.Append(' ', 1); // a space separates the bytes
2858 }
2859 return s;
2860}
2861
2863
2887int wxJSONValue::CompareMemoryBuff(const wxMemoryBuffer& buff1,
2888 const wxMemoryBuffer& buff2) {
2889 int r;
2890 size_t buff1Len = buff1.GetDataLen();
2891 size_t buff2Len = buff2.GetDataLen();
2892 if (buff1Len > buff2Len) {
2893 r = 1;
2894 } else if (buff1Len < buff2Len) {
2895 r = -1;
2896 } else {
2897 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2898 }
2899 return r;
2900}
2901
2903
2914int wxJSONValue::CompareMemoryBuff(const wxMemoryBuffer& buff1,
2915 const void* buff2) {
2916 int r;
2917 size_t buff1Len = buff1.GetDataLen();
2918 r = memcmp(buff1.GetData(), buff2, buff1Len);
2919 return r;
2920}
2921
2923
2943wxMemoryBuffer wxJSONValue::ArrayToMemoryBuff(const wxJSONValue& value) {
2944 wxMemoryBuffer buff;
2945 if (value.IsArray()) {
2946 int len = value.Size();
2947 for (int i = 0; i < len; i++) {
2948 short int byte;
2949 unsigned char c;
2950 // we do not use opertaor [] because it is not const
2951 // bool r = value[i].AsShort( byte );
2952 bool r = value.ItemAt(i).AsShort(byte);
2953 if (r && (byte >= 0 && byte <= 255)) {
2954 c = (unsigned char)byte;
2955 buff.AppendByte(c);
2956 }
2957 }
2958 }
2959 return buff;
2960}
2961
2962/*************************************************************************
2963
2964 64-bits integer support
2965
2966*************************************************************************/
2967
2968#if defined(wxJSON_64BIT_INT)
2969
2971wxJSONValue::wxJSONValue(wxInt64 i) {
2972 m_refData = nullptr;
2973 wxJSONRefData* data = Init(wxJSONTYPE_INT);
2974 wxJSON_ASSERT(data);
2975 if (data != 0) {
2976 data->m_value.VAL_INT = i;
2977 }
2978}
2979
2981wxJSONValue::wxJSONValue(wxUint64 ui) {
2982 m_refData = nullptr;
2983 wxJSONRefData* data = Init(wxJSONTYPE_UINT);
2984 wxJSON_ASSERT(data);
2985 if (data != 0) {
2986 data->m_value.VAL_UINT = ui;
2987 }
2988}
2989
2991
2999bool wxJSONValue::IsInt32() const {
3000 bool r = IsLong();
3001 return r;
3002}
3003
3005
3013bool wxJSONValue::IsUInt32() const {
3014 bool r = IsULong();
3015 return r;
3016}
3017
3019
3028bool wxJSONValue::IsInt64() const {
3029 wxJSONRefData* data = GetRefData();
3030 wxJSON_ASSERT(data);
3031 bool r = false;
3032 if (data->m_type == wxJSONTYPE_INT) {
3033 r = true;
3034 }
3035 return r;
3036}
3037
3039
3048bool wxJSONValue::IsUInt64() const {
3049 wxJSONRefData* data = GetRefData();
3050 wxJSON_ASSERT(data);
3051 bool r = false;
3052 if (data->m_type == wxJSONTYPE_UINT) {
3053 r = true;
3054 }
3055 return r;
3056}
3057
3059
3070wxInt32 wxJSONValue::AsInt32() const {
3071 wxInt32 i;
3072 i = (wxInt32)AsLong();
3073 return i;
3074}
3075
3077
3088wxUint32 wxJSONValue::AsUInt32() const {
3089 wxUint32 ui;
3090 ui = (wxUint32)AsULong();
3091 return ui;
3092}
3093
3095
3108wxInt64 wxJSONValue::AsInt64() const {
3109 wxJSONRefData* data = GetRefData();
3110 wxJSON_ASSERT(data);
3111 wxInt64 i64 = data->m_value.m_valInt64;
3112
3113 wxJSON_ASSERT(IsInt64()); // exapnds only in debug builds
3114 return i64;
3115}
3116
3118
3131wxUint64 wxJSONValue::AsUInt64() const {
3132 wxJSONRefData* data = GetRefData();
3133 wxJSON_ASSERT(data);
3134 wxUint64 ui64 = data->m_value.m_valUInt64;
3135
3136 wxJSON_ASSERT(IsUInt64()); // exapnds only in debug builds
3137 return ui64;
3138}
3139
3140bool wxJSONValue::AsInt32(wxInt32& i32) const {
3141 bool r = IsInt32();
3142 if (r) {
3143 i32 = AsInt32();
3144 }
3145 return r;
3146}
3147
3148bool wxJSONValue::AsUInt32(wxUint32& ui32) const {
3149 bool r = IsUInt32();
3150 if (r) {
3151 ui32 = AsUInt32();
3152 }
3153 return r;
3154}
3155
3156bool wxJSONValue::AsInt64(wxInt64& i64) const {
3157 bool r = IsInt64();
3158 if (r) {
3159 i64 = AsInt64();
3160 }
3161 return r;
3162}
3163
3164bool wxJSONValue::AsUInt64(wxUint64& ui64) const {
3165 bool r = IsUInt64();
3166 if (r) {
3167 ui64 = AsUInt64();
3168 }
3169 return r;
3170}
3171
3173wxJSONValue& wxJSONValue::Append(wxInt64 i) {
3174 wxJSONValue v(i);
3175 wxJSONValue& r = Append(v);
3176 return r;
3177}
3178
3180wxJSONValue& wxJSONValue::Append(wxUint64 ui) {
3181 wxJSONValue v(ui);
3182 wxJSONValue& r = Append(v);
3183 return r;
3184}
3185
3188 wxJSONRefData* data = SetType(wxJSONTYPE_INT);
3189 data->m_value.VAL_INT = i;
3190 return *this;
3191}
3192
3194wxJSONValue& wxJSONValue::operator=(wxUint64 ui) {
3195 wxJSONRefData* data = SetType(wxJSONTYPE_UINT);
3196 data->m_value.VAL_UINT = ui;
3197 return *this;
3198}
3199
3200#endif // defined( wxJSON_64BIT_INT )
3201
3202/*
3203{
3204}
3205*/
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:2126
void Ref(const wxJSONValue &clone)
Increments the referenced data counter.
Definition jsonval.cpp:2638
wxArrayString GetMemberNames() const
Return the array of keys of this JSON object.
Definition jsonval.cpp:1357
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:2670
bool Remove(int index)
Remove the item at the specified index or key.
Definition jsonval.cpp:1551
int AddComment(const wxString &str, int position=wxJSONVALUE_COMMENT_DEFAULT)
Add a comment to this JSON value object.
Definition jsonval.cpp:2346
virtual wxJSONRefData * CloneRefData(const wxJSONRefData *data) const
Make a copy of the referenced data.
Definition jsonval.cpp:2698
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:2003
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:997
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:1332
int GetCommentCount() const
Return the number of comment strings.
Definition jsonval.cpp:2441
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
Definition jsonval.cpp:1298
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:2803
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:1878
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:2743
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:2658
wxJSONValue * Find(unsigned index) const
Find an element.
Definition jsonval.cpp:1906
void DeepCopy(const wxJSONValue &other)
Do a deep copy of the other object.
Definition jsonval.cpp:2677
static wxMemoryBuffer ArrayToMemoryBuff(const wxJSONValue &value)
Converts an array of INTs to a memory buffer.
Definition jsonval.cpp:2943
wxJSONValue ItemAt(unsigned index) const
Return the item at the specified index.
Definition jsonval.cpp:1657
wxJSONRefData * COW()
Make sure the referenced data is unique.
Definition jsonval.cpp:2756
wxString GetComment(int idx=-1) const
Return a comment string.
Definition jsonval.cpp:2424
void SetRefData(wxJSONRefData *data)
Set the pointer to the referenced data.
Definition jsonval.cpp:2635
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:2466
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:1263
const wxChar * AsCString() const
Return the stored value as a pointer to a static C string.
Definition jsonval.cpp:947
wxJSONValue & operator[](unsigned index)
Return the item at the specified index.
Definition jsonval.cpp:1707
static int CompareMemoryBuff(const wxMemoryBuffer &buff1, const wxMemoryBuffer &buff2)
Compares two memory buffer objects.
Definition jsonval.cpp:2887
wxJSONValue & Append(const wxJSONValue &value)
Append the specified value in the array.
Definition jsonval.cpp:1385
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:976
unsigned short AsUShort() const
Returns the value as a unsigned short integer.
Definition jsonval.cpp:1062
void AllocExclusive()
Makes a private copy of the referenced data.
Definition jsonval.cpp:2768
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:1584
int GetLineNo() const
Return the line number of this JSON value object.
Definition jsonval.cpp:2617
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:1040
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:500
void SetLineNo(int num)
Set the line number of this JSON value object.
Definition jsonval.cpp:2628
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:1019
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:2535
int GetCommentPos() const
Return the comment position.
Definition jsonval.cpp:2451
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:1747
wxJSONValue & Item(unsigned index)
Return the item at the specified index.
Definition jsonval.cpp:1602
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:1281
wxMemoryBuffer AsMemoryBuff() const
Returns the value as a memory buffer.
Definition jsonval.cpp:1215
const wxArrayString & GetCommentArray() const
Get the comment string's array.
Definition jsonval.cpp:2458
wxJSONRefData * GetRefData() const
Return the pointer to the referenced data structure.
Definition jsonval.cpp:2684
static wxString TypeToString(wxJSONType type)
Return a string description of the type.
Definition jsonval.cpp:1954