blob: 7c9ae21c7f9c615cda4c6b004f0a9ee9a830dbfb [file] [log] [blame]
Devin Jeanpierre59e4d352017-07-21 03:44:36 -07001// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
Baptiste Lepilleur7469f1d2010-04-20 21:35:19 +00002// Distributed under MIT license, or public domain if desired and
3// recognized in your jurisdiction.
4// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5
Christopher Dunn6d135cb2007-06-13 15:51:04 +00006#ifndef JSON_WRITER_H_INCLUDED
Aaron Jacobs9fa4e842014-07-01 08:48:54 +10007#define JSON_WRITER_H_INCLUDED
Christopher Dunn6d135cb2007-06-13 15:51:04 +00008
Baptiste Lepilleureadc4782011-05-02 21:09:30 +00009#if !defined(JSON_IS_AMALGAMATION)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100010#include "value.h"
Baptiste Lepilleureadc4782011-05-02 21:09:30 +000011#endif // if !defined(JSON_IS_AMALGAMATION)
Christopher Dunn177b7b82015-01-26 10:35:54 -060012#include <ostream>
Billy Donahueb5e1fe82018-05-20 16:55:27 -040013#include <string>
14#include <vector>
Christopher Dunn6d135cb2007-06-13 15:51:04 +000015
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100016// Disable warning C4251: <data member>: <type> needs to have dll-interface to
17// be used by...
Hugh Bellamy72870652017-09-16 10:01:09 +010018#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) && defined(_MSC_VER)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100019#pragma warning(push)
20#pragma warning(disable : 4251)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +000021#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
22
Sergiy80d6e666f2016-12-03 22:29:14 +020023#pragma pack(push, 8)
24
Christopher Dunn6d135cb2007-06-13 15:51:04 +000025namespace Json {
26
Aaron Jacobs9fa4e842014-07-01 08:48:54 +100027class Value;
Christopher Dunn489707f2015-01-22 15:25:30 -060028
29/**
30
31Usage:
Christopher Dunn9da9f842015-01-25 19:20:43 -060032\code
Christopher Dunn489707f2015-01-22 15:25:30 -060033 using namespace Json;
Christopher Dunn38042b32015-01-26 11:23:31 -060034 void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {
Christopher Dunn999f5912015-01-26 11:12:53 -060035 std::unique_ptr<StreamWriter> const writer(
Christopher Dunnc41609b2015-02-09 18:44:53 -060036 factory.newStreamWriter());
37 writer->write(value, &std::cout);
Christopher Dunn999f5912015-01-26 11:12:53 -060038 std::cout << std::endl; // add lf and flush
39 }
Christopher Dunn9da9f842015-01-25 19:20:43 -060040\endcode
Christopher Dunn489707f2015-01-22 15:25:30 -060041*/
Christopher Dunn5fbfe3c2015-01-22 14:31:32 -060042class JSON_API StreamWriter {
43protected:
Billy Donahueb5e1fe82018-05-20 16:55:27 -040044 JSONCPP_OSTREAM* sout_; // not owned; will not delete
Christopher Dunn5fbfe3c2015-01-22 14:31:32 -060045public:
Christopher Dunnc41609b2015-02-09 18:44:53 -060046 StreamWriter();
Christopher Dunn5fbfe3c2015-01-22 14:31:32 -060047 virtual ~StreamWriter();
Christopher Dunnc41609b2015-02-09 18:44:53 -060048 /** Write Value into document as configured in sub-class.
49 Do not take ownership of sout, but maintain a reference during function.
50 \pre sout != NULL
Billy Donahueb5e1fe82018-05-20 16:55:27 -040051 \return zero on success (For now, we always return zero, so check the
52 stream instead.) \throw std::exception possibly, depending on configuration
Christopher Dunnc41609b2015-02-09 18:44:53 -060053 */
Christopher Dunn724ba292016-03-06 11:47:35 -060054 virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
Christopher Dunn5fbfe3c2015-01-22 14:31:32 -060055
Christopher Dunn177b7b82015-01-26 10:35:54 -060056 /** \brief A simple abstract factory.
57 */
58 class JSON_API Factory {
59 public:
60 virtual ~Factory();
Christopher Dunna9e1ab32015-02-09 17:22:28 -060061 /** \brief Allocate a CharReader via operator new().
Christopher Dunna9e1ab32015-02-09 17:22:28 -060062 * \throw std::exception if something goes wrong (e.g. invalid settings)
63 */
Christopher Dunnc41609b2015-02-09 18:44:53 -060064 virtual StreamWriter* newStreamWriter() const = 0;
Billy Donahueb5e1fe82018-05-20 16:55:27 -040065 }; // Factory
66}; // StreamWriter
Christopher Dunn5fbfe3c2015-01-22 14:31:32 -060067
Christopher Dunn694dbcb2015-02-09 15:25:57 -060068/** \brief Write into stringstream, then return string, for convenience.
69 * A StreamWriter will be created from the factory, used, and then deleted.
70 */
Billy Donahueb5e1fe82018-05-20 16:55:27 -040071JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory,
72 Value const& root);
Christopher Dunn6065a1c2015-01-26 11:01:15 -060073
74/** \brief Build a StreamWriter implementation.
Christopher Dunn999f5912015-01-26 11:12:53 -060075
76Usage:
77\code
78 using namespace Json;
79 Value value = ...;
Christopher Dunn38042b32015-01-26 11:23:31 -060080 StreamWriterBuilder builder;
Christopher Dunn37dde9d2015-03-04 15:04:19 -060081 builder["commentStyle"] = "None";
82 builder["indentation"] = " "; // or whatever you like
Christopher Dunna9e1ab32015-02-09 17:22:28 -060083 std::unique_ptr<Json::StreamWriter> writer(
Christopher Dunnc41609b2015-02-09 18:44:53 -060084 builder.newStreamWriter());
85 writer->write(value, &std::cout);
Christopher Dunn999f5912015-01-26 11:12:53 -060086 std::cout << std::endl; // add lf and flush
87\endcode
88*/
Christopher Dunn6065a1c2015-01-26 11:01:15 -060089class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
Christopher Dunn6065a1c2015-01-26 11:01:15 -060090public:
Christopher Dunna9e1ab32015-02-09 17:22:28 -060091 // Note: We use a Json::Value so that we can add data-members to this class
92 // without a major version bump.
93 /** Configuration of this builder.
94 Available settings (case-sensitive):
Christopher Dunn5a744702015-02-10 21:15:43 -060095 - "commentStyle": "None" or "All"
uvok cheetahc7728e82018-03-03 12:45:54 +010096 - "indentation": "<anything>".
97 - Setting this to an empty string also omits newline characters.
Christopher Dunn29501c42015-02-10 23:03:27 -060098 - "enableYAMLCompatibility": false or true
Christopher Dunn5a744702015-02-10 21:15:43 -060099 - slightly change the whitespace around colons
Christopher Dunn29501c42015-02-10 23:03:27 -0600100 - "dropNullPlaceholders": false or true
Christopher Dunn5a744702015-02-10 21:15:43 -0600101 - Drop the "null" string from the writer's output for nullValues.
102 Strictly speaking, this is not valid JSON. But when the output is being
Josh Sorefe6a588a2017-12-03 11:54:29 -0500103 fed to a browser's JavaScript, it makes for smaller output and the
Christopher Dunn5a744702015-02-10 21:15:43 -0600104 browser can handle the output just fine.
drgler20845632015-09-03 22:19:22 +0200105 - "useSpecialFloats": false or true
106 - If true, outputs non-finite floating point values in the following way:
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400107 NaN values as "NaN", positive infinity as "Infinity", and negative
108 infinity as "-Infinity".
Mike Ra07fc532018-03-13 23:35:31 +0300109 - "precision": int
110 - Number of precision digits for formatting of real values.
111 - "precisionType": "significant"(default) or "decimal"
112 - Type of precision for formatting of real values.
Christopher Dunnf757c182015-02-09 18:24:56 -0600113
114 You can examine 'settings_` yourself
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600115 to see the defaults. You can also write and read them just like any
116 JSON Value.
Christopher Dunnf757c182015-02-09 18:24:56 -0600117 \sa setDefaults()
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600118 */
119 Json::Value settings_;
Christopher Dunn7eca3b42015-01-26 11:17:42 -0600120
121 StreamWriterBuilder();
Christopher Dunn98e981d2016-03-21 21:00:24 -0500122 ~StreamWriterBuilder() JSONCPP_OVERRIDE;
Christopher Dunn6065a1c2015-01-26 11:01:15 -0600123
Christopher Dunnc41609b2015-02-09 18:44:53 -0600124 /**
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600125 * \throw std::exception if something goes wrong (e.g. invalid settings)
126 */
Christopher Dunn98e981d2016-03-21 21:00:24 -0500127 StreamWriter* newStreamWriter() const JSONCPP_OVERRIDE;
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600128
Christopher Dunnf757c182015-02-09 18:24:56 -0600129 /** \return true if 'settings' are legal and consistent;
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600130 * otherwise, indicate bad settings via 'invalid'.
131 */
132 bool validate(Json::Value* invalid) const;
Christopher Dunnc312dd52015-03-04 14:56:37 -0600133 /** A simple way to update a specific setting.
134 */
Christopher Dawes75570d72016-03-07 08:29:59 +0000135 Value& operator[](JSONCPP_STRING key);
Christopher Dunnc312dd52015-03-04 14:56:37 -0600136
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600137 /** Called by ctor, but you can use this to reset settings_.
138 * \pre 'settings' != NULL (but Json::null is fine)
Christopher Dunn3cf91752015-02-09 18:16:24 -0600139 * \remark Defaults:
140 * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults
Christopher Dunna9e1ab32015-02-09 17:22:28 -0600141 */
142 static void setDefaults(Json::Value* settings);
Christopher Dunn6065a1c2015-01-26 11:01:15 -0600143};
Christopher Dunn5fbfe3c2015-01-22 14:31:32 -0600144
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000145/** \brief Abstract class for writers.
Christopher Dunned495ed2015-03-08 14:01:28 -0500146 * \deprecated Use StreamWriter. (And really, this is an implementation detail.)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000147 */
damiramef16a352017-08-02 22:44:42 -0700148class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000149public:
150 virtual ~Writer();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000151
Christopher Dawes75570d72016-03-07 08:29:59 +0000152 virtual JSONCPP_STRING write(const Value& root) = 0;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000153};
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000154
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000155/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
156 *without formatting (not human friendly).
157 *
158 * The JSON document is written in a single line. It is not intended for 'human'
159 *consumption,
luzpaz5b45aa52018-02-08 20:05:50 -0500160 * but may be useful to support feature such as RPC where bandwidth is limited.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000161 * \sa Reader, Value
Christopher Dunn20d09672015-02-10 21:29:35 -0600162 * \deprecated Use StreamWriterBuilder.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000163 */
Hugh Bellamy72870652017-09-16 10:01:09 +0100164#if defined(_MSC_VER)
Motti Lanzkron9bb984a2017-09-11 16:14:52 +0300165#pragma warning(push)
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400166#pragma warning(disable : 4996) // Deriving from deprecated class
Hugh Bellamy72870652017-09-16 10:01:09 +0100167#endif
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400168class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
169 : public Writer {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000170public:
171 FastWriter();
Christopher Dunn98e981d2016-03-21 21:00:24 -0500172 ~FastWriter() JSONCPP_OVERRIDE {}
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000173
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000174 void enableYAMLCompatibility();
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000175
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000176 /** \brief Drop the "null" string from the writer's output for nullValues.
177 * Strictly speaking, this is not valid JSON. But when the output is being
Josh Sorefe6a588a2017-12-03 11:54:29 -0500178 * fed to a browser's JavaScript, it makes for smaller output and the
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000179 * browser can handle the output just fine.
180 */
181 void dropNullPlaceholders();
Aaron Jacobsae3c7a72012-03-12 04:53:57 +0000182
Don Milham5bf16102014-09-02 17:09:07 -0600183 void omitEndingLineFeed();
184
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000185public: // overridden from Writer
Christopher Dunn98e981d2016-03-21 21:00:24 -0500186 JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000187
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000188private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000189 void writeValue(const Value& value);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000190
Christopher Dawes75570d72016-03-07 08:29:59 +0000191 JSONCPP_STRING document_;
Josh Sorefe6a588a2017-12-03 11:54:29 -0500192 bool yamlCompatibilityEnabled_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000193 bool dropNullPlaceholders_;
Don Milham5bf16102014-09-02 17:09:07 -0600194 bool omitEndingLineFeed_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000195};
Hugh Bellamy72870652017-09-16 10:01:09 +0100196#if defined(_MSC_VER)
Christopher Dunn132840a2017-09-11 13:39:38 -0500197#pragma warning(pop)
Hugh Bellamy72870652017-09-16 10:01:09 +0100198#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000199
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000200/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
201 *human friendly way.
202 *
203 * The rules for line break and indent are as follow:
204 * - Object value:
205 * - if empty then print {} without indent and line break
206 * - if not empty the print '{', line break & indent, print one value per
207 *line
208 * and then unindent and line break and print '}'.
209 * - Array value:
210 * - if empty then print [] without indent and line break
211 * - if the array contains no object value, empty array or some other value
212 *types,
213 * and all the values fit on one lines, then print the array on a single
214 *line.
215 * - otherwise, it the values do not fit on one line, or the array contains
216 * object or non empty array, then print one value per line.
217 *
218 * If the Value have comments then they are outputed according to their
219 *#CommentPlacement.
220 *
221 * \sa Reader, Value, Value::setComment()
Christopher Dunn38042b32015-01-26 11:23:31 -0600222 * \deprecated Use StreamWriterBuilder.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000223 */
Hugh Bellamy72870652017-09-16 10:01:09 +0100224#if defined(_MSC_VER)
Motti Lanzkron9bb984a2017-09-11 16:14:52 +0300225#pragma warning(push)
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400226#pragma warning(disable : 4996) // Deriving from deprecated class
Hugh Bellamy72870652017-09-16 10:01:09 +0100227#endif
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400228class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
229 StyledWriter : public Writer {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000230public:
231 StyledWriter();
Christopher Dunn98e981d2016-03-21 21:00:24 -0500232 ~StyledWriter() JSONCPP_OVERRIDE {}
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000233
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000234public: // overridden from Writer
235 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
236 * \param root Value to serialize.
237 * \return String containing the JSON document that represents the root value.
238 */
Christopher Dunn98e981d2016-03-21 21:00:24 -0500239 JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000240
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000241private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000242 void writeValue(const Value& value);
243 void writeArrayValue(const Value& value);
Josh Sorefe6a588a2017-12-03 11:54:29 -0500244 bool isMultilineArray(const Value& value);
Christopher Dawes75570d72016-03-07 08:29:59 +0000245 void pushValue(const JSONCPP_STRING& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000246 void writeIndent();
Christopher Dawes75570d72016-03-07 08:29:59 +0000247 void writeWithIndent(const JSONCPP_STRING& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000248 void indent();
249 void unindent();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000250 void writeCommentBeforeValue(const Value& root);
251 void writeCommentAfterValueOnSameLine(const Value& root);
252 bool hasCommentForValue(const Value& value);
Christopher Dawes75570d72016-03-07 08:29:59 +0000253 static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000254
Christopher Dawes75570d72016-03-07 08:29:59 +0000255 typedef std::vector<JSONCPP_STRING> ChildValues;
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000256
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000257 ChildValues childValues_;
Christopher Dawes75570d72016-03-07 08:29:59 +0000258 JSONCPP_STRING document_;
259 JSONCPP_STRING indentString_;
Christopher Dunnd4513fc2016-02-06 09:25:20 -0600260 unsigned int rightMargin_;
261 unsigned int indentSize_;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000262 bool addChildValues_;
263};
Hugh Bellamy72870652017-09-16 10:01:09 +0100264#if defined(_MSC_VER)
Christopher Dunn132840a2017-09-11 13:39:38 -0500265#pragma warning(pop)
Hugh Bellamy72870652017-09-16 10:01:09 +0100266#endif
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000267
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000268/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
269 human friendly way,
270 to a stream rather than to a string.
271 *
272 * The rules for line break and indent are as follow:
273 * - Object value:
274 * - if empty then print {} without indent and line break
275 * - if not empty the print '{', line break & indent, print one value per
276 line
277 * and then unindent and line break and print '}'.
278 * - Array value:
279 * - if empty then print [] without indent and line break
280 * - if the array contains no object value, empty array or some other value
281 types,
282 * and all the values fit on one lines, then print the array on a single
283 line.
284 * - otherwise, it the values do not fit on one line, or the array contains
285 * object or non empty array, then print one value per line.
286 *
287 * If the Value have comments then they are outputed according to their
288 #CommentPlacement.
289 *
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000290 * \sa Reader, Value, Value::setComment()
Christopher Dunn38042b32015-01-26 11:23:31 -0600291 * \deprecated Use StreamWriterBuilder.
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000292 */
Hugh Bellamy72870652017-09-16 10:01:09 +0100293#if defined(_MSC_VER)
Christopher Dunn132840a2017-09-11 13:39:38 -0500294#pragma warning(push)
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400295#pragma warning(disable : 4996) // Deriving from deprecated class
Hugh Bellamy72870652017-09-16 10:01:09 +0100296#endif
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400297class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
298 StyledStreamWriter {
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000299public:
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400300 /**
301 * \param indentation Each level will be indented by this amount extra.
302 */
Marian Klymovc8bb6002018-06-02 19:41:57 +0300303 StyledStreamWriter(const JSONCPP_STRING& indentation = "\t");
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000304 ~StyledStreamWriter() {}
Christopher Dunn605cd7e2007-06-13 15:55:50 +0000305
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000306public:
307 /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
308 * \param out Stream to write to. (Can be ostringstream, e.g.)
309 * \param root Value to serialize.
310 * \note There is no point in deriving from Writer, since write() should not
311 * return a value.
312 */
Christopher Dunn724ba292016-03-06 11:47:35 -0600313 void write(JSONCPP_OSTREAM& out, const Value& root);
Christopher Dunn605cd7e2007-06-13 15:55:50 +0000314
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000315private:
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000316 void writeValue(const Value& value);
317 void writeArrayValue(const Value& value);
Josh Sorefe6a588a2017-12-03 11:54:29 -0500318 bool isMultilineArray(const Value& value);
Christopher Dawes75570d72016-03-07 08:29:59 +0000319 void pushValue(const JSONCPP_STRING& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000320 void writeIndent();
Christopher Dawes75570d72016-03-07 08:29:59 +0000321 void writeWithIndent(const JSONCPP_STRING& value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000322 void indent();
323 void unindent();
Aaron Jacobs11086dd2014-09-15 10:15:29 +1000324 void writeCommentBeforeValue(const Value& root);
325 void writeCommentAfterValueOnSameLine(const Value& root);
326 bool hasCommentForValue(const Value& value);
Christopher Dawes75570d72016-03-07 08:29:59 +0000327 static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
Christopher Dunn605cd7e2007-06-13 15:55:50 +0000328
Christopher Dawes75570d72016-03-07 08:29:59 +0000329 typedef std::vector<JSONCPP_STRING> ChildValues;
Christopher Dunn605cd7e2007-06-13 15:55:50 +0000330
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000331 ChildValues childValues_;
Christopher Dunn724ba292016-03-06 11:47:35 -0600332 JSONCPP_OSTREAM* document_;
Christopher Dawes75570d72016-03-07 08:29:59 +0000333 JSONCPP_STRING indentString_;
Christopher Dunnfef4b752016-02-06 09:59:18 -0600334 unsigned int rightMargin_;
Christopher Dawes75570d72016-03-07 08:29:59 +0000335 JSONCPP_STRING indentation_;
Christopher Dunnd3830562015-01-23 13:09:43 -0600336 bool addChildValues_ : 1;
337 bool indented_ : 1;
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000338};
Hugh Bellamy72870652017-09-16 10:01:09 +0100339#if defined(_MSC_VER)
Christopher Dunn132840a2017-09-11 13:39:38 -0500340#pragma warning(pop)
Hugh Bellamy72870652017-09-16 10:01:09 +0100341#endif
Christopher Dunn605cd7e2007-06-13 15:55:50 +0000342
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000343#if defined(JSON_HAS_INT64)
Christopher Dawes75570d72016-03-07 08:29:59 +0000344JSONCPP_STRING JSON_API valueToString(Int value);
345JSONCPP_STRING JSON_API valueToString(UInt value);
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000346#endif // if defined(JSON_HAS_INT64)
Christopher Dawes75570d72016-03-07 08:29:59 +0000347JSONCPP_STRING JSON_API valueToString(LargestInt value);
348JSONCPP_STRING JSON_API valueToString(LargestUInt value);
Billy Donahueb5e1fe82018-05-20 16:55:27 -0400349JSONCPP_STRING JSON_API
350valueToString(double value,
351 unsigned int precision = Value::defaultRealPrecision,
352 PrecisionType precisionType = PrecisionType::significantDigits);
Christopher Dawes75570d72016-03-07 08:29:59 +0000353JSONCPP_STRING JSON_API valueToString(bool value);
354JSONCPP_STRING JSON_API valueToQuotedString(const char* value);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000355
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000356/// \brief Output using the StyledStreamWriter.
357/// \see Json::operator>>()
Christopher Dunn724ba292016-03-06 11:47:35 -0600358JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000359
360} // namespace Json
361
Sergiy80d6e666f2016-12-03 22:29:14 +0200362#pragma pack(pop)
363
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000364#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
Aaron Jacobs9fa4e842014-07-01 08:48:54 +1000365#pragma warning(pop)
Baptiste Lepilleureafd7022013-05-08 20:21:11 +0000366#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
367
Christopher Dunn6d135cb2007-06-13 15:51:04 +0000368#endif // JSON_WRITER_H_INCLUDED