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#if !defined(_WX_JSONWRITER_H)
11#define _WX_JSONWRITER_H
12
13#ifdef __GNUG__
14#pragma interface "jsonwriter.h"
15#endif
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24// for all others, include the necessary headers (this file is usually all you
25// need because it includes almost all "standard" wxWidgets headers)
26#ifndef WX_PRECOMP
27#include <wx/stream.h>
28#include <wx/string.h>
29#endif
30
31#include "json_defs.h"
32#include "jsonval.h"
33
34enum {
35 wxJSONWRITER_NONE = 0,
36 wxJSONWRITER_STYLED = 1,
37 wxJSONWRITER_WRITE_COMMENTS = 2,
38 wxJSONWRITER_COMMENTS_BEFORE = 4,
39 wxJSONWRITER_COMMENTS_AFTER = 8,
40 wxJSONWRITER_SPLIT_STRING = 16,
41 wxJSONWRITER_NO_LINEFEEDS = 32,
42 wxJSONWRITER_ESCAPE_SOLIDUS = 64,
43 wxJSONWRITER_MULTILINE_STRING = 128,
44 wxJSONWRITER_RECOGNIZE_UNSIGNED = 256,
45 wxJSONWRITER_TAB_INDENT = 512,
46 wxJSONWRITER_NO_INDENTATION = 1024,
47 wxJSONWRITER_NOUTF8_STREAM = 2048,
48 wxJSONWRITER_MEMORYBUFF = 4096
49};
50
51// class declaration
52
53class WXDLLIMPEXP_JSON wxJSONWriter {
54public:
55 wxJSONWriter(int style = wxJSONWRITER_STYLED, int indent = 0, int step = 3);
57
58 void Write(const wxJSONValue& value, wxString& str);
59 void Write(const wxJSONValue& value, wxOutputStream& os);
60 void SetDoubleFmtString(const char* fmt);
61
62protected:
63 int DoWrite(wxOutputStream& os, const wxJSONValue& value, const wxString* key,
64 bool comma);
65 int WriteIndent(wxOutputStream& os);
66 int WriteIndent(wxOutputStream& os, int num);
67 bool IsSpace(wxChar ch);
68 bool IsPunctuation(wxChar ch);
69
70 int WriteString(wxOutputStream& os, const wxString& str);
71 int WriteStringValue(wxOutputStream& os, const wxString& str);
72 int WriteNullValue(wxOutputStream& os);
73 int WriteIntValue(wxOutputStream& os, const wxJSONValue& v);
74 int WriteUIntValue(wxOutputStream& os, const wxJSONValue& v);
75 int WriteBoolValue(wxOutputStream& os, const wxJSONValue& v);
76 int WriteDoubleValue(wxOutputStream& os, const wxJSONValue& v);
77 int WriteMemoryBuff(wxOutputStream& os, const wxMemoryBuffer& buff);
78
79 int WriteInvalid(wxOutputStream& os);
80 int WriteSeparator(wxOutputStream& os);
81
82 int WriteKey(wxOutputStream& os, const wxString& key);
83 int WriteComment(wxOutputStream& os, const wxJSONValue& value, bool indent);
84
85 int WriteError(const wxString& err);
86
87private:
89 int m_style;
90
92 int m_indent;
93
95 int m_step;
96
99 int m_level;
100
101 // The line number when printing JSON text output (not yet used)
102 int m_lineNo;
103
104 // The column number when printing JSON text output
105 int m_colNo;
106
107 // Flag used in ANSI mode that controls UTF-8 conversion
108 bool m_noUtf8;
109
110 // The format string for printing doubles
111 char* m_fmt;
112};
113
114#endif // not defined _WX_JSONWRITER_H
The JSON value class implementation.
Definition jsonval.h:79
The JSON document writer.
Definition jsonwriter.h:45
bool Write(const NavmsgFilter &filter, const std::string &name)
Write contents for given filter to disk.