00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma once
00039
00040 # include "value.h"
00041 # include <vector>
00042 # include <string>
00043 # include <iosfwd>
00044
00045 namespace Json {
00046
00047 class Value;
00048
00051 class JSON_API Writer
00052 {
00053 public:
00054 virtual ~Writer();
00055
00056 virtual std::string write( const Value &root ) = 0;
00057 };
00058
00065 class JSON_API FastWriter : public Writer
00066 {
00067 public:
00068 FastWriter();
00069
00070 void enableYAMLCompatibility();
00071
00072 public:
00073 virtual std::string write( const Value &root );
00074
00075 private:
00076 void writeValue( const Value &value );
00077
00078 std::string document_;
00079 bool yamlCompatiblityEnabled_;
00080 };
00081
00100 class JSON_API StyledWriter: public Writer
00101 {
00102 public:
00103 StyledWriter();
00104
00105 public:
00110 virtual std::string write( const Value &root );
00111
00112 private:
00113 void writeValue( const Value &value );
00114 void writeArrayValue( const Value &value );
00115 bool isMultineArray( const Value &value );
00116 void pushValue( const std::string &value );
00117 void writeIndent();
00118 void writeWithIndent( const std::string &value );
00119 void indent();
00120 void unindent();
00121 void writeCommentBeforeValue( const Value &root );
00122 void writeCommentAfterValueOnSameLine( const Value &root );
00123 bool hasCommentForValue( const Value &value );
00124 static std::string normalizeEOL( const std::string &text );
00125
00126 typedef std::vector<std::string> ChildValues;
00127
00128 ChildValues childValues_;
00129 std::string document_;
00130 std::string indentString_;
00131 int rightMargin_;
00132 int indentSize_;
00133 bool addChildValues_;
00134 };
00135
00156 class JSON_API StyledStreamWriter
00157 {
00158 public:
00159 StyledStreamWriter( std::string indentation="\t" );
00160 ~StyledStreamWriter(){}
00161
00162 public:
00168 void write( std::ostream &out, const Value &root );
00169
00170 private:
00171 void writeValue( const Value &value );
00172 void writeArrayValue( const Value &value );
00173 bool isMultineArray( const Value &value );
00174 void pushValue( const std::string &value );
00175 void writeIndent();
00176 void writeWithIndent( const std::string &value );
00177 void indent();
00178 void unindent();
00179 void writeCommentBeforeValue( const Value &root );
00180 void writeCommentAfterValueOnSameLine( const Value &root );
00181 bool hasCommentForValue( const Value &value );
00182 static std::string normalizeEOL( const std::string &text );
00183
00184 typedef std::vector<std::string> ChildValues;
00185
00186 ChildValues childValues_;
00187 std::ostream* document_;
00188 std::string indentString_;
00189 int rightMargin_;
00190 std::string indentation_;
00191 bool addChildValues_;
00192 };
00193
00194 std::string JSON_API valueToString( Int value );
00195 std::string JSON_API valueToString( UInt value );
00196 std::string JSON_API valueToString( double value );
00197 std::string JSON_API valueToString( bool value );
00198 std::string JSON_API valueToQuotedString( const char *value );
00199
00202 std::ostream& operator<<( std::ostream&, const Value &root );
00203
00204 }