OpenCPN Partial API docs
Loading...
Searching...
No Matches
jsonreader.h
1
2// Name: jsonreader.h
3// Purpose: the parser of JSON text
4// Author: Luciano Cattani
5// Created: 2007/09/15
6// Copyright: (c) 2007 Luciano Cattani
7// Licence: wxWidgets licence
9
10#ifndef WX_JSONREADER_H
11#define WX_JSONREADER_H
12
13#ifdef __GNUG__
14#pragma interface "jsonreader.h"
15#endif
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include <wx/wxprec.h>
19
20// for all others, include the necessary headers (this file is usually all you
21// need because it includes almost all "standard" wxWidgets headers)
22#ifndef WX_PRECOMP
23#include <wx/stream.h>
24#include <wx/string.h>
25#include <wx/arrstr.h>
26#endif
27
28#include "json_defs.h"
29#include "jsonval.h"
30
31// The flags of the parser
32enum {
33 wxJSONREADER_STRICT = 0,
34 wxJSONREADER_ALLOW_COMMENTS = 1,
35 wxJSONREADER_STORE_COMMENTS = 2,
36 wxJSONREADER_CASE = 4,
37 wxJSONREADER_MISSING = 8,
38 wxJSONREADER_MULTISTRING = 16,
39 wxJSONREADER_COMMENTS_AFTER = 32,
40 wxJSONREADER_NOUTF8_STREAM = 64,
41 wxJSONREADER_MEMORYBUFF = 128,
42
43 wxJSONREADER_TOLERANT = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_CASE |
44 wxJSONREADER_MISSING | wxJSONREADER_MULTISTRING,
45 wxJSONREADER_COMMENTS_BEFORE =
46 wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_STORE_COMMENTS
47};
48
49class WXDLLIMPEXP_JSON wxJSONReader {
50public:
51 wxJSONReader(int flags = wxJSONREADER_TOLERANT, int maxErrors = 30);
52 virtual ~wxJSONReader();
53
54 int Parse(const wxString& doc, wxJSONValue* val);
55 int Parse(wxInputStream& doc, wxJSONValue* val);
56
57 int GetDepth() const;
58 int GetErrorCount() const;
59 int GetWarningCount() const;
60 const wxArrayString& GetErrors() const;
61 const wxArrayString& GetWarnings() const;
62
63 static int UTF8NumBytes(char ch);
64
65#if defined(wxJSON_64BIT_INT)
66 static bool Strtoll(const wxString& str, wxInt64* i64);
67 static bool Strtoull(const wxString& str, wxUint64* ui64);
68 static bool DoStrto_ll(const wxString& str, wxUint64* ui64, wxChar* sign);
69#endif
70
71protected:
72 int DoRead(wxInputStream& doc, wxJSONValue& val);
73 void AddError(const wxString& descr);
74 void AddError(const wxString& fmt, const wxString& str);
75 void AddError(const wxString& fmt, wxChar ch);
76 void AddWarning(int type, const wxString& descr);
77 int GetStart(wxInputStream& is);
78 int ReadChar(wxInputStream& is);
79 int PeekChar(wxInputStream& is);
80 void StoreValue(int ch, const wxString& key, wxJSONValue& value,
81 wxJSONValue& parent);
82 int SkipWhiteSpace(wxInputStream& is);
83 int SkipComment(wxInputStream& is);
84 void StoreComment(const wxJSONValue* parent);
85 int ReadString(wxInputStream& is, wxJSONValue& val);
86 int ReadToken(wxInputStream& is, int ch, wxString& s);
87 int ReadValue(wxInputStream& is, int ch, wxJSONValue& val);
88 int ReadUES(wxInputStream& is, char* uesBuffer);
89 int AppendUES(wxMemoryBuffer& utf8Buff, const char* uesBuffer);
90 int NumBytes(char ch);
91 int ConvertCharByChar(wxString& s, const wxMemoryBuffer& utf8Buffer);
92 int ReadMemoryBuff(wxInputStream& is, wxJSONValue& val);
93
95 int m_flags;
96
98 int m_maxErrors;
99
101 int m_lineNo;
102
104 int m_colNo;
105
107 int m_level;
108
110 int m_depth;
111
113 wxJSONValue* m_current;
114
116 wxJSONValue* m_lastStored;
117
119 wxJSONValue* m_next;
120
122 wxString m_comment;
123
125 int m_commentLine;
126
128 wxArrayString m_errors;
129
131 wxArrayString m_warnings;
132
134 int m_peekChar;
135
137 bool m_noUtf8;
138};
139
140#endif // WX_JSONREADER_H
The JSON parser.
Definition jsonreader.h:45
The JSON value class implementation.
Definition jsonval.h:79