@@ -64,7 +64,10 @@ class JSON_API StreamWriter {
6464 class JSON_API Factory {
6565 public:
6666 virtual ~Factory ();
67- // / Do not take ownership of sout, but maintain a reference.
67+ /* * \brief Allocate a CharReader via operator new().
68+ * Do not take ownership of sout, but maintain a reference.
69+ * \throw std::exception if something goes wrong (e.g. invalid settings)
70+ */
6871 virtual StreamWriter* newStreamWriter (std::ostream* sout) const = 0;
6972 }; // Factory
7073}; // StreamWriter
@@ -77,41 +80,49 @@ std::string writeString(StreamWriter::Factory const& factory, Value const& root)
7780
7881/* * \brief Build a StreamWriter implementation.
7982
80- \deprecated This is experimental and will be altered before the next release.
81-
8283Usage:
8384\code
8485 using namespace Json;
8586 Value value = ...;
8687 StreamWriterBuilder builder;
87- builder.cs_ = StreamWriter::CommentStyle::None;
88- builder.indentation_ = " "; // or whatever you like
88+ builder.settings_["commentStyle"] = "None";
89+ builder.settings_["indentation"] = " "; // or whatever you like
90+ std::unique_ptr<Json::StreamWriter> writer(
91+ builder.newStreamWriter(&std::cout));
8992 writer->write(value);
9093 std::cout << std::endl; // add lf and flush
9194\endcode
9295*/
9396class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
9497public:
95- // Note: We cannot add data-members to this class without a major version bump.
96- // So these might as well be completely exposed.
97-
98- /* * \brief How to write comments.
99- * Default: All
100- */
101- StreamWriter::CommentStyle::Enum cs_;
102- /* * \brief Write in human-friendly style.
103-
104- If "", then skip all indentation and newlines.
105- In that case, you probably want CommentStyle::None also.
106- Default: "\t"
107- */
108- std::string indentation_;
98+ // Note: We use a Json::Value so that we can add data-members to this class
99+ // without a major version bump.
100+ /* * Configuration of this builder.
101+ Available settings (case-sensitive):
102+ - "commentStyle": "None", "Some", or "All" (default="All")
103+ - "indentation": (default="\t")
104+ But don't trust these docs. You can examine 'settings_` yourself
105+ to see the defaults. You can also write and read them just like any
106+ JSON Value.
107+ */
108+ Json::Value settings_;
109109
110110 StreamWriterBuilder ();
111111 virtual ~StreamWriterBuilder ();
112112
113- // / Do not take ownership of sout, but maintain a reference.
113+ /* * Do not take ownership of sout, but maintain a reference.
114+ * \throw std::exception if something goes wrong (e.g. invalid settings)
115+ */
114116 virtual StreamWriter* newStreamWriter (std::ostream* sout) const ;
117+
118+ /* * \return true if 'settings' are illegal and consistent;
119+ * otherwise, indicate bad settings via 'invalid'.
120+ */
121+ bool validate (Json::Value* invalid) const ;
122+ /* * Called by ctor, but you can use this to reset settings_.
123+ * \pre 'settings' != NULL (but Json::null is fine)
124+ */
125+ static void setDefaults (Json::Value* settings);
115126};
116127
117128/* * \brief Build a StreamWriter implementation.
@@ -126,6 +137,8 @@ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
126137 * w->write(value);
127138 * delete w;
128139 * \endcode
140+ *
141+ * \deprecated Use StreamWriterBuilder
129142 */
130143class JSON_API OldCompressingStreamWriterBuilder : public StreamWriter::Factory
131144{
0 commit comments