18#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(
"\'" ));
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 = 0;
1268 if (data->m_type == wxJSONTYPE_OBJECT) {
1269 v = &(data->m_valMap);
1283 wxJSON_ASSERT(data);
1285 const wxJSONInternalArray* v = 0;
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__,
1682 wxLogTrace(traceMask, _T(
"(%s) actual object: %s"), __PRETTY_FUNCTION__,
1687 wxJSON_ASSERT(data);
1690 if (data->m_type == wxJSONTYPE_OBJECT) {
1691 wxJSONInternalMap::const_iterator it = data->m_valMap.find(key);
1692 if (it != data->m_valMap.end()) {
1751 data->m_value.VAL_INT = i;
1758 data->m_value.m_valBool = b;
1765 data->m_value.VAL_UINT = ui;
1772 data->m_value.VAL_INT = l;
1779 data->m_value.VAL_UINT = ul;
1786 data->m_value.VAL_INT = i;
1793 data->m_value.VAL_UINT = ui;
1800 data->m_value.m_valDouble = d;
1807 data->m_value.m_valCString = str;
1808#if !defined(WXJSON_USE_CSTRING)
1809 data->m_type = wxJSONTYPE_STRING;
1810 data->m_valString.assign(str);
1818 data->m_valString.assign(str);
1830 data->m_memBuff =
new wxMemoryBuffer();
1831 const void* ptr = buff.GetData();
1832 size_t len = buff.GetDataLen();
1833 if (data->m_memBuff && len) {
1834 data->m_memBuff->AppendData(ptr, len);
1889 wxJSON_ASSERT(data);
1890 if (data->m_type == wxJSONTYPE_OBJECT) {
1891 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1892 if (it != data->m_valMap.end()) {
1910 wxJSON_ASSERT(data);
1914 if (data->m_type == wxJSONTYPE_ARRAY) {
1915 size_t size = data->m_valArray.GetCount();
1917 vp = &(data->m_valArray.Item(index));
1932 wxJSON_ASSERT(data);
1936 if (data->m_type == wxJSONTYPE_OBJECT) {
1937 wxJSONInternalMap::iterator it = data->m_valMap.find(key);
1938 if (it != data->m_valMap.end()) {
1957 static const wxChar* str[] = {
1958 _T(
"wxJSONTYPE_INVALID" ),
1959 _T(
"wxJSONTYPE_NULL" ),
1960 _T(
"wxJSONTYPE_INT" ),
1961 _T(
"wxJSONTYPE_UINT" ),
1962 _T(
"wxJSONTYPE_DOUBLE" ),
1963 _T(
"wxJSONTYPE_STRING" ),
1964 _T(
"wxJSONTYPE_CSTRING" ),
1965 _T(
"wxJSONTYPE_BOOL" ),
1966 _T(
"wxJSONTYPE_ARRAY" ),
1967 _T(
"wxJSONTYPE_OBJECT" ),
1968 _T(
"wxJSONTYPE_LONG" ),
1969 _T(
"wxJSONTYPE_INT64" ),
1970 _T(
"wxJSONTYPE_ULONG" ),
1971 _T(
"wxJSONTYPE_UINT64" ),
1972 _T(
"wxJSONTYPE_SHORT" ),
1973 _T(
"wxJSONTYPE_USHORT" ),
1974 _T(
"wxJSONTYPE_MEMORYBUFF" ),
1978 int idx = (int)type;
1979 if (idx >= 0 && idx < 17) {
2007 wxJSON_ASSERT(data);
2013 s.append(indent,
' ');
2018#if defined(WXJSON_USE_VALUE_COUNTER)
2019 s1.Printf(_T(
"Object: Progr=%d Type=%s Size=%d comments=%d\n"), m_progr,
2021 s2.Printf(_T(
" : RefData=%p Progr=%d Num shares=%d\n"), data,
2022 data->m_progr, data->GetRefCount());
2024 s1.Printf(_T(
"Object: Type=%s Size=%d comments=%d\n"),
2026 s2.Printf(_T(
" : RefData=%p Num shares=%d\n"), data,
2027 data->GetRefCount());
2031 s.append(indent,
' ');
2041 const wxJSONInternalMap* map;
2044 wxJSONInternalMap::const_iterator it;
2046 case wxJSONTYPE_OBJECT:
2049 for (it = map->begin(); it != map->end(); ++it) {
2051 sub = v.
Dump(
true, indent);
2055 case wxJSONTYPE_ARRAY:
2057 for (
int i = 0; i < size; i++) {
2060 sub = v->
Dump(
true, indent);
2079 wxJSON_ASSERT(data);
2082#if defined(WXJSON_USE_VALUE_CONTER)
2083 s.Printf(_T(
"Object: Progr=%d Type=%s Size=%d comments=%d\n"), data->m_progr,
2085 data->m_comments.GetCount());
2087 s.Printf(_T(
"Object: Type=%s Size=%d comments=%d\n"),
2089 data->m_comments.GetCount());
2091 if (data->m_type == wxJSONTYPE_OBJECT) {
2093 for (
unsigned int i = 0; i < arr.size(); i++) {
2094 s.append(_T(
" Member name: "));
2135 wxJSONInternalMap::const_iterator it;
2141 if (data == otherData) {
2142 wxLogTrace(compareTraceMask,
2143 _T(
"(%s) objects share the same referenced data - r=TRUE"),
2144 __PRETTY_FUNCTION__);
2150 if (data->m_type != otherData->
m_type) {
2154 switch (data->m_type) {
2155 case wxJSONTYPE_INT:
2156 if (otherData->
m_type == wxJSONTYPE_UINT) {
2159 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2160 (data->m_value.VAL_UINT == otherData->
m_value.VAL_UINT)) {
2163 }
else if (otherData->
m_type == wxJSONTYPE_DOUBLE) {
2164 val = data->m_value.VAL_INT;
2165 if (val == otherData->
m_value.m_valDouble) {
2172 case wxJSONTYPE_UINT:
2173 if (otherData->
m_type == wxJSONTYPE_INT) {
2176 if ((data->m_value.VAL_UINT <= LLONG_MAX) &&
2177 (data->m_value.VAL_UINT == otherData->
m_value.VAL_UINT)) {
2180 }
else if (otherData->
m_type == wxJSONTYPE_DOUBLE) {
2181 val = data->m_value.VAL_UINT;
2182 if (val == otherData->
m_value.m_valDouble) {
2189 case wxJSONTYPE_DOUBLE:
2190 if (otherData->
m_type == wxJSONTYPE_INT) {
2191 val = otherData->
m_value.VAL_INT;
2192 if (val == data->m_value.m_valDouble) {
2195 }
else if (otherData->
m_type == wxJSONTYPE_UINT) {
2196 val = otherData->
m_value.VAL_UINT;
2197 if (val == data->m_value.m_valDouble) {
2220 switch (data->m_type) {
2221 case wxJSONTYPE_INVALID:
2222 case wxJSONTYPE_NULL:
2225 case wxJSONTYPE_INT:
2226 if (data->m_value.VAL_INT != otherData->
m_value.VAL_INT) {
2230 case wxJSONTYPE_UINT:
2231 if (data->m_value.VAL_UINT != otherData->
m_value.VAL_UINT) {
2235 case wxJSONTYPE_DOUBLE:
2236 if (data->m_value.m_valDouble != otherData->
m_value.m_valDouble) {
2240 case wxJSONTYPE_CSTRING:
2241 s1 = wxString(data->m_value.m_valCString);
2242 s2 = wxString(otherData->
m_value.m_valCString);
2247 case wxJSONTYPE_BOOL:
2248 if (data->m_value.m_valBool != otherData->
m_value.m_valBool) {
2252 case wxJSONTYPE_STRING:
2253 if (data->m_valString != otherData->
m_valString) {
2257 case wxJSONTYPE_MEMORYBUFF:
2264 case wxJSONTYPE_ARRAY:
2266 wxLogTrace(compareTraceMask,
2267 _T(
"(%s) Comparing an array object - size=%d"),
2268 __PRETTY_FUNCTION__, size);
2270 if (size != other.
Size()) {
2271 wxLogTrace(compareTraceMask, _T(
"(%s) Sizes does not match"),
2272 __PRETTY_FUNCTION__);
2277 for (
int i = 0; i < size; i++) {
2278 wxLogTrace(compareTraceMask, _T(
"(%s) Comparing array element=%d"),
2279 __PRETTY_FUNCTION__, i);
2288 case wxJSONTYPE_OBJECT:
2290 wxLogTrace(compareTraceMask, _T(
"(%s) Comparing a map obejct - size=%d"),
2291 __PRETTY_FUNCTION__, size);
2293 if (size != other.
Size()) {
2294 wxLogTrace(compareTraceMask,
2295 _T(
"(%s) Comparison failed - sizes does not match"),
2296 __PRETTY_FUNCTION__);
2301 for (it = data->m_valMap.begin(); it != data->m_valMap.end(); it++) {
2302 wxString key = it->first;
2303 wxLogTrace(compareTraceMask, _T(
"(%s) Comparing map object - key=%s"),
2304 __PRETTY_FUNCTION__, key.c_str());
2306 bool isSame = it->second.
IsSameAs(otherVal);
2308 wxLogTrace(compareTraceMask,
2309 _T(
"(%s) Comparison failed for the last object"),
2310 __PRETTY_FUNCTION__);
2317 wxFAIL_MSG(_T(
"wxJSONValue::IsSameAs() unexpected wxJSONType"));
2350 wxJSON_ASSERT(data);
2352 wxLogTrace(traceMask, _T(
"(%s) comment=%s"), __PRETTY_FUNCTION__,
2355 int len = str.length();
2357 wxLogTrace(traceMask, _T(
" error: len < 2"));
2360 if (str[0] !=
'/') {
2361 wxLogTrace(traceMask, _T(
" error: does not start with\'/\'"));
2364 if (str[1] ==
'/') {
2365 wxLogTrace(traceMask, _T(
" C++ comment" ));
2366 if (str.GetChar(len - 1) !=
'\n') {
2368 temp.append(1,
'\n');
2369 data->m_comments.Add(temp);
2370 wxLogTrace(traceMask, _T(
" C++ comment: LF added"));
2372 data->m_comments.Add(str);
2374 r = data->m_comments.size();
2375 }
else if (str[1] ==
2377 wxLogTrace(traceMask, _T(
" C-style comment"));
2378 int lastPos = len - 1;
2379 wxChar ch = str.GetChar(lastPos);
2381 while (ch ==
' ' || ch ==
'\n' || ch ==
'\t') {
2383 ch = str.GetChar(lastPos);
2385 if (str.GetChar(lastPos) ==
'/' && str.GetChar(lastPos - 1) ==
'*') {
2386 data->m_comments.Add(str);
2387 r = data->m_comments.size();
2390 wxLogTrace(traceMask, _T(
" error: is not a valid comment string"));
2394 if (r >= 0 && position != wxJSONVALUE_COMMENT_DEFAULT) {
2395 data->m_commentPos = position;
2408 int siz = comments.GetCount();
2410 for (
int i = 0; i < siz; i++) {
2428 wxJSON_ASSERT(data);
2431 int size = data->m_comments.GetCount();
2433 for (
int i = 0; i < size; i++) {
2434 s.append(data->m_comments[i]);
2436 }
else if (idx < size) {
2437 s = data->m_comments[idx];
2445 wxJSON_ASSERT(data);
2447 int d = data->m_comments.GetCount();
2448 wxLogTrace(traceMask, _T(
"(%s) comment count=%d"), __PRETTY_FUNCTION__, d);
2455 wxJSON_ASSERT(data);
2456 return data->m_commentPos;
2462 wxJSON_ASSERT(data);
2464 return data->m_comments;
2470 wxJSON_ASSERT(data);
2472 data->m_comments.clear();
2539 wxJSONType oldType =
GetType();
2542 wxJSON_ASSERT((type >= wxJSONTYPE_INVALID) &&
2543 (type <= wxJSONTYPE_MEMORYBUFF));
2544 if ((type < wxJSONTYPE_INVALID) || (type > wxJSONTYPE_MEMORYBUFF)) {
2545 type = wxJSONTYPE_INVALID;
2558 if (type == oldType) {
2564 if (type == wxJSONTYPE_LONG || type == wxJSONTYPE_INT64 ||
2565 type == wxJSONTYPE_SHORT) {
2566 type = wxJSONTYPE_INT;
2568 if (type == wxJSONTYPE_ULONG || type == wxJSONTYPE_UINT64 ||
2569 type == wxJSONTYPE_USHORT) {
2570 type = wxJSONTYPE_UINT;
2573 wxJSON_ASSERT(data);
2574 data->m_type = type;
2578 case wxJSONTYPE_STRING:
2579 data->m_valString.clear();
2581 case wxJSONTYPE_ARRAY:
2582 data->m_valArray.Clear();
2584 case wxJSONTYPE_OBJECT:
2585 data->m_valMap.clear();
2587 case wxJSONTYPE_MEMORYBUFF:
2589 if (data->m_memBuff) {
2590 delete data->m_memBuff;
2591 data->m_memBuff = 0;
2601#if !defined(WXJSON_USE_CSTRING)
2602 if (data->m_type == wxJSONTYPE_CSTRING) {
2603 data->m_type = wxJSONTYPE_STRING;
2632 wxJSON_ASSERT(data);
2633 data->m_lineNo = num;
2701 wxJSON_ASSERT(otherData);
2711 data->m_type = other->
m_type;
2712 data->m_value = other->
m_value;
2724 data->m_memBuff =
new wxMemoryBuffer();
2725 const void* ptr = data->m_memBuff->GetData();
2726 size_t len = data->m_memBuff->GetDataLen();
2727 if (data->m_memBuff && len) {
2728 data->m_memBuff->AppendData(ptr, len);
2732 wxLogTrace(cowTraceMask, _T(
"(%s) CloneRefData() PROGR: other=%d data=%d"),
2733 __PRETTY_FUNCTION__, other->GetRefCount(), data->GetRefCount());
2747 data->m_type = wxJSONTYPE_INVALID;
2760 wxLogTrace(cowTraceMask, _T(
"(%s) COW() START data=%p data->m_count=%d"),
2761 __PRETTY_FUNCTION__, data, data->GetRefCount());
2764 wxLogTrace(cowTraceMask, _T(
"(%s) COW() END data=%p data->m_count=%d"),
2765 __PRETTY_FUNCTION__, data, data->GetRefCount());
2773 }
else if (
m_refData->GetRefCount() > 1) {
2784 _T(
"wxObject::AllocExclusive() failed."));
2807 size_t buffLen = buff.GetDataLen();
2808 void* ptr = buff.GetData();
2837 size_t buffLen = actualLen;
2838 if (buffLen == (
size_t)-1) {
2841 s.Printf(_T(
"%p (%u) "), buff, buffLen);
2842 unsigned char* ptr = (
unsigned char*)buff;
2843 for (
unsigned int i = 0; i < len; i++) {
2844 unsigned char c = *ptr;
2890 const wxMemoryBuffer& buff2) {
2892 size_t buff1Len = buff1.GetDataLen();
2893 size_t buff2Len = buff2.GetDataLen();
2894 if (buff1Len > buff2Len) {
2896 }
else if (buff1Len < buff2Len) {
2899 r = memcmp(buff1.GetData(), buff2.GetData(), buff1Len);
2917 const void* buff2) {
2919 size_t buff1Len = buff1.GetDataLen();
2920 r = memcmp(buff1.GetData(), buff2, buff1Len);
2946 wxMemoryBuffer buff;
2947 if (value.IsArray()) {
2948 int len = value.Size();
2949 for (
int i = 0; i < len; i++) {
2954 bool r = value.ItemAt(i).AsShort(
byte);
2955 if (r && (
byte >= 0 &&
byte <= 255)) {
2956 c = (
unsigned char)
byte;
2970#if defined(wxJSON_64BIT_INT)
2976 wxJSON_ASSERT(data);
2978 data->m_value.VAL_INT = i;
2986 wxJSON_ASSERT(data);
2988 data->m_value.VAL_UINT = ui;
3001bool wxJSONValue::IsInt32()
const {
3015bool wxJSONValue::IsUInt32()
const {
3030bool wxJSONValue::IsInt64()
const {
3032 wxJSON_ASSERT(data);
3034 if (data->m_type == wxJSONTYPE_INT) {
3050bool wxJSONValue::IsUInt64()
const {
3052 wxJSON_ASSERT(data);
3054 if (data->m_type == wxJSONTYPE_UINT) {
3072wxInt32 wxJSONValue::AsInt32()
const {
3090wxUint32 wxJSONValue::AsUInt32()
const {
3110wxInt64 wxJSONValue::AsInt64()
const {
3112 wxJSON_ASSERT(data);
3113 wxInt64 i64 = data->m_value.m_valInt64;
3115 wxJSON_ASSERT(IsInt64());
3133wxUint64 wxJSONValue::AsUInt64()
const {
3135 wxJSON_ASSERT(data);
3136 wxUint64 ui64 = data->m_value.m_valUInt64;
3138 wxJSON_ASSERT(IsUInt64());
3142bool wxJSONValue::AsInt32(wxInt32& i32)
const {
3150bool wxJSONValue::AsUInt32(wxUint32& ui32)
const {
3151 bool r = IsUInt32();
3158bool wxJSONValue::AsInt64(wxInt64& i64)
const {
3166bool wxJSONValue::AsUInt64(wxUint64& ui64)
const {
3167 bool r = IsUInt64();
3191 data->m_value.VAL_INT = i;
3198 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.