@@ -58,58 +58,43 @@ class JSON_API StreamWriter {
58
58
// / \throw std::exception possibly, depending on configuration
59
59
virtual int write (Value const & root) = 0;
60
60
61
- // / Because this Builder is non-virtual, we can safely add
62
- // / methods without a major version bump.
63
- // / \see http://stackoverflow.com/questions/14875052/pure-virtual-functions-and-binary-compatibility
64
- class JSON_API Builder {
65
- StreamWriterBuilder* own_;
66
- Builder (Builder const &); // noncopyable
67
- void operator =(Builder const &); // noncopyable
68
- public:
69
- Builder ();
70
- ~Builder (); // delete underlying StreamWriterBuilder
71
-
72
- Builder& withCommentStyle (CommentStyle cs); // / default: All
73
- /* * \brief Write in human-friendly style.
74
-
75
- If "", then skip all indentation, newlines, and comments,
76
- which implies CommentStyle::None.
77
- Default: "\t"
78
- */
79
- Builder& withIndentation (std::string indentation);
80
-
81
- // / Do not take ownership of sout, but maintain a reference.
82
- StreamWriter* newStreamWriter (std::ostream* sout) const ;
83
- };
84
-
85
61
/* * \brief A simple abstract factory.
86
62
*/
87
63
class JSON_API Factory {
88
64
public:
89
65
virtual ~Factory ();
90
- /* Because this is only a trivial API (the Factory pattern), we will
91
- * never need to add virtual methods, so we do not need a concrete wrapper.
92
- * This is better than the Builder above, but not everyone will agree.
93
- */
94
-
95
66
// / Do not take ownership of sout, but maintain a reference.
96
67
virtual StreamWriter* newStreamWriter (std::ostream* sout) const = 0;
97
- };
68
+ }; // Factory
69
+ }; // StreamWriter
70
+
71
+ // / \brief Write into stringstream, then return string, for convenience.
72
+ std::string writeString (Value const & root, StreamWriter::Factory const & factory);
98
73
99
- /* * \brief Extensions of this are used to create a StreamWriter::Factory.
74
+
75
+ /* * \brief Build a StreamWriter implementation.
76
+ */
77
+ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
78
+ // typedef StreamWriter::CommentStyle CommentStyle;
79
+ public:
80
+ // Note: We cannot add data-members to this class without a major version bump.
81
+ // So these might as well be completely exposed.
82
+
83
+ /* * \brief How to write comments.
84
+ * Default: All
100
85
*/
101
- class JSON_API FactoryFactory {
102
- virtual ~FactoryFactory ();
103
- virtual Factory* newFactory () const = 0;
104
- /* This class will seem strange to some developers, but it actually
105
- * simplifies our library maintenance.
106
- */
107
- };
86
+ StreamWriter::CommentStyle cs_ = StreamWriter::CommentStyle::All;
87
+ /* * \brief Write in human-friendly style.
108
88
109
- };
89
+ If "", then skip all indentation and newlines.
90
+ In that case, you probably want CommentStyle::None also.
91
+ Default: "\t"
92
+ */
93
+ std::string indentation_ = " \t " ;
110
94
111
- // / \brief Write into stringstream, then return string, for convenience.
112
- std::string writeString (Value const & root, StreamWriter::Builder const & builder);
95
+ // / Do not take ownership of sout, but maintain a reference.
96
+ StreamWriter* newStreamWriter (std::ostream* sout) const ;
97
+ };
113
98
114
99
/* * \brief Build a StreamWriter implementation.
115
100
* Comments are not written, and most whitespace is omitted.
@@ -124,7 +109,7 @@ std::string writeString(Value const& root, StreamWriter::Builder const& builder)
124
109
* delete w;
125
110
* \endcode
126
111
*/
127
- class JSON_API OldCompressingStreamWriterBuilder
112
+ class JSON_API OldCompressingStreamWriterBuilder : public StreamWriter::Factory
128
113
{
129
114
public:
130
115
// Note: We cannot add data-members to this class without a major version bump.
0 commit comments