[CodeGen] Convert IslNodeBuilder::getNumberOfIterations to isl++. NFC.
[polly-mirror.git] / lib / External / JSON / include / json / writer.h
blob83def71657ebad8ee634c5fc3016e27e7f674986
1 #ifndef JSON_WRITER_H_INCLUDED
2 # define JSON_WRITER_H_INCLUDED
4 # include "value.h"
5 # include <vector>
6 # include <string>
7 # include <iostream>
9 namespace Json {
11 class Value;
13 /** \brief Abstract class for writers.
15 class JSON_API Writer
17 public:
18 virtual ~Writer();
20 virtual std::string write( const Value &root ) = 0;
23 /** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly).
25 * The JSON document is written in a single line. It is not intended for 'human' consumption,
26 * but may be useful to support feature such as RPC where bandwidth is limited.
27 * \sa Reader, Value
29 class JSON_API FastWriter : public Writer
31 public:
32 FastWriter();
33 virtual ~FastWriter(){}
35 void enableYAMLCompatibility();
37 public: // overridden from Writer
38 virtual std::string write( const Value &root );
40 private:
41 void writeValue( const Value &value );
43 std::string document_;
44 bool yamlCompatiblityEnabled_;
47 /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way.
49 * The rules for line break and indent are as follow:
50 * - Object value:
51 * - if empty then print {} without indent and line break
52 * - if not empty the print '{', line break & indent, print one value per line
53 * and then unindent and line break and print '}'.
54 * - Array value:
55 * - if empty then print [] without indent and line break
56 * - if the array contains no object value, empty array or some other value types,
57 * and all the values fit on one lines, then print the array on a single line.
58 * - otherwise, it the values do not fit on one line, or the array contains
59 * object or non empty array, then print one value per line.
61 * If the Value have comments then they are outputed according to their #CommentPlacement.
63 * \sa Reader, Value, Value::setComment()
65 class JSON_API StyledWriter: public Writer
67 public:
68 StyledWriter();
69 virtual ~StyledWriter(){}
71 public: // overridden from Writer
72 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
73 * \param root Value to serialize.
74 * \return String containing the JSON document that represents the root value.
76 virtual std::string write( const Value &root );
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 );
92 typedef std::vector<std::string> ChildValues;
94 ChildValues childValues_;
95 std::string document_;
96 std::string indentString_;
97 int rightMargin_;
98 int indentSize_;
99 bool addChildValues_;
102 /** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way,
103 to a stream rather than to a string.
105 * The rules for line break and indent are as follow:
106 * - Object value:
107 * - if empty then print {} without indent and line break
108 * - if not empty the print '{', line break & indent, print one value per line
109 * and then unindent and line break and print '}'.
110 * - Array value:
111 * - if empty then print [] without indent and line break
112 * - if the array contains no object value, empty array or some other value types,
113 * and all the values fit on one lines, then print the array on a single line.
114 * - otherwise, it the values do not fit on one line, or the array contains
115 * object or non empty array, then print one value per line.
117 * If the Value have comments then they are outputed according to their #CommentPlacement.
119 * \sa Reader, Value, Value::setComment()
121 class JSON_API StyledStreamWriter
123 public:
124 StyledStreamWriter( std::string indentation="\t" );
125 ~StyledStreamWriter(){}
127 public:
128 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
129 * \param out Stream to write to. (Can be ostringstream, e.g.)
130 * \param root Value to serialize.
131 * \note There is no point in deriving from Writer, since write() should not return a value.
133 void write( std::ostream &out, const Value &root );
135 private:
136 void writeValue( const Value &value );
137 void writeArrayValue( const Value &value );
138 bool isMultineArray( const Value &value );
139 void pushValue( const std::string &value );
140 void writeIndent();
141 void writeWithIndent( const std::string &value );
142 void indent();
143 void unindent();
144 void writeCommentBeforeValue( const Value &root );
145 void writeCommentAfterValueOnSameLine( const Value &root );
146 bool hasCommentForValue( const Value &value );
147 static std::string normalizeEOL( const std::string &text );
149 typedef std::vector<std::string> ChildValues;
151 ChildValues childValues_;
152 std::ostream* document_;
153 std::string indentString_;
154 int rightMargin_;
155 std::string indentation_;
156 bool addChildValues_;
159 std::string JSON_API valueToString( Int value );
160 std::string JSON_API valueToString( UInt value );
161 std::string JSON_API valueToString( double value );
162 std::string JSON_API valueToString( bool value );
163 std::string JSON_API valueToQuotedString( const char *value );
165 /// \brief Output using the StyledStreamWriter.
166 /// \see Json::operator>>()
167 std::ostream& operator<<( std::ostream&, const Value &root );
169 } // namespace Json
173 #endif // JSON_WRITER_H_INCLUDED