17#define wxDEBUG_LEVEL 0
29#include <wx/arrimpl.cpp>
31#include <wx/jsonval.h>
33WX_DEFINE_OBJARRAY(wxJSONInternalArray);
35#if wxCHECK_VERSION(3, 0, 0)
36#define compatibleLongLongFmtSpec _T(wxLongLongFmtSpec)
38#define compatibleLongLongFmtSpec wxLongLongFmtSpec
44static const wxChar* traceMask =
"jsonval";
45static const wxChar* compareTraceMask =
"sameas";
46static const wxChar* cowTraceMask = _T(
"traceCOW" );
66#if defined(WXJSON_USE_VALUE_COUNTER)
68int wxJSONRefData::sm_progr = 1;
77#if defined(WXJSON_USE_VALUE_COUNTER)
80 wxLogTrace(traceMask,
"(%s) JSON refData ctor progr=%d", __PRETTY_FUNCTION__,
86wxJSONRefData::~wxJSONRefData() {
93int wxJSONRefData::GetRefCount()
const {
return m_refCount; }
160#if defined(WXJSON_USE_VALUE_COUNTER)
162int wxJSONValue::sm_progr = 1;
185 Init(wxJSONTYPE_NULL);
210 data->m_commentPos = wxJSONVALUE_COMMENT_BEFORE;
214#if defined(WXJSON_USE_VALUE_COUNTER)
217 wxLogTrace(cowTraceMask,
"(%s) Init a new object progr=%d",
218 __PRETTY_FUNCTION__, m_progr);
237 data->m_value.VAL_INT = i;
249 data->m_value.VAL_UINT = ui;
261 data->m_value.VAL_INT = i;
273 data->m_value.VAL_UINT = ui;
283 data->m_value.m_valBool = b;
293 data->m_value.m_valDouble = d;
303#if !defined(WXJSON_USE_CSTRING)
304 data->m_type = wxJSONTYPE_STRING;
305 data->m_valString.assign(str);
307 data->m_value.m_valCString = str;
318 data->m_valString.assign(str);
328 data->m_value.VAL_INT = l;
338 data->m_value.VAL_UINT = ul;
353 data->m_memBuff =
new wxMemoryBuffer();
354 const void* ptr = buff.GetData();
355 size_t buffLen = buff.GetDataLen();
357 data->m_memBuff->AppendData(ptr, buffLen);
372 if (data != 0 && len > 0) {
373 data->m_memBuff =
new wxMemoryBuffer();
374 data->m_memBuff->AppendData(buff, len);
394#if defined(WXJSON_USE_VALUE_COUNTER)
397 wxLogTrace(cowTraceMask,
"(%s) Copy ctor - progr=%d other progr=%d",
398 __PRETTY_FUNCTION__, m_progr, other.m_progr);
460 wxJSONType type = wxJSONTYPE_INVALID;
469 if (data->m_value.VAL_INT >= SHORT_MIN &&
470 data->m_value.VAL_INT <= SHORT_MAX) {
471 type = wxJSONTYPE_SHORT;
474 else if (data->m_value.VAL_INT >= LONG_MIN &&
475 data->m_value.VAL_INT <= LONG_MAX) {
476 type = wxJSONTYPE_LONG;
478 type = wxJSONTYPE_INT64;
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;
488 type = wxJSONTYPE_UINT64;
503 if (type == wxJSONTYPE_NULL) {
524 if (type != wxJSONTYPE_INVALID) {
556 if (type == wxJSONTYPE_SHORT) {
558 }
else if (type == wxJSONTYPE_LONG) {
560 if (INT_MAX == LONG_MAX) {
584 if (type == wxJSONTYPE_SHORT) {
616 if (type == wxJSONTYPE_USHORT) {
618 }
else if (type == wxJSONTYPE_ULONG) {
619 if (INT_MAX == LONG_MAX) {
643 if (type == wxJSONTYPE_USHORT) {
666 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_SHORT) {
690 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_USHORT) {
700 if (type == wxJSONTYPE_BOOL) {
710 if (type == wxJSONTYPE_DOUBLE) {
720 if (type == wxJSONTYPE_STRING) {
739 if (type == wxJSONTYPE_CSTRING) {
749 if (type == wxJSONTYPE_ARRAY) {
759 if (type == wxJSONTYPE_OBJECT) {
769 if (type == wxJSONTYPE_MEMORYBUFF) {
792 int i = (int)data->m_value.VAL_INT;
794 wxJSON_ASSERT(
IsInt());
812 wxJSON_ASSERT(data->m_type == wxJSONTYPE_BOOL);
813 return data->m_value.m_valBool;
830 double d = data->m_value.m_valDouble;
877 switch (data->m_type) {
878 case wxJSONTYPE_STRING:
879 s.assign(data->m_valString);
881 case wxJSONTYPE_CSTRING:
882 s.assign(data->m_value.m_valCString);
885#if defined(wxJSON_64BIT_INT)
886 s.Printf(
"%" compatibleLongLongFmtSpec
"i", data->m_value.m_valInt64);
888 s.Printf(
"%ld", data->m_value.m_valLong);
891 case wxJSONTYPE_UINT:
892#if defined(wxJSON_64BIT_INT)
893 s.Printf(
"%" compatibleLongLongFmtSpec
"u", data->m_value.m_valUInt64);
895 s.Printf(
"%lu", data->m_value.m_valULong);
898 case wxJSONTYPE_DOUBLE:
899 s.Printf(
"%.10g", data->m_value.m_valDouble);
901 case wxJSONTYPE_BOOL:
902 s.assign((data->m_value.m_valBool ?
"true" :
"false"));
904 case wxJSONTYPE_NULL:
905 s.assign(_T(
"null"));
907 case wxJSONTYPE_INVALID:
908 s.assign(_T(
"<invalid>"));
910 case wxJSONTYPE_ARRAY:
911 s.Printf(
"[%d]", size);
913 case wxJSONTYPE_OBJECT:
914 s.Printf(
"{%d}", size);
916 case wxJSONTYPE_MEMORYBUFF:
920 s.assign(_T(
"wxJSONValue::AsString(): Unknown JSON type \'"));
922 s.append(_T(
"\'" ));
946 const wxChar* s =
nullptr;
949 switch (data->m_type) {
950 case wxJSONTYPE_CSTRING:
951 s = data->m_value.m_valCString;
953 case wxJSONTYPE_STRING:
954 s = data->m_valString.c_str();
977 unsigned int ui = (unsigned)data->m_value.VAL_UINT;
999 l = (long)data->m_value.VAL_INT;
1019 wxJSON_ASSERT(data);
1020 unsigned long int ul = (
unsigned long)data->m_value.VAL_UINT;
1041 wxJSON_ASSERT(data);
1042 i = (short)data->m_value.VAL_INT;
1063 wxJSON_ASSERT(data);
1064 ui = (
unsigned short)data->m_value.VAL_UINT;
1215 wxJSON_ASSERT(data);
1216 wxMemoryBuffer buff;
1217 if (data->m_memBuff) {
1218 buff = *(data->m_memBuff);
1263 wxJSON_ASSERT(data);
1265 const wxJSONInternalMap* v =
nullptr;
1266 if (data->m_type == wxJSONTYPE_OBJECT) {
1267 v = &(data->m_valMap);
1281 wxJSON_ASSERT(data);
1283 const wxJSONInternalArray* v =
nullptr;
1284 if (data->m_type == wxJSONTYPE_ARRAY) {
1285 v = &(data->m_valArray);
1299 if (index < (
unsigned)size) {
1312 wxJSON_ASSERT(data);
1314 if (data && data->m_type == wxJSONTYPE_OBJECT) {
1315 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1316 if (it != data->m_valMap.end()) {
1332 wxJSON_ASSERT(data);
1335 if (data->m_type == wxJSONTYPE_ARRAY) {
1336 size = (int)data->m_valArray.GetCount();
1338 if (data->m_type == wxJSONTYPE_OBJECT) {
1339 size = (int)data->m_valMap.size();
1357 wxJSON_ASSERT(data);
1358 wxJSON_ASSERT(data->m_type == wxJSONTYPE_OBJECT);
1361 if (data->m_type == wxJSONTYPE_OBJECT) {
1362 wxJSONInternalMap::iterator it;
1363 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
1385 wxJSON_ASSERT(data);
1386 if (data->m_type != wxJSONTYPE_ARRAY) {
1393 data->m_valArray.Add(value);
1491bool wxJSONValue::Cat(
const wxString& str) {
1493 wxJSON_ASSERT(data);
1496 if (data->m_type == wxJSONTYPE_STRING) {
1498 wxJSON_ASSERT(data);
1499 data->m_valString.append(str);
1512bool wxJSONValue::Cat(
const wxMemoryBuffer& buff) {
1514 wxJSON_ASSERT(data);
1517 if (data->m_type == wxJSONTYPE_MEMORYBUFF) {
1519 wxJSON_ASSERT(data);
1520 data->m_memBuff->AppendData(buff.GetData(), buff.GetDataLen());
1527bool wxJSONValue::Cat(
const wxChar* str) {
1529 wxJSON_ASSERT(data);
1532 if (data->m_type == wxJSONTYPE_STRING) {
1534 wxJSON_ASSERT(data);
1535 data->m_valString.append(str);
1551 wxJSON_ASSERT(data);
1554 if (data->m_type == wxJSONTYPE_ARRAY) {
1555 data->m_valArray.RemoveAt(index);
1564 wxJSON_ASSERT(data);
1567 if (data->m_type == wxJSONTYPE_OBJECT) {
1568 wxJSONInternalMap::size_type count = data->m_valMap.erase(key);
1602 wxJSON_ASSERT(data);
1604 if (data->m_type != wxJSONTYPE_ARRAY) {
1605 data =
SetType(wxJSONTYPE_ARRAY);
1608 wxJSON_ASSERT(size >= 0);
1611 if (index >= (
unsigned)size) {
1613 int missing = index - size + 1;
1614 data->m_valArray.Add(v, missing);
1616 return data->m_valArray.Item(index);
1629 wxLogTrace(traceMask,
"(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1631#if !wxCHECK_VERSION(2, 9, 0)
1632 wxLogTrace(traceMask,
"(%s) actual object: %s", __PRETTY_FUNCTION__,
1637 wxJSON_ASSERT(data);
1639 if (data->m_type != wxJSONTYPE_OBJECT) {
1641 data =
SetType(wxJSONTYPE_OBJECT);
1642 return data->m_valMap[key];
1644 wxLogTrace(traceMask,
"(%s) searching key \'%s' in the actual object",
1645 __PRETTY_FUNCTION__, key.c_str());
1646 return data->m_valMap[key];
1657 wxJSON_ASSERT(data);
1660 if (data->m_type == wxJSONTYPE_ARRAY) {
1662 wxJSON_ASSERT(size >= 0);
1663 if (index < (
unsigned)size) {
1664 v = data->m_valArray.
Item(index);
1677 wxLogTrace(traceMask,
"(%s) searched key=\'%s\'", __PRETTY_FUNCTION__,
1679 wxLogTrace(traceMask,
"(%s) actual object: %s", __PRETTY_FUNCTION__,
1683 wxJSON_ASSERT(data);
1686 if (data->m_type == wxJSONTYPE_OBJECT) {
1687 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1688 if (it != data->m_valMap.end()) {
1747 data->m_value.VAL_INT = i;
1754 data->m_value.m_valBool = b;
1761 data->m_value.VAL_UINT = ui;
1768 data->m_value.VAL_INT = l;
1775 data->m_value.VAL_UINT = ul;
1782 data->m_value.VAL_INT = i;
1789 data->m_value.VAL_UINT = ui;
1796 data->m_value.m_valDouble = d;
1803 data->m_value.m_valCString = str;
1804#if !defined(WXJSON_USE_CSTRING)
1805 data->m_type = wxJSONTYPE_STRING;
1806 data->m_valString.assign(str);
1814 data->m_valString.assign(str);
1826 data->m_memBuff =
new wxMemoryBuffer();
1827 const void* ptr = buff.GetData();
1828 size_t len = buff.GetDataLen();
1829 if (data->m_memBuff && len) {
1830 data->m_memBuff->AppendData(ptr, len);
1885 wxJSON_ASSERT(data);
1886 if (data->m_type == wxJSONTYPE_OBJECT) {
1887 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1888 if (it != data->m_valMap.end()) {
1906 wxJSON_ASSERT(data);
1910 if (data->m_type == wxJSONTYPE_ARRAY) {
1911 size_t size = data->m_valArray.GetCount();
1913 vp = &(data->m_valArray.Item(index));
1928 wxJSON_ASSERT(data);
1932 if (data->m_type == wxJSONTYPE_OBJECT) {
1933 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1934 if (it != data->m_valMap.end()) {
1953 static const wxChar* str[] = {
1954 _T(
"wxJSONTYPE_INVALID" ),
1955 _T(
"wxJSONTYPE_NULL" ),
1956 _T(
"wxJSONTYPE_INT" ),
1957 _T(
"wxJSONTYPE_UINT" ),
1958 _T(
"wxJSONTYPE_DOUBLE" ),
1959 _T(
"wxJSONTYPE_STRING" ),
1960 _T(
"wxJSONTYPE_CSTRING" ),
1961 _T(
"wxJSONTYPE_BOOL" ),
1962 _T(
"wxJSONTYPE_ARRAY" ),
1963 _T(
"wxJSONTYPE_OBJECT" ),
1964 _T(
"wxJSONTYPE_LONG" ),
1965 _T(
"wxJSONTYPE_INT64" ),
1966 _T(
"wxJSONTYPE_ULONG" ),
1967 _T(
"wxJSONTYPE_UINT64" ),
1968 _T(
"wxJSONTYPE_SHORT" ),
1969 _T(
"wxJSONTYPE_USHORT" ),
1970 _T(
"wxJSONTYPE_MEMORYBUFF" ),
1974 int idx = (int)type;
1975 if (idx >= 0 && idx < 17) {
2003 wxJSON_ASSERT(data);
2009 s.append(indent,
' ');
2014#if defined(WXJSON_USE_VALUE_COUNTER)
2015 s1.Printf(
"Object: Progr=%d Type=%s Size=%d comments=%d\n", m_progr,
2017 s2.Printf(
" : RefData=%p Progr=%d Num shares=%d\n", data, data->m_progr,
2018 data->GetRefCount());
2020 s1.Printf(
"Object: Type=%s Size=%d comments=%d\n",
TypeToString(type).c_str(),
2021 Size(), data->m_comments.GetCount());
2022 s2.Printf(
" : RefData=%p Num shares=%d\n", data, data->GetRefCount());
2026 s.append(indent,
' ');
2036 const wxJSONInternalMap* map;
2039 wxJSONInternalMap::const_iterator it;
2041 case wxJSONTYPE_OBJECT:
2044 for (it = map->begin(); it != map->end(); ++it) {
2046 sub = v.
Dump(
true, indent);
2050 case wxJSONTYPE_ARRAY:
2052 for (
int i = 0; i < size; i++) {
2055 sub = v->
Dump(
true, indent);
2074 wxJSON_ASSERT(data);
2077#if defined(WXJSON_USE_VALUE_CONTER)
2078 s.Printf(
"Object: Progr=%d Type=%s Size=%d comments=%d\n", data->m_progr,
2080 data->m_comments.GetCount());
2082 s.Printf(
"Object: Type=%s Size=%d comments=%d\n",
2084 data->m_comments.GetCount());
2086 if (data->m_type == wxJSONTYPE_OBJECT) {
2088 for (
unsigned int i = 0; i < arr.size(); i++) {
2089 s.append(
" Member name: ");
2130 wxJSONInternalMap::const_iterator it;
2136 if (data == otherData) {
2137 wxLogTrace(compareTraceMask,
2138 "(%s) objects share the same referenced data - r=TRUE",
2139 __PRETTY_FUNCTION__);
2145 if (data->m_type != otherData->
m_type) {
2149 switch (data->m_type) {
2150 case wxJSONTYPE_INT:
2151 if (otherData->
m_type == wxJSONTYPE_UINT) {
2154 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2155 (data->m_value.VAL_UINT == otherData->
m_value.VAL_UINT)) {
2158 }
else if (otherData->
m_type == wxJSONTYPE_DOUBLE) {
2159 val = data->m_value.VAL_INT;
2160 if (val == otherData->
m_value.m_valDouble) {
2167 case wxJSONTYPE_UINT:
2168 if (otherData->
m_type == wxJSONTYPE_INT) {
2171 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2172 (data->m_value.VAL_UINT == otherData->
m_value.VAL_UINT)) {
2175 }
else if (otherData->
m_type == wxJSONTYPE_DOUBLE) {
2176 val = data->m_value.VAL_UINT;
2177 if (val == otherData->
m_value.m_valDouble) {
2184 case wxJSONTYPE_DOUBLE:
2185 if (otherData->
m_type == wxJSONTYPE_INT) {
2186 val = otherData->
m_value.VAL_INT;
2187 if (val == data->m_value.m_valDouble) {
2190 }
else if (otherData->
m_type == wxJSONTYPE_UINT) {
2191 val = otherData->
m_value.VAL_UINT;
2192 if (val == data->m_value.m_valDouble) {
2215 switch (data->m_type) {
2216 case wxJSONTYPE_INVALID:
2217 case wxJSONTYPE_NULL:
2220 case wxJSONTYPE_INT:
2221 if (data->m_value.VAL_INT != otherData->
m_value.VAL_INT) {
2225 case wxJSONTYPE_UINT:
2226 if (data->m_value.VAL_UINT != otherData->
m_value.VAL_UINT) {
2230 case wxJSONTYPE_DOUBLE:
2231 if (data->m_value.m_valDouble != otherData->
m_value.m_valDouble) {
2235 case wxJSONTYPE_CSTRING:
2236 s1 = wxString(data->m_value.m_valCString);
2237 s2 = wxString(otherData->
m_value.m_valCString);
2242 case wxJSONTYPE_BOOL:
2243 if (data->m_value.m_valBool != otherData->
m_value.m_valBool) {
2247 case wxJSONTYPE_STRING:
2248 if (data->m_valString != otherData->
m_valString) {
2252 case wxJSONTYPE_MEMORYBUFF:
2259 case wxJSONTYPE_ARRAY:
2261 wxLogTrace(compareTraceMask,
"(%s) Comparing an array object - size=%d",
2262 __PRETTY_FUNCTION__, size);
2264 if (size != other.
Size()) {
2265 wxLogTrace(compareTraceMask,
"(%s) Sizes does not match",
2266 __PRETTY_FUNCTION__);
2271 for (
int i = 0; i < size; i++) {
2272 wxLogTrace(compareTraceMask,
"(%s) Comparing array element=%d",
2273 __PRETTY_FUNCTION__, i);
2282 case wxJSONTYPE_OBJECT:
2284 wxLogTrace(compareTraceMask,
"(%s) Comparing a map obejct - size=%d",
2285 __PRETTY_FUNCTION__, size);
2287 if (size != other.
Size()) {
2288 wxLogTrace(compareTraceMask,
2289 "(%s) Comparison failed - sizes does not match",
2290 __PRETTY_FUNCTION__);
2295 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
2296 wxString key = it->first;
2297 wxLogTrace(compareTraceMask,
"(%s) Comparing map object - key=%s",
2298 __PRETTY_FUNCTION__, key.c_str());
2300 bool isSame = it->second.
IsSameAs(otherVal);
2302 wxLogTrace(compareTraceMask,
2303 "(%s) Comparison failed for the last object",
2304 __PRETTY_FUNCTION__);
2311 wxFAIL_MSG(
"wxJSONValue::IsSameAs() unexpected wxJSONType");
2344 wxJSON_ASSERT(data);
2346 wxLogTrace(traceMask,
"(%s) comment=%s", __PRETTY_FUNCTION__, str.c_str());
2348 int len = str.length();
2350 wxLogTrace(traceMask,
" error: len < 2");
2353 if (str[0] !=
'/') {
2354 wxLogTrace(traceMask,
" error: does not start with\'/\'");
2357 if (str[1] ==
'/') {
2358 wxLogTrace(traceMask, _T(
" C++ comment" ));
2359 if (str.GetChar(len - 1) !=
'\n') {
2361 temp.append(1,
'\n');
2362 data->m_comments.Add(temp);
2363 wxLogTrace(traceMask,
" C++ comment: LF added");
2365 data->m_comments.Add(str);
2367 r = data->m_comments.size();
2368 }
else if (str[1] ==
2370 wxLogTrace(traceMask,
" C-style comment");
2371 int lastPos = len - 1;
2372 wxChar ch = str.GetChar(lastPos);
2374 while (ch ==
' ' || ch ==
'\n' || ch ==
'\t') {
2376 ch = str.GetChar(lastPos);
2378 if (str.GetChar(lastPos) ==
'/' && str.GetChar(lastPos - 1) ==
'*') {
2379 data->m_comments.Add(str);
2380 r = data->m_comments.size();
2383 wxLogTrace(traceMask,
" error: is not a valid comment string");
2387 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2388 data->m_commentPos = position;
2401 int siz = comments.GetCount();
2403 for (
int i = 0; i < siz; i++) {
2421 wxJSON_ASSERT(data);
2424 int size = data->m_comments.GetCount();
2426 for (
int i = 0; i < size; i++) {
2427 s.append(data->m_comments[i]);
2429 }
else if (idx < size) {
2430 s = data->m_comments[idx];
2438 wxJSON_ASSERT(data);
2440 int d = data->m_comments.GetCount();
2441 wxLogTrace(traceMask,
"(%s) comment count=%d", __PRETTY_FUNCTION__, d);
2448 wxJSON_ASSERT(data);
2449 return data->m_commentPos;
2455 wxJSON_ASSERT(data);
2457 return data->m_comments;
2463 wxJSON_ASSERT(data);
2465 data->m_comments.clear();
2532 wxJSONType oldType =
GetType();
2535 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2536 (type <= wxJSONTYPE_MEMORYBUFF));
2537 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2538 type = wxJSONTYPE_INVALID;
2551 if (type == oldType) {
2557 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2558 type == wxJSONTYPE_SHORT) {
2559 type = wxJSONTYPE_INT;
2561 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2562 type == wxJSONTYPE_USHORT) {
2563 type = wxJSONTYPE_UINT;
2566 wxJSON_ASSERT(data);
2567 data->m_type = type;
2571 case wxJSONTYPE_STRING:
2572 data->m_valString.clear();
2574 case wxJSONTYPE_ARRAY:
2575 data->m_valArray.Clear();
2577 case wxJSONTYPE_OBJECT:
2578 data->m_valMap.clear();
2580 case wxJSONTYPE_MEMORYBUFF:
2582 if (data->m_memBuff) {
2583 delete data->m_memBuff;
2584 data->m_memBuff = 0;
2594#if !defined(WXJSON_USE_CSTRING)
2595 if (data->m_type == wxJSONTYPE_CSTRING) {
2596 data->m_type = wxJSONTYPE_STRING;
2625 wxJSON_ASSERT(data);
2626 data->m_lineNo = num;
2694 wxJSON_ASSERT(otherData);
2704 data->m_type = other->
m_type;
2705 data->m_value = other->
m_value;
2717 data->m_memBuff =
new wxMemoryBuffer();
2718 const void* ptr = data->m_memBuff->GetData();
2719 size_t len = data->m_memBuff->GetDataLen();
2720 if (data->m_memBuff && len) {
2721 data->m_memBuff->AppendData(ptr, len);
2725 wxLogTrace(cowTraceMask,
"(%s) CloneRefData() PROGR: other=%d data=%d",
2726 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2740 data->m_type = wxJSONTYPE_INVALID;
2753 wxLogTrace(cowTraceMask,
"(%s) COW() START data=%p data->m_count=%d",
2754 __PRETTY_FUNCTION__, data, data->GetRefCount());
2757 wxLogTrace(cowTraceMask,
"(%s) COW() END data=%p data->m_count=%d",
2758 __PRETTY_FUNCTION__, data, data->GetRefCount());
2766 }
else if (
m_refData->GetRefCount() > 1) {
2777 "wxObject::AllocExclusive() failed.");
2800 size_t buffLen = buff.GetDataLen();
2801 void* ptr = buff.GetData();
2830 size_t buffLen = actualLen;
2831 if (buffLen == (
size_t)-1) {
2834 s.Printf(
"%p (%u) ", buff, buffLen);
2835 unsigned char* ptr = (
unsigned char*)buff;
2836 for (
unsigned int i = 0; i < len; i++) {
2837 unsigned char c = *ptr;
2883 const wxMemoryBuffer& buff2) {
2885 size_t buff1Len = buff1.GetDataLen();
2886 size_t buff2Len = buff2.GetDataLen();
2887 if (buff1Len > buff2Len) {
2889 }
else if (buff1Len < buff2Len) {
2892 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2910 const void* buff2) {
2912 size_t buff1Len = buff1.GetDataLen();
2913 r = memcmp(buff1.GetData(), buff2, buff1Len);
2939 wxMemoryBuffer buff;
2940 if (value.IsArray()) {
2941 int len = value.Size();
2942 for (
int i = 0; i < len; i++) {
2947 bool r = value.ItemAt(i).AsShort(
byte);
2948 if (r && (
byte >= 0 &&
byte <= 255)) {
2949 c = (
unsigned char)
byte;
2963#if defined(wxJSON_64BIT_INT)
2969 wxJSON_ASSERT(data);
2971 data->m_value.VAL_INT = i;
2979 wxJSON_ASSERT(data);
2981 data->m_value.VAL_UINT = ui;
2994bool wxJSONValue::IsInt32()
const {
3008bool wxJSONValue::IsUInt32()
const {
3023bool wxJSONValue::IsInt64()
const {
3025 wxJSON_ASSERT(data);
3027 if (data->m_type == wxJSONTYPE_INT) {
3043bool wxJSONValue::IsUInt64()
const {
3045 wxJSON_ASSERT(data);
3047 if (data->m_type == wxJSONTYPE_UINT) {
3065wxInt32 wxJSONValue::AsInt32()
const {
3083wxUint32 wxJSONValue::AsUInt32()
const {
3103wxInt64 wxJSONValue::AsInt64()
const {
3105 wxJSON_ASSERT(data);
3106 wxInt64 i64 = data->m_value.m_valInt64;
3108 wxJSON_ASSERT(IsInt64());
3126wxUint64 wxJSONValue::AsUInt64()
const {
3128 wxJSON_ASSERT(data);
3129 wxUint64 ui64 = data->m_value.m_valUInt64;
3131 wxJSON_ASSERT(IsUInt64());
3135bool wxJSONValue::AsInt32(wxInt32& i32)
const {
3143bool wxJSONValue::AsUInt32(wxUint32& ui32)
const {
3144 bool r = IsUInt32();
3151bool wxJSONValue::AsInt64(wxInt64& i64)
const {
3159bool wxJSONValue::AsUInt64(wxUint64& ui64)
const {
3160 bool r = IsUInt64();
3184 data->m_value.VAL_INT = i;
3191 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.