20#define wxDEBUG_LEVEL 0
32#include <wx/arrimpl.cpp>
36WX_DEFINE_OBJARRAY(wxJSONInternalArray);
38#if wxCHECK_VERSION(3, 0, 0)
39#define compatibleLongLongFmtSpec _T(wxLongLongFmtSpec)
41#define compatibleLongLongFmtSpec wxLongLongFmtSpec
47static const wxChar* traceMask =
"jsonval";
48static const wxChar* compareTraceMask =
"sameas";
49static const wxChar* cowTraceMask = _T(
"traceCOW" );
69#if defined(WXJSON_USE_VALUE_COUNTER)
71int wxJSONRefData::sm_progr = 1;
80#if defined(WXJSON_USE_VALUE_COUNTER)
83 wxLogTrace(traceMask,
"(%s) JSON refData ctor progr=%d", __PRETTY_FUNCTION__,
89wxJSONRefData::~wxJSONRefData() {
96int wxJSONRefData::GetRefCount()
const {
return m_refCount; }
163#if defined(WXJSON_USE_VALUE_COUNTER)
165int wxJSONValue::sm_progr = 1;
188 Init(wxJSONTYPE_NULL);
213 data->m_commentPos = wxJSONVALUE_COMMENT_BEFORE;
217#if defined(WXJSON_USE_VALUE_COUNTER)
220 wxLogTrace(cowTraceMask,
"(%s) Init a new object progr=%d",
221 __PRETTY_FUNCTION__, m_progr);
240 data->m_value.VAL_INT = i;
252 data->m_value.VAL_UINT = ui;
264 data->m_value.VAL_INT = i;
276 data->m_value.VAL_UINT = ui;
286 data->m_value.m_valBool = b;
296 data->m_value.m_valDouble = d;
306#if !defined(WXJSON_USE_CSTRING)
307 data->m_type = wxJSONTYPE_STRING;
308 data->m_valString.assign(str);
310 data->m_value.m_valCString = str;
321 data->m_valString.assign(str);
331 data->m_value.VAL_INT = l;
341 data->m_value.VAL_UINT = ul;
356 data->m_memBuff =
new wxMemoryBuffer();
357 const void* ptr = buff.GetData();
358 size_t buffLen = buff.GetDataLen();
360 data->m_memBuff->AppendData(ptr, buffLen);
375 if (data != 0 && len > 0) {
376 data->m_memBuff =
new wxMemoryBuffer();
377 data->m_memBuff->AppendData(buff, len);
397#if defined(WXJSON_USE_VALUE_COUNTER)
400 wxLogTrace(cowTraceMask,
"(%s) Copy ctor - progr=%d other progr=%d",
401 __PRETTY_FUNCTION__, m_progr, other.m_progr);
463 wxJSONType type = wxJSONTYPE_INVALID;
472 if (data->m_value.VAL_INT >= SHORT_MIN &&
473 data->m_value.VAL_INT <= SHORT_MAX) {
474 type = wxJSONTYPE_SHORT;
477 else if (data->m_value.VAL_INT >= LONG_MIN &&
478 data->m_value.VAL_INT <= LONG_MAX) {
479 type = wxJSONTYPE_LONG;
481 type = wxJSONTYPE_INT64;
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;
491 type = wxJSONTYPE_UINT64;
506 if (type == wxJSONTYPE_NULL) {
527 if (type != wxJSONTYPE_INVALID) {
559 if (type == wxJSONTYPE_SHORT) {
561 }
else if (type == wxJSONTYPE_LONG) {
563 if (INT_MAX == LONG_MAX) {
587 if (type == wxJSONTYPE_SHORT) {
619 if (type == wxJSONTYPE_USHORT) {
621 }
else if (type == wxJSONTYPE_ULONG) {
622 if (INT_MAX == LONG_MAX) {
646 if (type == wxJSONTYPE_USHORT) {
669 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_SHORT) {
693 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_USHORT) {
703 if (type == wxJSONTYPE_BOOL) {
713 if (type == wxJSONTYPE_DOUBLE) {
723 if (type == wxJSONTYPE_STRING) {
742 if (type == wxJSONTYPE_CSTRING) {
752 if (type == wxJSONTYPE_ARRAY) {
762 if (type == wxJSONTYPE_OBJECT) {
772 if (type == wxJSONTYPE_MEMORYBUFF) {
795 int i = (int)data->m_value.VAL_INT;
797 wxJSON_ASSERT(
IsInt());
815 wxJSON_ASSERT(data->m_type == wxJSONTYPE_BOOL);
816 return data->m_value.m_valBool;
833 double d = data->m_value.m_valDouble;
880 switch (data->m_type) {
881 case wxJSONTYPE_STRING:
882 s.assign(data->m_valString);
884 case wxJSONTYPE_CSTRING:
885 s.assign(data->m_value.m_valCString);
888#if defined(wxJSON_64BIT_INT)
889 s.Printf(
"%" compatibleLongLongFmtSpec
"i", data->m_value.m_valInt64);
891 s.Printf(
"%ld", data->m_value.m_valLong);
894 case wxJSONTYPE_UINT:
895#if defined(wxJSON_64BIT_INT)
896 s.Printf(
"%" compatibleLongLongFmtSpec
"u", data->m_value.m_valUInt64);
898 s.Printf(
"%lu", data->m_value.m_valULong);
901 case wxJSONTYPE_DOUBLE:
902 s.Printf(
"%.10g", data->m_value.m_valDouble);
904 case wxJSONTYPE_BOOL:
905 s.assign((data->m_value.m_valBool ?
"true" :
"false"));
907 case wxJSONTYPE_NULL:
908 s.assign(_T(
"null"));
910 case wxJSONTYPE_INVALID:
911 s.assign(_T(
"<invalid>"));
913 case wxJSONTYPE_ARRAY:
914 s.Printf(
"[%d]", size);
916 case wxJSONTYPE_OBJECT:
917 s.Printf(
"{%d}", size);
919 case wxJSONTYPE_MEMORYBUFF:
923 s.assign(_T(
"wxJSONValue::AsString(): Unknown JSON type \'"));
925 s.append(_T(
"\'" ));
949 const wxChar* s =
nullptr;
952 switch (data->m_type) {
953 case wxJSONTYPE_CSTRING:
954 s = data->m_value.m_valCString;
956 case wxJSONTYPE_STRING:
957 s = data->m_valString.c_str();
980 unsigned int ui = (unsigned)data->m_value.VAL_UINT;
1001 wxJSON_ASSERT(data);
1002 l = (long)data->m_value.VAL_INT;
1022 wxJSON_ASSERT(data);
1023 unsigned long int ul = (
unsigned long)data->m_value.VAL_UINT;
1044 wxJSON_ASSERT(data);
1045 i = (short)data->m_value.VAL_INT;
1066 wxJSON_ASSERT(data);
1067 ui = (
unsigned short)data->m_value.VAL_UINT;
1218 wxJSON_ASSERT(data);
1219 wxMemoryBuffer buff;
1220 if (data->m_memBuff) {
1221 buff = *(data->m_memBuff);
1266 wxJSON_ASSERT(data);
1268 const wxJSONInternalMap* v =
nullptr;
1269 if (data->m_type == wxJSONTYPE_OBJECT) {
1270 v = &(data->m_valMap);
1284 wxJSON_ASSERT(data);
1286 const wxJSONInternalArray* v =
nullptr;
1287 if (data->m_type == wxJSONTYPE_ARRAY) {
1288 v = &(data->m_valArray);
1302 if (index < (
unsigned)size) {
1315 wxJSON_ASSERT(data);
1317 if (data && data->m_type == wxJSONTYPE_OBJECT) {
1318 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1319 if (it != data->m_valMap.end()) {
1335 wxJSON_ASSERT(data);
1338 if (data->m_type == wxJSONTYPE_ARRAY) {
1339 size = (int)data->m_valArray.GetCount();
1341 if (data->m_type == wxJSONTYPE_OBJECT) {
1342 size = (int)data->m_valMap.size();
1360 wxJSON_ASSERT(data);
1361 wxJSON_ASSERT(data->m_type == wxJSONTYPE_OBJECT);
1364 if (data->m_type == wxJSONTYPE_OBJECT) {
1365 wxJSONInternalMap::iterator it;
1366 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
1388 wxJSON_ASSERT(data);
1389 if (data->m_type != wxJSONTYPE_ARRAY) {
1396 data->m_valArray.Add(value);
1494bool wxJSONValue::Cat(
const wxString& str) {
1496 wxJSON_ASSERT(data);
1499 if (data->m_type == wxJSONTYPE_STRING) {
1501 wxJSON_ASSERT(data);
1502 data->m_valString.append(str);
1515bool wxJSONValue::Cat(
const wxMemoryBuffer& buff) {
1517 wxJSON_ASSERT(data);
1520 if (data->m_type == wxJSONTYPE_MEMORYBUFF) {
1522 wxJSON_ASSERT(data);
1523 data->m_memBuff->AppendData(buff.GetData(), buff.GetDataLen());
1530bool wxJSONValue::Cat(
const wxChar* str) {
1532 wxJSON_ASSERT(data);
1535 if (data->m_type == wxJSONTYPE_STRING) {
1537 wxJSON_ASSERT(data);
1538 data->m_valString.append(str);
1554 wxJSON_ASSERT(data);
1557 if (data->m_type == wxJSONTYPE_ARRAY) {
1558 data->m_valArray.RemoveAt(index);
1567 wxJSON_ASSERT(data);
1570 if (data->m_type == wxJSONTYPE_OBJECT) {
1571 wxJSONInternalMap::size_type count = data->m_valMap.erase(key);
1605 wxJSON_ASSERT(data);
1607 if (data->m_type != wxJSONTYPE_ARRAY) {
1608 data =
SetType(wxJSONTYPE_ARRAY);
1611 wxJSON_ASSERT(size >= 0);
1614 if (index >= (
unsigned)size) {
1616 int missing = index - size + 1;
1617 data->m_valArray.Add(v, missing);
1619 return data->m_valArray.Item(index);
1632 wxLogTrace(traceMask,
"(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1634#if !wxCHECK_VERSION(2, 9, 0)
1635 wxLogTrace(traceMask,
"(%s) actual object: %s", __PRETTY_FUNCTION__,
1640 wxJSON_ASSERT(data);
1642 if (data->m_type != wxJSONTYPE_OBJECT) {
1644 data =
SetType(wxJSONTYPE_OBJECT);
1645 return data->m_valMap[key];
1647 wxLogTrace(traceMask,
"(%s) searching key \'%s' in the actual object",
1648 __PRETTY_FUNCTION__, key.c_str());
1649 return data->m_valMap[key];
1660 wxJSON_ASSERT(data);
1663 if (data->m_type == wxJSONTYPE_ARRAY) {
1665 wxJSON_ASSERT(size >= 0);
1666 if (index < (
unsigned)size) {
1667 v = data->m_valArray.
Item(index);
1680 wxLogTrace(traceMask,
"(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1682 wxLogTrace(traceMask,
"(%s) actual object: %s", __PRETTY_FUNCTION__,
1686 wxJSON_ASSERT(data);
1689 if (data->m_type == wxJSONTYPE_OBJECT) {
1690 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1691 if (it != data->m_valMap.end()) {
1750 data->m_value.VAL_INT = i;
1757 data->m_value.m_valBool = b;
1764 data->m_value.VAL_UINT = ui;
1771 data->m_value.VAL_INT = l;
1778 data->m_value.VAL_UINT = ul;
1785 data->m_value.VAL_INT = i;
1792 data->m_value.VAL_UINT = ui;
1799 data->m_value.m_valDouble = d;
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);
1817 data->m_valString.assign(str);
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);
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()) {
1909 wxJSON_ASSERT(data);
1913 if (data->m_type == wxJSONTYPE_ARRAY) {
1914 size_t size = data->m_valArray.GetCount();
1916 vp = &(data->m_valArray.Item(index));
1931 wxJSON_ASSERT(data);
1935 if (data->m_type == wxJSONTYPE_OBJECT) {
1936 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1937 if (it != data->m_valMap.end()) {
1956 static const wxChar* str[] = {
1957 _T(
"wxJSONTYPE_INVALID" ),
1958 _T(
"wxJSONTYPE_NULL" ),
1959 _T(
"wxJSONTYPE_INT" ),
1960 _T(
"wxJSONTYPE_UINT" ),
1961 _T(
"wxJSONTYPE_DOUBLE" ),
1962 _T(
"wxJSONTYPE_STRING" ),
1963 _T(
"wxJSONTYPE_CSTRING" ),
1964 _T(
"wxJSONTYPE_BOOL" ),
1965 _T(
"wxJSONTYPE_ARRAY" ),
1966 _T(
"wxJSONTYPE_OBJECT" ),
1967 _T(
"wxJSONTYPE_LONG" ),
1968 _T(
"wxJSONTYPE_INT64" ),
1969 _T(
"wxJSONTYPE_ULONG" ),
1970 _T(
"wxJSONTYPE_UINT64" ),
1971 _T(
"wxJSONTYPE_SHORT" ),
1972 _T(
"wxJSONTYPE_USHORT" ),
1973 _T(
"wxJSONTYPE_MEMORYBUFF" ),
1977 int idx = (int)type;
1978 if (idx >= 0 && idx < 17) {
2006 wxJSON_ASSERT(data);
2012 s.append(indent,
' ');
2017#if defined(WXJSON_USE_VALUE_COUNTER)
2018 s1.Printf(
"Object: Progr=%d Type=%s Size=%d comments=%d\n", m_progr,
2020 s2.Printf(
" : RefData=%p Progr=%d Num shares=%d\n", data, data->m_progr,
2021 data->GetRefCount());
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());
2029 s.append(indent,
' ');
2039 const wxJSONInternalMap* map;
2042 wxJSONInternalMap::const_iterator it;
2044 case wxJSONTYPE_OBJECT:
2047 for (it = map->begin(); it != map->end(); ++it) {
2049 sub = v.
Dump(
true, indent);
2053 case wxJSONTYPE_ARRAY:
2055 for (
int i = 0; i < size; i++) {
2058 sub = v->
Dump(
true, indent);
2077 wxJSON_ASSERT(data);
2080#if defined(WXJSON_USE_VALUE_CONTER)
2081 s.Printf(
"Object: Progr=%d Type=%s Size=%d comments=%d\n", data->m_progr,
2083 data->m_comments.GetCount());
2085 s.Printf(
"Object: Type=%s Size=%d comments=%d\n",
2087 data->m_comments.GetCount());
2089 if (data->m_type == wxJSONTYPE_OBJECT) {
2091 for (
unsigned int i = 0; i < arr.size(); i++) {
2092 s.append(
" Member name: ");
2133 wxJSONInternalMap::const_iterator it;
2139 if (data == otherData) {
2140 wxLogTrace(compareTraceMask,
2141 "(%s) objects share the same referenced data - r=TRUE",
2142 __PRETTY_FUNCTION__);
2148 if (data->m_type != otherData->
m_type) {
2152 switch (data->m_type) {
2153 case wxJSONTYPE_INT:
2154 if (otherData->
m_type == wxJSONTYPE_UINT) {
2157 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2158 (data->m_value.VAL_UINT == otherData->
m_value.VAL_UINT)) {
2161 }
else if (otherData->
m_type == wxJSONTYPE_DOUBLE) {
2162 val = data->m_value.VAL_INT;
2163 if (val == otherData->
m_value.m_valDouble) {
2170 case wxJSONTYPE_UINT:
2171 if (otherData->
m_type == wxJSONTYPE_INT) {
2174 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2175 (data->m_value.VAL_UINT == otherData->
m_value.VAL_UINT)) {
2178 }
else if (otherData->
m_type == wxJSONTYPE_DOUBLE) {
2179 val = data->m_value.VAL_UINT;
2180 if (val == otherData->
m_value.m_valDouble) {
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) {
2193 }
else if (otherData->
m_type == wxJSONTYPE_UINT) {
2194 val = otherData->
m_value.VAL_UINT;
2195 if (val == data->m_value.m_valDouble) {
2218 switch (data->m_type) {
2219 case wxJSONTYPE_INVALID:
2220 case wxJSONTYPE_NULL:
2223 case wxJSONTYPE_INT:
2224 if (data->m_value.VAL_INT != otherData->
m_value.VAL_INT) {
2228 case wxJSONTYPE_UINT:
2229 if (data->m_value.VAL_UINT != otherData->
m_value.VAL_UINT) {
2233 case wxJSONTYPE_DOUBLE:
2234 if (data->m_value.m_valDouble != otherData->
m_value.m_valDouble) {
2238 case wxJSONTYPE_CSTRING:
2239 s1 = wxString(data->m_value.m_valCString);
2240 s2 = wxString(otherData->
m_value.m_valCString);
2245 case wxJSONTYPE_BOOL:
2246 if (data->m_value.m_valBool != otherData->
m_value.m_valBool) {
2250 case wxJSONTYPE_STRING:
2251 if (data->m_valString != otherData->
m_valString) {
2255 case wxJSONTYPE_MEMORYBUFF:
2262 case wxJSONTYPE_ARRAY:
2264 wxLogTrace(compareTraceMask,
"(%s) Comparing an array object - size=%d",
2265 __PRETTY_FUNCTION__, size);
2267 if (size != other.
Size()) {
2268 wxLogTrace(compareTraceMask,
"(%s) Sizes does not match",
2269 __PRETTY_FUNCTION__);
2274 for (
int i = 0; i < size; i++) {
2275 wxLogTrace(compareTraceMask,
"(%s) Comparing array element=%d",
2276 __PRETTY_FUNCTION__, i);
2285 case wxJSONTYPE_OBJECT:
2287 wxLogTrace(compareTraceMask,
"(%s) Comparing a map obejct - size=%d",
2288 __PRETTY_FUNCTION__, size);
2290 if (size != other.
Size()) {
2291 wxLogTrace(compareTraceMask,
2292 "(%s) Comparison failed - sizes does not match",
2293 __PRETTY_FUNCTION__);
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());
2303 bool isSame = it->second.
IsSameAs(otherVal);
2305 wxLogTrace(compareTraceMask,
2306 "(%s) Comparison failed for the last object",
2307 __PRETTY_FUNCTION__);
2314 wxFAIL_MSG(
"wxJSONValue::IsSameAs() unexpected wxJSONType");
2347 wxJSON_ASSERT(data);
2349 wxLogTrace(traceMask,
"(%s) comment=%s", __PRETTY_FUNCTION__, str.c_str());
2351 int len = str.length();
2353 wxLogTrace(traceMask,
" error: len < 2");
2356 if (str[0] !=
'/') {
2357 wxLogTrace(traceMask,
" error: does not start with\'/\'");
2360 if (str[1] ==
'/') {
2361 wxLogTrace(traceMask, _T(
" C++ comment" ));
2362 if (str.GetChar(len - 1) !=
'\n') {
2364 temp.append(1,
'\n');
2365 data->m_comments.Add(temp);
2366 wxLogTrace(traceMask,
" C++ comment: LF added");
2368 data->m_comments.Add(str);
2370 r = data->m_comments.size();
2371 }
else if (str[1] ==
2373 wxLogTrace(traceMask,
" C-style comment");
2374 int lastPos = len - 1;
2375 wxChar ch = str.GetChar(lastPos);
2377 while (ch ==
' ' || ch ==
'\n' || ch ==
'\t') {
2379 ch = str.GetChar(lastPos);
2381 if (str.GetChar(lastPos) ==
'/' && str.GetChar(lastPos - 1) ==
'*') {
2382 data->m_comments.Add(str);
2383 r = data->m_comments.size();
2386 wxLogTrace(traceMask,
" error: is not a valid comment string");
2390 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2391 data->m_commentPos = position;
2404 int siz = comments.GetCount();
2406 for (
int i = 0; i < siz; i++) {
2424 wxJSON_ASSERT(data);
2427 int size = data->m_comments.GetCount();
2429 for (
int i = 0; i < size; i++) {
2430 s.append(data->m_comments[i]);
2432 }
else if (idx < size) {
2433 s = data->m_comments[idx];
2441 wxJSON_ASSERT(data);
2443 int d = data->m_comments.GetCount();
2444 wxLogTrace(traceMask,
"(%s) comment count=%d", __PRETTY_FUNCTION__, d);
2451 wxJSON_ASSERT(data);
2452 return data->m_commentPos;
2458 wxJSON_ASSERT(data);
2460 return data->m_comments;
2466 wxJSON_ASSERT(data);
2468 data->m_comments.clear();
2535 wxJSONType oldType =
GetType();
2538 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2539 (type <= wxJSONTYPE_MEMORYBUFF));
2540 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2541 type = wxJSONTYPE_INVALID;
2554 if (type == oldType) {
2560 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2561 type == wxJSONTYPE_SHORT) {
2562 type = wxJSONTYPE_INT;
2564 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2565 type == wxJSONTYPE_USHORT) {
2566 type = wxJSONTYPE_UINT;
2569 wxJSON_ASSERT(data);
2570 data->m_type = type;
2574 case wxJSONTYPE_STRING:
2575 data->m_valString.clear();
2577 case wxJSONTYPE_ARRAY:
2578 data->m_valArray.Clear();
2580 case wxJSONTYPE_OBJECT:
2581 data->m_valMap.clear();
2583 case wxJSONTYPE_MEMORYBUFF:
2585 if (data->m_memBuff) {
2586 delete data->m_memBuff;
2587 data->m_memBuff = 0;
2597#if !defined(WXJSON_USE_CSTRING)
2598 if (data->m_type == wxJSONTYPE_CSTRING) {
2599 data->m_type = wxJSONTYPE_STRING;
2628 wxJSON_ASSERT(data);
2629 data->m_lineNo = num;
2697 wxJSON_ASSERT(otherData);
2707 data->m_type = other->
m_type;
2708 data->m_value = other->
m_value;
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);
2728 wxLogTrace(cowTraceMask,
"(%s) CloneRefData() PROGR: other=%d data=%d",
2729 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2743 data->m_type = wxJSONTYPE_INVALID;
2756 wxLogTrace(cowTraceMask,
"(%s) COW() START data=%p data->m_count=%d",
2757 __PRETTY_FUNCTION__, data, data->GetRefCount());
2760 wxLogTrace(cowTraceMask,
"(%s) COW() END data=%p data->m_count=%d",
2761 __PRETTY_FUNCTION__, data, data->GetRefCount());
2769 }
else if (
m_refData->GetRefCount() > 1) {
2780 "wxObject::AllocExclusive() failed.");
2803 size_t buffLen = buff.GetDataLen();
2804 void* ptr = buff.GetData();
2833 size_t buffLen = actualLen;
2834 if (buffLen == (
size_t)-1) {
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;
2886 const wxMemoryBuffer& buff2) {
2888 size_t buff1Len = buff1.GetDataLen();
2889 size_t buff2Len = buff2.GetDataLen();
2890 if (buff1Len > buff2Len) {
2892 }
else if (buff1Len < buff2Len) {
2895 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2913 const void* buff2) {
2915 size_t buff1Len = buff1.GetDataLen();
2916 r = memcmp(buff1.GetData(), buff2, buff1Len);
2942 wxMemoryBuffer buff;
2943 if (value.IsArray()) {
2944 int len = value.Size();
2945 for (
int i = 0; i < len; i++) {
2950 bool r = value.ItemAt(i).AsShort(
byte);
2951 if (r && (
byte >= 0 &&
byte <= 255)) {
2952 c = (
unsigned char)
byte;
2966#if defined(wxJSON_64BIT_INT)
2972 wxJSON_ASSERT(data);
2974 data->m_value.VAL_INT = i;
2982 wxJSON_ASSERT(data);
2984 data->m_value.VAL_UINT = ui;
2997bool wxJSONValue::IsInt32()
const {
3011bool wxJSONValue::IsUInt32()
const {
3026bool wxJSONValue::IsInt64()
const {
3028 wxJSON_ASSERT(data);
3030 if (data->m_type == wxJSONTYPE_INT) {
3046bool wxJSONValue::IsUInt64()
const {
3048 wxJSON_ASSERT(data);
3050 if (data->m_type == wxJSONTYPE_UINT) {
3068wxInt32 wxJSONValue::AsInt32()
const {
3086wxUint32 wxJSONValue::AsUInt32()
const {
3106wxInt64 wxJSONValue::AsInt64()
const {
3108 wxJSON_ASSERT(data);
3109 wxInt64 i64 = data->m_value.m_valInt64;
3111 wxJSON_ASSERT(IsInt64());
3129wxUint64 wxJSONValue::AsUInt64()
const {
3131 wxJSON_ASSERT(data);
3132 wxUint64 ui64 = data->m_value.m_valUInt64;
3134 wxJSON_ASSERT(IsUInt64());
3138bool wxJSONValue::AsInt32(wxInt32& i32)
const {
3146bool wxJSONValue::AsUInt32(wxUint32& ui32)
const {
3147 bool r = IsUInt32();
3154bool wxJSONValue::AsInt64(wxInt64& i64)
const {
3162bool wxJSONValue::AsUInt64(wxUint64& ui64)
const {
3163 bool r = IsUInt64();
3187 data->m_value.VAL_INT = i;
3194 data->m_value.VAL_UINT = ui;
The reference counted JSON value data (internal use).
wxMemoryBuffer * m_memBuff
The pointer to the memory buffer object.
wxJSONInternalMap m_valMap
The JSON object value.
int m_commentPos
The position of the comment line(s), if any.
int m_refCount
the references count
wxJSONInternalArray m_valArray
The JSON array value.
wxJSONType m_type
The actual type of the value held by this object.
int m_lineNo
The line number when this value was read.
wxJSONRefData()
Constructor.
wxString m_valString
The JSON string value.
wxJSONValueHolder m_value
The JSON value held by this object.
wxArrayString m_comments
The array of comment lines; may be empty.
The JSON value class implementation.
bool IsSameAs(const wxJSONValue &other) const
The comparison function.
void Ref(const wxJSONValue &clone)
Increments the referenced data counter.
wxArrayString GetMemberNames() const
Return the array of keys of this JSON object.
bool IsArray() const
Return TRUE if the type of the value stored is an array type.
bool IsCString() const
Return TRUE if the type of the value stored is a pointer to a static C string.
void UnShare()
Makes an exclusive copy of shared data.
bool Remove(int index)
Remove the item at the specified index or key.
int AddComment(const wxString &str, int position=wxJSONVALUE_COMMENT_DEFAULT)
Add a comment to this JSON value object.
virtual wxJSONRefData * CloneRefData(const wxJSONRefData *data) const
Make a copy of the referenced data.
bool IsUInt() const
Return TRUE if the type of the value stored is a unsigned int.
wxString Dump(bool deep=false, int mode=0) const
Returns informations about the object.
wxJSONRefData * Init(wxJSONType type)
Initialize the JSON value class.
long int AsLong() const
Returns the value as a long integer.
bool IsLong() const
Return TRUE if the stored value is an integer which fits in a long int.
int Size() const
Return the size of the array or map stored in this value.
int GetCommentCount() const
Return the number of comment strings.
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
bool IsDouble() const
Return TRUE if the type of the value stored is a double.
bool IsInt() const
Return TRUE if the type of the value stored is integer.
static wxString MemoryBuffToString(const wxMemoryBuffer &buff, size_t len=-1)
Convert memory buffer object to a string representation.
bool IsShort() const
Return TRUE if the type of the value stored is 16-bit integer.
wxJSONValue Get(const wxString &key, const wxJSONValue &defaultValue) const
Return a value or a default value.
double AsDouble() const
Return the stored value as a double.
virtual wxJSONRefData * CreateRefData() const
Create a new data structure.
wxJSONType GetType() const
Return the type of the value stored in the object.
void UnRef()
Unreferences the shared data.
wxJSONValue * Find(unsigned index) const
Find an element.
void DeepCopy(const wxJSONValue &other)
Do a deep copy of the other object.
static wxMemoryBuffer ArrayToMemoryBuff(const wxJSONValue &value)
Converts an array of INTs to a memory buffer.
wxJSONValue ItemAt(unsigned index) const
Return the item at the specified index.
wxJSONRefData * COW()
Make sure the referenced data is unique.
wxString GetComment(int idx=-1) const
Return a comment string.
void SetRefData(wxJSONRefData *data)
Set the pointer to the referenced data.
bool IsString() const
Return TRUE if the type of the value stored is a wxString object.
void ClearComments()
Clear all comment strings.
bool IsUShort() const
Return TRUE if the type of the value stored is a unsigned short.
const wxJSONInternalMap * AsMap() const
Return the stored value as a map object.
const wxChar * AsCString() const
Return the stored value as a pointer to a static C string.
wxJSONValue & operator[](unsigned index)
Return the item at the specified index.
static int CompareMemoryBuff(const wxMemoryBuffer &buff1, const wxMemoryBuffer &buff2)
Compares two memory buffer objects.
wxJSONValue & Append(const wxJSONValue &value)
Append the specified value in the array.
bool IsBool() const
Return TRUE if the type of the value stored is a boolean.
unsigned int AsUInt() const
Return the stored value as a unsigned int.
unsigned short AsUShort() const
Returns the value as a unsigned short integer.
void AllocExclusive()
Makes a private copy of the referenced data.
wxJSONValue()
Constructors.
bool IsULong() const
Return TRUE if the stored value is an integer which fits in a unsigned long int.
wxString AsString() const
Return the stored value as a wxWidget's string.
void Clear()
Clear the object value.
int GetLineNo() const
Return the line number of this JSON value object.
bool IsValid() const
Return TRUE if the value stored is valid.
bool IsMemoryBuff() const
Return TRUE if the type of this value is a binary memory buffer.
short AsShort() const
Returns the value as a short integer.
wxString GetInfo() const
Returns informations about the object.
bool IsNull() const
Return TRUE if the type of the value is wxJSONTYPE_NULL.
void SetLineNo(int num)
Set the line number of this JSON value object.
bool IsObject() const
Return TRUE if the type of this value is a key/value map.
unsigned long AsULong() const
Returns the value as a unsigned long integer.
bool AsBool() const
Return the stored value as a boolean.
wxJSONRefData * SetType(wxJSONType type)
Set the type of the stored value.
int GetCommentPos() const
Return the comment position.
wxJSONRefData * m_refData
the referenced data
virtual ~wxJSONValue()
Dtor - calls UnRef().
wxJSONValue & operator=(int i)
Assign the specified value to this object replacing the old value.
wxJSONValue & Item(unsigned index)
Return the item at the specified index.
int AsInt() const
Return the stored value as an integer.
const wxJSONInternalArray * AsArray() const
Return the stored value as an array object.
wxMemoryBuffer AsMemoryBuff() const
Returns the value as a memory buffer.
const wxArrayString & GetCommentArray() const
Get the comment string's array.
wxJSONRefData * GetRefData() const
Return the pointer to the referenced data structure.
static wxString TypeToString(wxJSONType type)
Return a string description of the type.