2525
2626#include " JSON.h"
2727
28- #include " clFontHelper.h"
2928#include " fileutils.h"
3029
3130#include < wx/filename.h>
3231
3332JSON::JSON (const wxString& text)
34- : m_json(NULL )
3533{
3634 m_json = cJSON_Parse (text.mb_str (wxConvUTF8).data ());
3735}
3836
39- JSON::JSON (JSONItem item)
40- : m_json(item.release())
41- {
42- }
43-
4437JSON::JSON (JsonType type)
45- : m_json(NULL )
4638{
4739 if (type == JsonType::Array)
4840 m_json = cJSON_CreateArray ();
@@ -53,7 +45,6 @@ JSON::JSON(JsonType type)
5345}
5446
5547JSON::JSON (const wxFileName& filename)
56- : m_json(NULL )
5748{
5849 wxString content;
5950 if (!FileUtils::ReadFileContent (filename, content)) {
@@ -68,7 +59,7 @@ JSON::~JSON()
6859{
6960 if (m_json) {
7061 cJSON_Delete (m_json);
71- m_json = NULL ;
62+ m_json = nullptr ;
7263 }
7364}
7465
@@ -84,42 +75,28 @@ void JSON::save(const wxFileName& fn) const
8475JSONItem JSON::toElement () const
8576{
8677 if (!m_json) {
87- return JSONItem (NULL );
78+ return JSONItem (nullptr );
8879 }
8980 return JSONItem (m_json);
9081}
9182
9283JSONItem JSONItem::namedObject (const wxString& name) const
9384{
9485 if (!m_json) {
95- return JSONItem (NULL );
86+ return JSONItem (nullptr );
9687 }
9788
9889 cJSON* obj = cJSON_GetObjectItem (m_json, name.mb_str (wxConvUTF8).data ());
9990 if (!obj) {
100- return JSONItem (NULL );
91+ return JSONItem (nullptr );
10192 }
10293 return JSONItem (obj);
10394}
10495
105- void JSON::clear ()
106- {
107- int type = cJSON_Object;
108- if (m_json) {
109- type = m_json->type ;
110- cJSON_Delete (m_json);
111- m_json = NULL ;
112- }
113- if (type == cJSON_Array)
114- m_json = cJSON_CreateArray ();
115- else
116- m_json = cJSON_CreateObject ();
117- }
118-
11996cJSON* JSON::release ()
12097{
12198 cJSON* p = m_json;
122- m_json = NULL ;
99+ m_json = nullptr ;
123100 return p;
124101}
125102
@@ -135,7 +112,7 @@ JSONItem JSONItem::operator[](int index) const
135112 if (isArray ()) {
136113 return arrayItem (index);
137114 }
138- return JSONItem (NULL );
115+ return JSONItem (nullptr );
139116}
140117
141118std::unordered_map<std::string_view, JSONItem> JSONItem::GetAsMap () const
@@ -175,15 +152,15 @@ JSONItem JSONItem::operator[](const wxString& name) const { return namedObject(n
175152JSONItem JSONItem::arrayItem (int pos) const
176153{
177154 if (!m_json) {
178- return JSONItem (NULL );
155+ return JSONItem (nullptr );
179156 }
180157
181158 if (m_json->type != cJSON_Array)
182- return JSONItem (NULL );
159+ return JSONItem (nullptr );
183160
184161 int size = cJSON_GetArraySize (m_json);
185162 if (pos >= size)
186- return JSONItem (NULL );
163+ return JSONItem (nullptr );
187164
188165 return JSONItem (cJSON_GetArrayItem (m_json, pos));
189166}
@@ -249,7 +226,7 @@ void JSONItem::arrayAppend(const char* value)
249226 cJSON_AddItemToArray (m_json, p);
250227}
251228
252- void JSONItem::arrayAppend (const std::string& value) { arrayAppend (( const char *) value.c_str ()); }
229+ void JSONItem::arrayAppend (const std::string& value) { arrayAppend (value.c_str ()); }
253230
254231void JSONItem::arrayAppend (double number)
255232{
@@ -262,7 +239,7 @@ void JSONItem::arrayAppend(double number)
262239
263240void JSONItem::arrayAppend (int number) { arrayAppend ((double )number); }
264241
265- void JSONItem::arrayAppend (const wxString& value) { arrayAppend (( const char *) value.mb_str (wxConvUTF8).data ()); }
242+ void JSONItem::arrayAppend (const wxString& value) { arrayAppend (value.mb_str (wxConvUTF8).data ()); }
266243
267244void JSONItem::arrayAppend (JSONItem&& element)
268245{
@@ -289,7 +266,7 @@ JSONItem JSONItem::createObject()
289266char * JSONItem::FormatRawString (bool formatted) const
290267{
291268 if (!m_json) {
292- return NULL ;
269+ return nullptr ;
293270 }
294271
295272 if (formatted) {
@@ -443,15 +420,9 @@ bool JSONItem::hasNamedObject(const wxString& name) const
443420 }
444421
445422 cJSON* obj = cJSON_GetObjectItem (m_json, name.mb_str (wxConvUTF8).data ());
446- return obj != NULL ;
423+ return obj != nullptr ;
447424}
448425#if wxUSE_GUI
449- JSONItem& JSONItem::addProperty (const wxString& name, const wxPoint& pt)
450- {
451- wxString szStr;
452- szStr << pt.x << " ," << pt.y ;
453- return addProperty (name, szStr);
454- }
455426
456427JSONItem& JSONItem::addProperty (const wxString& name, const wxSize& sz)
457428{
@@ -460,14 +431,14 @@ JSONItem& JSONItem::addProperty(const wxString& name, const wxSize& sz)
460431 return addProperty (name, szStr);
461432}
462433
463- wxPoint JSONItem::toPoint () const
434+ wxSize JSONItem::toSize () const
464435{
465436 if (!m_json) {
466- return wxDefaultPosition ;
437+ return wxDefaultSize ;
467438 }
468439
469440 if (m_json->type != cJSON_String) {
470- return wxDefaultPosition ;
441+ return wxDefaultSize ;
471442 }
472443
473444 wxString str = m_json->valuestring ;
@@ -476,28 +447,11 @@ wxPoint JSONItem::toPoint() const
476447
477448 long nX (-1 ), nY (-1 );
478449 if (!x.ToLong (&nX) || !y.ToLong (&nY))
479- return wxDefaultPosition;
480-
481- return wxPoint (nX, nY);
482- }
483-
484- wxColour JSONItem::toColour (const wxColour& defaultColour) const
485- {
486- if (!m_json) {
487- return defaultColour;
488- }
450+ return wxDefaultSize;
489451
490- if (m_json->type != cJSON_String) {
491- return defaultColour;
492- }
493- return wxColour (m_json->valuestring );
452+ return wxSize (nX, nY);
494453}
495454
496- wxSize JSONItem::toSize () const
497- {
498- wxPoint pt = toPoint ();
499- return wxSize (pt.x , pt.y );
500- }
501455#endif
502456
503457JSONItem& JSONItem::addProperty (const wxString& name, const JSONItem& element)
@@ -551,17 +505,6 @@ wxStringMap_t JSONItem::toStringMap(const wxStringMap_t& default_map) const
551505
552506JSONItem& JSONItem::addProperty (const wxString& name, size_t value) { return addProperty (name, (int )value); }
553507
554- #if wxUSE_GUI
555- JSONItem& JSONItem::addProperty (const wxString& name, const wxColour& colour)
556- {
557- wxString colourValue;
558- if (colour.IsOk ()) {
559- colourValue = colour.GetAsString (wxC2S_HTML_SYNTAX);
560- }
561- return addProperty (name, colourValue);
562- }
563- #endif
564-
565508JSONItem& JSONItem::addNull (const wxString& name)
566509{
567510 if (m_json) {
@@ -575,22 +518,6 @@ JSONItem& JSONItem::addProperty(const wxString& name, const char* value, const w
575518 return addProperty (name, wxString (value, conv));
576519}
577520
578- #if wxUSE_GUI
579- JSONItem& JSONItem::addProperty (const wxString& name, const wxFont& font)
580- {
581- return addProperty (name, clFontHelper::ToString (font));
582- }
583-
584- wxFont JSONItem::toFont (const wxFont& defaultFont) const
585- {
586- wxString str = toString ();
587- if (str.IsEmpty ())
588- return defaultFont;
589- wxFont f = clFontHelper::FromString (str);
590- return f;
591- }
592- #endif
593-
594521bool JSONItem::isArray () const
595522{
596523 if (!m_json) {
0 commit comments