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// RCS-ID: $Id: jsonreader.h,v 1.3 2008/03/03 19:05:45 luccat Exp $
7// Copyright: (c) 2007 Luciano Cattani
8// Licence: wxWidgets licence
10
11#if !defined(_WX_JSONREADER_H)
12#define _WX_JSONREADER_H
13
14#ifdef __GNUG__
15#pragma interface "jsonreader.h"
16#endif
17
18// For compilers that support precompilation, includes "wx/wx.h".
19#include "wx/wxprec.h"
20
21#ifdef __BORLANDC__
22#pragma hdrstop
23#endif
24
25// for all others, include the necessary headers (this file is usually all you
26// need because it includes almost all "standard" wxWidgets headers)
27#ifndef WX_PRECOMP
28#include <wx/stream.h>
29#include <wx/string.h>
30#include <wx/arrstr.h>
31#endif
32
33#include "json_defs.h"
34#include "jsonval.h"
35
36// The flags of the parser
37enum {
38 wxJSONREADER_STRICT = 0,
39 wxJSONREADER_ALLOW_COMMENTS = 1,
40 wxJSONREADER_STORE_COMMENTS = 2,
41 wxJSONREADER_CASE = 4,
42 wxJSONREADER_MISSING = 8,
43 wxJSONREADER_MULTISTRING = 16,
44 wxJSONREADER_COMMENTS_AFTER = 32,
45 wxJSONREADER_NOUTF8_STREAM = 64,
46 wxJSONREADER_MEMORYBUFF = 128,
47
48 wxJSONREADER_TOLERANT = wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_CASE |
49 wxJSONREADER_MISSING | wxJSONREADER_MULTISTRING,
50 wxJSONREADER_COMMENTS_BEFORE =
51 wxJSONREADER_ALLOW_COMMENTS | wxJSONREADER_STORE_COMMENTS
52};
53
54class WXDLLIMPEXP_JSON wxJSONReader {
55public:
56 wxJSONReader(int flags = wxJSONREADER_TOLERANT, int maxErrors = 30);
57 virtual ~wxJSONReader();
58
59 int Parse(const wxString& doc, wxJSONValue* val);
60 int Parse(wxInputStream& doc, wxJSONValue* val);
61
62 int GetDepth() const;
63 int GetErrorCount() const;
64 int GetWarningCount() const;
65 const wxArrayString& GetErrors() const;
66 const wxArrayString& GetWarnings() const;
67
68 static int UTF8NumBytes(char ch);
69
70#if defined(wxJSON_64BIT_INT)
71 static bool Strtoll(const wxString& str, wxInt64* i64);
72 static bool Strtoull(const wxString& str, wxUint64* ui64);
73 static bool DoStrto_ll(const wxString& str, wxUint64* ui64, wxChar* sign);
74#endif
75
76protected:
77 int DoRead(wxInputStream& doc, wxJSONValue& val);
78 void AddError(const wxString& descr);
79 void AddError(const wxString& fmt, const wxString& str);
80 void AddError(const wxString& fmt, wxChar ch);
81 void AddWarning(int type, const wxString& descr);
82 int GetStart(wxInputStream& is);
83 int ReadChar(wxInputStream& is);
84 int PeekChar(wxInputStream& is);
85 void StoreValue(int ch, const wxString& key, wxJSONValue& value,
86 wxJSONValue& parent);
87 int SkipWhiteSpace(wxInputStream& is);
88 int SkipComment(wxInputStream& is);
89 void StoreComment(const wxJSONValue* parent);
90 int ReadString(wxInputStream& is, wxJSONValue& val);
91 int ReadToken(wxInputStream& is, int ch, wxString& s);
92 int ReadValue(wxInputStream& is, int ch, wxJSONValue& val);
93 int ReadUES(wxInputStream& is, char* uesBuffer);
94 int AppendUES(wxMemoryBuffer& utf8Buff, const char* uesBuffer);
95 int NumBytes(char ch);
96 int ConvertCharByChar(wxString& s, const wxMemoryBuffer& utf8Buffer);
97 int ReadMemoryBuff(wxInputStream& is, wxJSONValue& val);
98
100 int m_flags;
101
103 int m_maxErrors;
104
106 int m_lineNo;
107
109 int m_colNo;
110
112 int m_level;
113
115 int m_depth;
116
118 wxJSONValue* m_current;
119
121 wxJSONValue* m_lastStored;
122
124 wxJSONValue* m_next;
125
127 wxString m_comment;
128
130 int m_commentLine;
131
133 wxArrayString m_errors;
134
136 wxArrayString m_warnings;
137
139 int m_peekChar;
140
142 bool m_noUtf8;
143};
144
145#endif // not defined _WX_JSONREADER_H
The JSON parser.
Definition jsonreader.h:50
The JSON value class implementation.
Definition jsonval.h:84