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 = _T(
"jsonval");
45static const wxChar* compareTraceMask = _T(
"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, _T(
"(%s) JSON refData ctor progr=%d"),
81 __PRETTY_FUNCTION__, m_progr);
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, _T(
"(%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, _T(
"(%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(_T(
"%") compatibleLongLongFmtSpec _T(
"i"),
887 data->m_value.m_valInt64);
889 s.Printf(_T(
"%ld"), data->m_value.m_valLong);
892 case wxJSONTYPE_UINT:
893#if defined(wxJSON_64BIT_INT)
894 s.Printf(_T(
"%") compatibleLongLongFmtSpec _T(
"u"),
895 data->m_value.m_valUInt64);
897 s.Printf(_T(
"%lu"), data->m_value.m_valULong);
900 case wxJSONTYPE_DOUBLE:
901 s.Printf(_T(
"%.10g"), data->m_value.m_valDouble);
903 case wxJSONTYPE_BOOL:
904 s.assign((data->m_value.m_valBool ? _T(
"true") : _T(
"false")));
906 case wxJSONTYPE_NULL:
907 s.assign(_T(
"null"));
909 case wxJSONTYPE_INVALID:
910 s.assign(_T(
"<invalid>"));
912 case wxJSONTYPE_ARRAY:
913 s.Printf(_T(
"[%d]"), size);
915 case wxJSONTYPE_OBJECT:
916 s.Printf(_T(
"{%d}"), size);
918 case wxJSONTYPE_MEMORYBUFF:
922 s.assign(_T(
"wxJSONValue::AsString(): Unknown JSON type \'"));
924 s.append(_T(
"\'" ));
948 const wxChar* s =
nullptr;
951 switch (data->m_type) {
952 case wxJSONTYPE_CSTRING:
953 s = data->m_value.m_valCString;
955 case wxJSONTYPE_STRING:
956 s = data->m_valString.c_str();
979 unsigned int ui = (unsigned)data->m_value.VAL_UINT;
1000 wxJSON_ASSERT(data);
1001 l = (long)data->m_value.VAL_INT;
1021 wxJSON_ASSERT(data);
1022 unsigned long int ul = (
unsigned long)data->m_value.VAL_UINT;
1043 wxJSON_ASSERT(data);
1044 i = (short)data->m_value.VAL_INT;
1065 wxJSON_ASSERT(data);
1066 ui = (
unsigned short)data->m_value.VAL_UINT;
1217 wxJSON_ASSERT(data);
1218 wxMemoryBuffer buff;
1219 if (data->m_memBuff) {
1220 buff = *(data->m_memBuff);
1265 wxJSON_ASSERT(data);
1267 const wxJSONInternalMap* v =
nullptr;
1268 if (data->m_type == wxJSONTYPE_OBJECT) {
1269 v = &(data->m_valMap);
1283 wxJSON_ASSERT(data);
1285 const wxJSONInternalArray* v =
nullptr;
1286 if (data->m_type == wxJSONTYPE_ARRAY) {
1287 v = &(data->m_valArray);
1301 if (index < (
unsigned)size) {
1314 wxJSON_ASSERT(data);
1316 if (data && data->m_type == wxJSONTYPE_OBJECT) {
1317 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1318 if (it != data->m_valMap.end()) {
1334 wxJSON_ASSERT(data);
1337 if (data->m_type == wxJSONTYPE_ARRAY) {
1338 size = (int)data->m_valArray.GetCount();
1340 if (data->m_type == wxJSONTYPE_OBJECT) {
1341 size = (int)data->m_valMap.size();
1359 wxJSON_ASSERT(data);
1360 wxJSON_ASSERT(data->m_type == wxJSONTYPE_OBJECT);
1363 if (data->m_type == wxJSONTYPE_OBJECT) {
1364 wxJSONInternalMap::iterator it;
1365 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
1387 wxJSON_ASSERT(data);
1388 if (data->m_type != wxJSONTYPE_ARRAY) {
1395 data->m_valArray.Add(value);
1493bool wxJSONValue::Cat(
const wxString& str) {
1495 wxJSON_ASSERT(data);
1498 if (data->m_type == wxJSONTYPE_STRING) {
1500 wxJSON_ASSERT(data);
1501 data->m_valString.append(str);
1514bool wxJSONValue::Cat(
const wxMemoryBuffer& buff) {
1516 wxJSON_ASSERT(data);
1519 if (data->m_type == wxJSONTYPE_MEMORYBUFF) {
1521 wxJSON_ASSERT(data);
1522 data->m_memBuff->AppendData(buff.GetData(), buff.GetDataLen());
1529bool wxJSONValue::Cat(
const wxChar* str) {
1531 wxJSON_ASSERT(data);
1534 if (data->m_type == wxJSONTYPE_STRING) {
1536 wxJSON_ASSERT(data);
1537 data->m_valString.append(str);
1553 wxJSON_ASSERT(data);
1556 if (data->m_type == wxJSONTYPE_ARRAY) {
1557 data->m_valArray.RemoveAt(index);
1566 wxJSON_ASSERT(data);
1569 if (data->m_type == wxJSONTYPE_OBJECT) {
1570 wxJSONInternalMap::size_type count = data->m_valMap.erase(key);
1604 wxJSON_ASSERT(data);
1606 if (data->m_type != wxJSONTYPE_ARRAY) {
1607 data =
SetType(wxJSONTYPE_ARRAY);
1610 wxJSON_ASSERT(size >= 0);
1613 if (index >= (
unsigned)size) {
1615 int missing = index - size + 1;
1616 data->m_valArray.Add(v, missing);
1618 return data->m_valArray.Item(index);
1631 wxLogTrace(traceMask, _T(
"(%s) searched key=\'%s\'"), __PRETTY_FUNCTION__,
1633#if !wxCHECK_VERSION(2, 9, 0)
1634 wxLogTrace(traceMask, _T(
"(%s) actual object: %s"), __PRETTY_FUNCTION__,
1639 wxJSON_ASSERT(data);
1641 if (data->m_type != wxJSONTYPE_OBJECT) {
1643 data =
SetType(wxJSONTYPE_OBJECT);
1644 return data->m_valMap[key];
1646 wxLogTrace(traceMask, _T(
"(%s) searching key \'%s' in the actual object"),
1647 __PRETTY_FUNCTION__, key.c_str());
1648 return data->m_valMap[key];
1659 wxJSON_ASSERT(data);
1662 if (data->m_type == wxJSONTYPE_ARRAY) {
1664 wxJSON_ASSERT(size >= 0);
1665 if (index < (
unsigned)size) {
1666 v = data->m_valArray.
Item(index);
1679 wxLogTrace(traceMask, _T(
"(%s) searched key=\'%s\'"), __PRETTY_FUNCTION__,
1681 wxLogTrace(traceMask, _T(
"(%s) actual object: %s"), __PRETTY_FUNCTION__,
1685 wxJSON_ASSERT(data);
1688 if (data->m_type == wxJSONTYPE_OBJECT) {
1689 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1690 if (it != data->m_valMap.end()) {
1749 data->m_value.VAL_INT = i;
1756 data->m_value.m_valBool = b;
1763 data->m_value.VAL_UINT = ui;
1770 data->m_value.VAL_INT = l;
1777 data->m_value.VAL_UINT = ul;
1784 data->m_value.VAL_INT = i;
1791 data->m_value.VAL_UINT = ui;
1798 data->m_value.m_valDouble = d;
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);
1816 data->m_valString.assign(str);
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);
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()) {
1908 wxJSON_ASSERT(data);
1912 if (data->m_type == wxJSONTYPE_ARRAY) {
1913 size_t size = data->m_valArray.GetCount();
1915 vp = &(data->m_valArray.Item(index));
1930 wxJSON_ASSERT(data);
1934 if (data->m_type == wxJSONTYPE_OBJECT) {
1935 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1936 if (it != data->m_valMap.end()) {
1955 static const wxChar* str[] = {
1956 _T(
"wxJSONTYPE_INVALID" ),
1957 _T(
"wxJSONTYPE_NULL" ),
1958 _T(
"wxJSONTYPE_INT" ),
1959 _T(
"wxJSONTYPE_UINT" ),
1960 _T(
"wxJSONTYPE_DOUBLE" ),
1961 _T(
"wxJSONTYPE_STRING" ),
1962 _T(
"wxJSONTYPE_CSTRING" ),
1963 _T(
"wxJSONTYPE_BOOL" ),
1964 _T(
"wxJSONTYPE_ARRAY" ),
1965 _T(
"wxJSONTYPE_OBJECT" ),
1966 _T(
"wxJSONTYPE_LONG" ),
1967 _T(
"wxJSONTYPE_INT64" ),
1968 _T(
"wxJSONTYPE_ULONG" ),
1969 _T(
"wxJSONTYPE_UINT64" ),
1970 _T(
"wxJSONTYPE_SHORT" ),
1971 _T(
"wxJSONTYPE_USHORT" ),
1972 _T(
"wxJSONTYPE_MEMORYBUFF" ),
1976 int idx = (int)type;
1977 if (idx >= 0 && idx < 17) {
2005 wxJSON_ASSERT(data);
2011 s.append(indent,
' ');
2016#if defined(WXJSON_USE_VALUE_COUNTER)
2017 s1.Printf(_T(
"Object: Progr=%d Type=%s Size=%d comments=%d\n"), m_progr,
2019 s2.Printf(_T(
" : RefData=%p Progr=%d Num shares=%d\n"), data,
2020 data->m_progr, data->GetRefCount());
2022 s1.Printf(_T(
"Object: Type=%s Size=%d comments=%d\n"),
2024 s2.Printf(_T(
" : RefData=%p Num shares=%d\n"), data,
2025 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(_T(
"Object: Progr=%d Type=%s Size=%d comments=%d\n"), data->m_progr,
2083 data->m_comments.GetCount());
2085 s.Printf(_T(
"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(_T(
" Member name: "));
2133 wxJSONInternalMap::const_iterator it;
2139 if (data == otherData) {
2140 wxLogTrace(compareTraceMask,
2141 _T(
"(%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,
2265 _T(
"(%s) Comparing an array object - size=%d"),
2266 __PRETTY_FUNCTION__, size);
2268 if (size != other.
Size()) {
2269 wxLogTrace(compareTraceMask, _T(
"(%s) Sizes does not match"),
2270 __PRETTY_FUNCTION__);
2275 for (
int i = 0; i < size; i++) {
2276 wxLogTrace(compareTraceMask, _T(
"(%s) Comparing array element=%d"),
2277 __PRETTY_FUNCTION__, i);
2286 case wxJSONTYPE_OBJECT:
2288 wxLogTrace(compareTraceMask, _T(
"(%s) Comparing a map obejct - size=%d"),
2289 __PRETTY_FUNCTION__, size);
2291 if (size != other.
Size()) {
2292 wxLogTrace(compareTraceMask,
2293 _T(
"(%s) Comparison failed - sizes does not match"),
2294 __PRETTY_FUNCTION__);
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());
2304 bool isSame = it->second.
IsSameAs(otherVal);
2306 wxLogTrace(compareTraceMask,
2307 _T(
"(%s) Comparison failed for the last object"),
2308 __PRETTY_FUNCTION__);
2315 wxFAIL_MSG(_T(
"wxJSONValue::IsSameAs() unexpected wxJSONType"));
2348 wxJSON_ASSERT(data);
2350 wxLogTrace(traceMask, _T(
"(%s) comment=%s"), __PRETTY_FUNCTION__,
2353 int len = str.length();
2355 wxLogTrace(traceMask, _T(
" error: len < 2"));
2358 if (str[0] !=
'/') {
2359 wxLogTrace(traceMask, _T(
" error: does not start with\'/\'"));
2362 if (str[1] ==
'/') {
2363 wxLogTrace(traceMask, _T(
" C++ comment" ));
2364 if (str.GetChar(len - 1) !=
'\n') {
2366 temp.append(1,
'\n');
2367 data->m_comments.Add(temp);
2368 wxLogTrace(traceMask, _T(
" C++ comment: LF added"));
2370 data->m_comments.Add(str);
2372 r = data->m_comments.size();
2373 }
else if (str[1] ==
2375 wxLogTrace(traceMask, _T(
" C-style comment"));
2376 int lastPos = len - 1;
2377 wxChar ch = str.GetChar(lastPos);
2379 while (ch ==
' ' || ch ==
'\n' || ch ==
'\t') {
2381 ch = str.GetChar(lastPos);
2383 if (str.GetChar(lastPos) ==
'/' && str.GetChar(lastPos - 1) ==
'*') {
2384 data->m_comments.Add(str);
2385 r = data->m_comments.size();
2388 wxLogTrace(traceMask, _T(
" error: is not a valid comment string"));
2392 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2393 data->m_commentPos = position;
2406 int siz = comments.GetCount();
2408 for (
int i = 0; i < siz; i++) {
2426 wxJSON_ASSERT(data);
2429 int size = data->m_comments.GetCount();
2431 for (
int i = 0; i < size; i++) {
2432 s.append(data->m_comments[i]);
2434 }
else if (idx < size) {
2435 s = data->m_comments[idx];
2443 wxJSON_ASSERT(data);
2445 int d = data->m_comments.GetCount();
2446 wxLogTrace(traceMask, _T(
"(%s) comment count=%d"), __PRETTY_FUNCTION__, d);
2453 wxJSON_ASSERT(data);
2454 return data->m_commentPos;
2460 wxJSON_ASSERT(data);
2462 return data->m_comments;
2468 wxJSON_ASSERT(data);
2470 data->m_comments.clear();
2537 wxJSONType oldType =
GetType();
2540 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2541 (type <= wxJSONTYPE_MEMORYBUFF));
2542 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2543 type = wxJSONTYPE_INVALID;
2556 if (type == oldType) {
2562 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2563 type == wxJSONTYPE_SHORT) {
2564 type = wxJSONTYPE_INT;
2566 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2567 type == wxJSONTYPE_USHORT) {
2568 type = wxJSONTYPE_UINT;
2571 wxJSON_ASSERT(data);
2572 data->m_type = type;
2576 case wxJSONTYPE_STRING:
2577 data->m_valString.clear();
2579 case wxJSONTYPE_ARRAY:
2580 data->m_valArray.Clear();
2582 case wxJSONTYPE_OBJECT:
2583 data->m_valMap.clear();
2585 case wxJSONTYPE_MEMORYBUFF:
2587 if (data->m_memBuff) {
2588 delete data->m_memBuff;
2589 data->m_memBuff = 0;
2599#if !defined(WXJSON_USE_CSTRING)
2600 if (data->m_type == wxJSONTYPE_CSTRING) {
2601 data->m_type = wxJSONTYPE_STRING;
2630 wxJSON_ASSERT(data);
2631 data->m_lineNo = num;
2699 wxJSON_ASSERT(otherData);
2709 data->m_type = other->
m_type;
2710 data->m_value = other->
m_value;
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);
2730 wxLogTrace(cowTraceMask, _T(
"(%s) CloneRefData() PROGR: other=%d data=%d"),
2731 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2745 data->m_type = wxJSONTYPE_INVALID;
2758 wxLogTrace(cowTraceMask, _T(
"(%s) COW() START data=%p data->m_count=%d"),
2759 __PRETTY_FUNCTION__, data, data->GetRefCount());
2762 wxLogTrace(cowTraceMask, _T(
"(%s) COW() END data=%p data->m_count=%d"),
2763 __PRETTY_FUNCTION__, data, data->GetRefCount());
2771 }
else if (
m_refData->GetRefCount() > 1) {
2782 _T(
"wxObject::AllocExclusive() failed."));
2805 size_t buffLen = buff.GetDataLen();
2806 void* ptr = buff.GetData();
2835 size_t buffLen = actualLen;
2836 if (buffLen == (
size_t)-1) {
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;
2888 const wxMemoryBuffer& buff2) {
2890 size_t buff1Len = buff1.GetDataLen();
2891 size_t buff2Len = buff2.GetDataLen();
2892 if (buff1Len > buff2Len) {
2894 }
else if (buff1Len < buff2Len) {
2897 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2915 const void* buff2) {
2917 size_t buff1Len = buff1.GetDataLen();
2918 r = memcmp(buff1.GetData(), buff2, buff1Len);
2944 wxMemoryBuffer buff;
2945 if (value.IsArray()) {
2946 int len = value.Size();
2947 for (
int i = 0; i < len; i++) {
2952 bool r = value.ItemAt(i).AsShort(
byte);
2953 if (r && (
byte >= 0 &&
byte <= 255)) {
2954 c = (
unsigned char)
byte;
2968#if defined(wxJSON_64BIT_INT)
2974 wxJSON_ASSERT(data);
2976 data->m_value.VAL_INT = i;
2984 wxJSON_ASSERT(data);
2986 data->m_value.VAL_UINT = ui;
2999bool wxJSONValue::IsInt32()
const {
3013bool wxJSONValue::IsUInt32()
const {
3028bool wxJSONValue::IsInt64()
const {
3030 wxJSON_ASSERT(data);
3032 if (data->m_type == wxJSONTYPE_INT) {
3048bool wxJSONValue::IsUInt64()
const {
3050 wxJSON_ASSERT(data);
3052 if (data->m_type == wxJSONTYPE_UINT) {
3070wxInt32 wxJSONValue::AsInt32()
const {
3088wxUint32 wxJSONValue::AsUInt32()
const {
3108wxInt64 wxJSONValue::AsInt64()
const {
3110 wxJSON_ASSERT(data);
3111 wxInt64 i64 = data->m_value.m_valInt64;
3113 wxJSON_ASSERT(IsInt64());
3131wxUint64 wxJSONValue::AsUInt64()
const {
3133 wxJSON_ASSERT(data);
3134 wxUint64 ui64 = data->m_value.m_valUInt64;
3136 wxJSON_ASSERT(IsUInt64());
3140bool wxJSONValue::AsInt32(wxInt32& i32)
const {
3148bool wxJSONValue::AsUInt32(wxUint32& ui32)
const {
3149 bool r = IsUInt32();
3156bool wxJSONValue::AsInt64(wxInt64& i64)
const {
3164bool wxJSONValue::AsUInt64(wxUint64& ui64)
const {
3165 bool r = IsUInt64();
3189 data->m_value.VAL_INT = i;
3196 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.