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