17#define wxDEBUG_LEVEL 0
27#include <wx/arrimpl.cpp>
29#include <wx/jsonval.h>
31WX_DEFINE_OBJARRAY(wxJSONInternalArray);
33#if wxCHECK_VERSION(3, 0, 0)
34#define compatibleLongLongFmtSpec _T(wxLongLongFmtSpec)
36#define compatibleLongLongFmtSpec wxLongLongFmtSpec
42static const wxChar* traceMask = _T(
"jsonval");
43static const wxChar* compareTraceMask = _T(
"sameas");
44static const wxChar* cowTraceMask = _T(
"traceCOW" );
64#if defined(WXJSON_USE_VALUE_COUNTER)
66int wxJSONRefData::sm_progr = 1;
75#if defined(WXJSON_USE_VALUE_COUNTER)
78 wxLogTrace(traceMask, _T(
"(%s) JSON refData ctor progr=%d"),
79 __PRETTY_FUNCTION__, m_progr);
84wxJSONRefData::~wxJSONRefData() {
91int wxJSONRefData::GetRefCount()
const {
return m_refCount; }
158#if defined(WXJSON_USE_VALUE_COUNTER)
160int wxJSONValue::sm_progr = 1;
183 Init(wxJSONTYPE_NULL);
208 data->m_commentPos = wxJSONVALUE_COMMENT_BEFORE;
212#if defined(WXJSON_USE_VALUE_COUNTER)
215 wxLogTrace(cowTraceMask, _T(
"(%s) Init a new object progr=%d"),
216 __PRETTY_FUNCTION__, m_progr);
235 data->m_value.VAL_INT = i;
247 data->m_value.VAL_UINT = ui;
259 data->m_value.VAL_INT = i;
271 data->m_value.VAL_UINT = ui;
281 data->m_value.m_valBool = b;
291 data->m_value.m_valDouble = d;
301#if !defined(WXJSON_USE_CSTRING)
302 data->m_type = wxJSONTYPE_STRING;
303 data->m_valString.assign(str);
305 data->m_value.m_valCString = str;
316 data->m_valString.assign(str);
326 data->m_value.VAL_INT = l;
336 data->m_value.VAL_UINT = ul;
351 data->m_memBuff =
new wxMemoryBuffer();
352 const void* ptr = buff.GetData();
353 size_t buffLen = buff.GetDataLen();
355 data->m_memBuff->AppendData(ptr, buffLen);
370 if (data != 0 && len > 0) {
371 data->m_memBuff =
new wxMemoryBuffer();
372 data->m_memBuff->AppendData(buff, len);
392#if defined(WXJSON_USE_VALUE_COUNTER)
395 wxLogTrace(cowTraceMask, _T(
"(%s) Copy ctor - progr=%d other progr=%d"),
396 __PRETTY_FUNCTION__, m_progr, other.m_progr);
458 wxJSONType type = wxJSONTYPE_INVALID;
467 if (data->m_value.VAL_INT >= SHORT_MIN &&
468 data->m_value.VAL_INT <= SHORT_MAX) {
469 type = wxJSONTYPE_SHORT;
472 else if (data->m_value.VAL_INT >= LONG_MIN &&
473 data->m_value.VAL_INT <= LONG_MAX) {
474 type = wxJSONTYPE_LONG;
476 type = wxJSONTYPE_INT64;
480 case wxJSONTYPE_UINT:
481 if (data->m_value.VAL_UINT <= USHORT_MAX) {
482 type = wxJSONTYPE_USHORT;
483 }
else if (data->m_value.VAL_UINT <= ULONG_MAX) {
484 type = wxJSONTYPE_ULONG;
486 type = wxJSONTYPE_UINT64;
501 if (type == wxJSONTYPE_NULL) {
522 if (type != wxJSONTYPE_INVALID) {
554 if (type == wxJSONTYPE_SHORT) {
556 }
else if (type == wxJSONTYPE_LONG) {
558 if (INT_MAX == LONG_MAX) {
582 if (type == wxJSONTYPE_SHORT) {
614 if (type == wxJSONTYPE_USHORT) {
616 }
else if (type == wxJSONTYPE_ULONG) {
617 if (INT_MAX == LONG_MAX) {
641 if (type == wxJSONTYPE_USHORT) {
664 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_SHORT) {
688 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_USHORT) {
698 if (type == wxJSONTYPE_BOOL) {
708 if (type == wxJSONTYPE_DOUBLE) {
718 if (type == wxJSONTYPE_STRING) {
737 if (type == wxJSONTYPE_CSTRING) {
747 if (type == wxJSONTYPE_ARRAY) {
757 if (type == wxJSONTYPE_OBJECT) {
767 if (type == wxJSONTYPE_MEMORYBUFF) {
790 int i = (int)data->m_value.VAL_INT;
792 wxJSON_ASSERT(
IsInt());
810 wxJSON_ASSERT(data->m_type == wxJSONTYPE_BOOL);
811 return data->m_value.m_valBool;
828 double d = data->m_value.m_valDouble;
875 switch (data->m_type) {
876 case wxJSONTYPE_STRING:
877 s.assign(data->m_valString);
879 case wxJSONTYPE_CSTRING:
880 s.assign(data->m_value.m_valCString);
883#if defined(wxJSON_64BIT_INT)
884 s.Printf(_T(
"%") compatibleLongLongFmtSpec _T(
"i"),
885 data->m_value.m_valInt64);
887 s.Printf(_T(
"%ld"), data->m_value.m_valLong);
890 case wxJSONTYPE_UINT:
891#if defined(wxJSON_64BIT_INT)
892 s.Printf(_T(
"%") compatibleLongLongFmtSpec _T(
"u"),
893 data->m_value.m_valUInt64);
895 s.Printf(_T(
"%lu"), data->m_value.m_valULong);
898 case wxJSONTYPE_DOUBLE:
899 s.Printf(_T(
"%.10g"), data->m_value.m_valDouble);
901 case wxJSONTYPE_BOOL:
902 s.assign((data->m_value.m_valBool ? _T(
"true") : _T(
"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(_T(
"[%d]"), size);
913 case wxJSONTYPE_OBJECT:
914 s.Printf(_T(
"{%d}"), size);
916 case wxJSONTYPE_MEMORYBUFF:
920 s.assign(_T(
"wxJSONValue::AsString(): Unknown JSON type \'"));
922 s.append(_T(
"\'" ));
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 = 0;
1266 if (data->m_type == wxJSONTYPE_OBJECT) {
1267 v = &(data->m_valMap);
1281 wxJSON_ASSERT(data);
1283 const wxJSONInternalArray* v = 0;
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, _T(
"(%s) searched key=\'%s\'"), __PRETTY_FUNCTION__,
1631#if !wxCHECK_VERSION(2, 9, 0)
1632 wxLogTrace(traceMask, _T(
"(%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, _T(
"(%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, _T(
"(%s) searched key=\'%s\'"), __PRETTY_FUNCTION__,
1680 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.