OpenCPN Partial API docs
Loading...
Searching...
No Matches
jsonwriter.h
1
2// Name: jsonwriter.h
3// Purpose: the generator of JSON text from a JSON value
4// Author: Luciano Cattani
5// Created: 2007/09/15
6// Copyright: (c) 2007 Luciano Cattani
7// Licence: wxWidgets licence
9
10#ifndef WX_JSONWRITER_H
11#define WX_JSONWRITER_H
12
13// For compilers that support precompilation, includes "wx/wx.h".
14#include <wx/wxprec.h>
15
16// for all others, include the necessary headers (this file is usually all you
17// need because it includes almost all "standard" wxWidgets headers)
18#ifndef WX_PRECOMP
19#include <wx/stream.h>
20#include <wx/string.h>
21#endif
22
23#include "json_defs.h"
24#include "jsonval.h"
25
26enum {
27 wxJSONWRITER_NONE = 0,
28 wxJSONWRITER_STYLED = 1,
29 wxJSONWRITER_WRITE_COMMENTS = 2,
30 wxJSONWRITER_COMMENTS_BEFORE = 4,
31 wxJSONWRITER_COMMENTS_AFTER = 8,
32 wxJSONWRITER_SPLIT_STRING = 16,
33 wxJSONWRITER_NO_LINEFEEDS = 32,
34 wxJSONWRITER_ESCAPE_SOLIDUS = 64,
35 wxJSONWRITER_MULTILINE_STRING = 128,
36 wxJSONWRITER_RECOGNIZE_UNSIGNED = 256,
37 wxJSONWRITER_TAB_INDENT = 512,
38 wxJSONWRITER_NO_INDENTATION = 1024,
39 wxJSONWRITER_NOUTF8_STREAM = 2048,
40 wxJSONWRITER_MEMORYBUFF = 4096
41};
42
43// class declaration
44
45class WXDLLIMPEXP_JSON wxJSONWriter {
46public:
47 wxJSONWriter(int style = wxJSONWRITER_STYLED, int indent = 0, int step = 3);
49
50 void Write(const wxJSONValue& value, wxString& str);
51 void Write(const wxJSONValue& value, wxOutputStream& os);
52 void SetDoubleFmtString(const char* fmt);
53
54protected:
55 int DoWrite(wxOutputStream& os, const wxJSONValue& value, const wxString* key,
56 bool comma);
57 int WriteIndent(wxOutputStream& os);
58 int WriteIndent(wxOutputStream& os, int num);
59 bool IsSpace(wxChar ch);
60 bool IsPunctuation(wxChar ch);
61
62 int WriteString(wxOutputStream& os, const wxString& str);
63 int WriteStringValue(wxOutputStream& os, const wxString& str);
64 int WriteNullValue(wxOutputStream& os);
65 int WriteIntValue(wxOutputStream& os, const wxJSONValue& v);
66 int WriteUIntValue(wxOutputStream& os, const wxJSONValue& v);
67 int WriteBoolValue(wxOutputStream& os, const wxJSONValue& v);
68 int WriteDoubleValue(wxOutputStream& os, const wxJSONValue& v);
69 int WriteMemoryBuff(wxOutputStream& os, const wxMemoryBuffer& buff);
70
71 int WriteInvalid(wxOutputStream& os);
72 int WriteSeparator(wxOutputStream& os);
73
74 int WriteKey(wxOutputStream& os, const wxString& key);
75 int WriteComment(wxOutputStream& os, const wxJSONValue& value, bool indent);
76
77 int WriteError(const wxString& err);
78
79private:
81 int m_style;
82
84 int m_indent;
85
87 int m_step;
88
91 int m_level;
92
93 // The line number when printing JSON text output (not yet used)
94 int m_lineNo;
95
96 // The column number when printing JSON text output
97 int m_colNo;
98
99 // Flag used in ANSI mode that controls UTF-8 conversion
100 bool m_noUtf8;
101
102 // The format string for printing doubles
103 char* m_fmt;
104};
105
106#endif // WX_JSONWRITER_H
The JSON value class implementation.
Definition jsonval.h:79
The JSON document writer.
Definition jsonwriter.h:45