Version: 0.6.0
jsonwriter.h
1 // 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 #ifdef __GNUG__
15  #pragma interface "jsonwriter.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 #endif
31 
32 #include "json_defs.h"
33 #include "jsonval.h"
34 
35 enum {
36  wxJSONWRITER_NONE = 0,
37  wxJSONWRITER_STYLED = 1,
38  wxJSONWRITER_WRITE_COMMENTS = 2,
39  wxJSONWRITER_COMMENTS_BEFORE = 4,
40  wxJSONWRITER_COMMENTS_AFTER = 8,
41  wxJSONWRITER_SPLIT_STRING = 16,
42  wxJSONWRITER_NO_LINEFEEDS = 32,
43  wxJSONWRITER_ESCAPE_SOLIDUS = 64,
44  wxJSONWRITER_MULTILINE_STRING = 128,
45  wxJSONWRITER_RECOGNIZE_UNSIGNED = 256,
46  wxJSONWRITER_TAB_INDENT = 512,
47  wxJSONWRITER_NO_INDENTATION = 1024,
48  wxJSONWRITER_NOUTF8_STREAM = 2048,
49  wxJSONWRITER_MEMORYBUFF = 4096
50 };
51 
52 // class declaration
53 
54 class WXDLLIMPEXP_JSON wxJSONWriter
55 {
56 public:
57  wxJSONWriter( int style = wxJSONWRITER_STYLED, int indent = 0, int step = 3 );
58  ~wxJSONWriter();
59 
60  void Write( const wxJSONValue& value, wxString& str );
61  void Write( const wxJSONValue& value, wxOutputStream& os );
62  void SetDoubleFmtString( const char* fmt );
63 
64 protected:
65 
66  int DoWrite( wxOutputStream& os, const wxJSONValue& value, const wxString* key, bool comma );
67  int WriteIndent( wxOutputStream& os );
68  int WriteIndent( wxOutputStream& os, int num );
69  bool IsSpace( wxChar ch );
70  bool IsPunctuation( wxChar ch );
71 
72  int WriteString( wxOutputStream& os, const wxString& str );
73  int WriteStringValue( wxOutputStream& os, const wxString& str );
74  int WriteNullValue( wxOutputStream& os );
75  int WriteIntValue( wxOutputStream& os, const wxJSONValue& v );
76  int WriteUIntValue( wxOutputStream& os, const wxJSONValue& v );
77  int WriteBoolValue( wxOutputStream& os, const wxJSONValue& v );
78  int WriteDoubleValue( wxOutputStream& os, const wxJSONValue& v );
79  int WriteMemoryBuff( wxOutputStream& os, const wxMemoryBuffer& buff );
80 
81  int WriteInvalid( wxOutputStream& os );
82  int WriteSeparator( wxOutputStream& os );
83 
84  int WriteKey( wxOutputStream& os, const wxString& key );
85  int WriteComment( wxOutputStream& os, const wxJSONValue& value, bool indent );
86 
87  int WriteError( const wxString& err );
88 
89 private:
91  int m_style;
92 
94  int m_indent;
95 
97  int m_step;
98 
100  int m_level;
101 
102  // The line number when printing JSON text output (not yet used)
103  int m_lineNo;
104 
105  // The column number when printing JSON text output
106  int m_colNo;
107 
108  // Flag used in ANSI mode that controls UTF-8 conversion
109  bool m_noUtf8;
110 
111  // The format string for printing doubles
112  char* m_fmt;
113 };
114 
115 
116 #endif // not defined _WX_JSONWRITER_H
117 
118 
119 
The JSON value class implementation.
Definition: jsonval.h:91
The JSON document writer.
Definition: jsonwriter.h:54