Skip to content

Commit 9da9f84

Browse files
committed
improve docs
including `writeString()`
1 parent 54b8e69 commit 9da9f84

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

doc/jsoncpp.dox

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,19 @@ Json::StreamWriter::Builder builder;
8585
builder.withIndentation(" "); // or whatever you like
8686

8787
// Then build a StreamWriter.
88-
// (Of course, you can write to std::ostringstream if you prefer.)
8988
std::shared_ptr<Json::StreamWriter> writer(
90-
builder.newStreamWriter( &std::cout );
89+
builder.newStreamWriter( &std::cout ) );
9190

9291
// Make a new JSON document for the configuration. Preserve original comments.
9392
writer->write( root );
9493

9594
// If you like the defaults, you can insert directly into a stream.
9695
std::cout << root;
9796

97+
// Of course, you can write to `std::ostringstream` if you prefer. Or
98+
// use `writeString()` for convenience.
99+
std::string document = Json::writeString( root, builder );
100+
98101
// You can also read from a stream. This will put the contents of any JSON
99102
// stream at a particular sub-value, if you'd like.
100103
std::cin >> root["subtree"];

include/json/writer.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StreamWriterBuilder;
2727
/**
2828
2929
Usage:
30-
30+
\code
3131
using namespace Json;
3232
Value value;
3333
StreamWriter::Builder builder;
@@ -36,16 +36,18 @@ class StreamWriterBuilder;
3636
builder.newStreamWriter(&std::cout));
3737
writer->write(value);
3838
std::cout.flush();
39+
\endcode
3940
*/
4041
class JSON_API StreamWriter {
4142
protected:
4243
std::ostream& sout_; // not owned; will not delete
4344
public:
44-
/// `All`: Keep all comments.
45-
/// `None`: Drop all comments.
46-
/// Use `Most` to recover the odd behavior of previous versions.
47-
/// Only `All` is currently implemented.
48-
enum class CommentStyle {None, Most, All};
45+
/// Decide whether to write comments.
46+
enum class CommentStyle {
47+
None, ///< Drop all comments.
48+
Most, ///< Recover odd behavior of previous versions (not implemented yet).
49+
All ///< Keep all comments.
50+
};
4951

5052
/// Keep a reference, but do not take ownership of `sout`.
5153
StreamWriter(std::ostream* sout);

0 commit comments

Comments
 (0)