JsonCpp project page JsonCpp home page

writer.h
Go to the documentation of this file.
1#ifndef JSON_WRITER_H_INCLUDED
2# define JSON_WRITER_H_INCLUDED
3
4# include "json/value.h"
5# include <vector>
6# include <string>
7# include <iostream>
8
9namespace Json {
10
11 class Value;
12
16 {
17 public:
18 virtual ~Writer();
19
20 virtual std::string write( const Value &root ) = 0;
21 };
22
29 class JSON_API FastWriter : public Writer
30 {
31 public:
32 FastWriter();
33 virtual ~FastWriter(){}
34
35 void enableYAMLCompatibility();
36
37 public: // overridden from Writer
38 virtual std::string write( const Value &root );
39
40 private:
41 void writeValue( const Value &value );
42
43 std::string document_;
44 bool yamlCompatiblityEnabled_;
45 };
46
66 {
67 public:
69 virtual ~StyledWriter(){}
70
71 public: // overridden from Writer
76 virtual std::string write( const Value &root );
77
78 private:
79 void writeValue( const Value &value );
80 void writeArrayValue( const Value &value );
81 bool isMultineArray( const Value &value );
82 void pushValue( const std::string &value );
83 void writeIndent();
84 void writeWithIndent( const std::string &value );
85 void indent();
86 void unindent();
87 void writeCommentBeforeValue( const Value &root );
88 void writeCommentAfterValueOnSameLine( const Value &root );
89 bool hasCommentForValue( const Value &value );
90 static std::string normalizeEOL( const std::string &text );
91
92 typedef std::vector<std::string> ChildValues;
93
94 ChildValues childValues_;
95 std::string document_;
96 std::string indentString_;
97 int rightMargin_;
98 int indentSize_;
99 bool addChildValues_;
100 };
101
123 {
124 public:
125 StyledStreamWriter( std::string indentation="\t" );
127
128 public:
134 void write( std::ostream &out, const Value &root );
135
136 private:
137 void writeValue( const Value &value );
138 void writeArrayValue( const Value &value );
139 bool isMultineArray( const Value &value );
140 void pushValue( const std::string &value );
141 void writeIndent();
142 void writeWithIndent( const std::string &value );
143 void indent();
144 void unindent();
145 void writeCommentBeforeValue( const Value &root );
146 void writeCommentAfterValueOnSameLine( const Value &root );
147 bool hasCommentForValue( const Value &value );
148 static std::string normalizeEOL( const std::string &text );
149
150 typedef std::vector<std::string> ChildValues;
151
152 ChildValues childValues_;
153 std::ostream* document_;
154 std::string indentString_;
155 int rightMargin_;
156 std::string indentation_;
157 bool addChildValues_;
158 };
159
160 std::string JSON_API valueToString( Int value );
161 std::string JSON_API valueToString( UInt value );
162 std::string JSON_API valueToString( double value );
163 std::string JSON_API valueToString( bool value );
164 std::string JSON_API valueToQuotedString( const char *value );
165
168 std::ostream& operator<<( std::ostream&, const Value &root );
169
170} // namespace Json
171
172
173
174#endif // JSON_WRITER_H_INCLUDED
Outputs a Value in JSON format without formatting (not human friendly).
Definition: writer.h:30
virtual ~FastWriter()
Definition: writer.h:33
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.
Definition: writer.h:123
Writes a Value in JSON format in a human friendly way.
Definition: writer.h:66
virtual ~StyledWriter()
Definition: writer.h:69
Represents a JSON value.
Definition: value.h:112
Abstract class for writers.
Definition: writer.h:16
virtual std::string write(const Value &root)=0
#define JSON_API
Definition: config.h:40
JSON (JavaScript Object Notation).
Definition: features.h:6
int Int
Definition: forwards.h:19
std::string valueToString(Int value)
Definition: json_writer.cpp:42
unsigned int UInt
Definition: forwards.h:20
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
std::string valueToQuotedString(const char *value)

SourceForge Logo hosts this site. Send comments to:
Json-cpp Developers