Skip to content

Commit 3cf9175

Browse files
committed
remark defaults via doxygen snippet
1 parent a9e1ab3 commit 3cf9175

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

doc/jsoncpp.dox

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ std::string errs;
103103
bool ok = Json::parseFromStream(rbuilder, std::cin, &root, &errs);
104104
\endcode
105105

106+
Yes, compile-time configuration-checking would be helpful,
107+
but `Json::Value` lets you
108+
write and read the builder configuration, which is better! In other words,
109+
you can configure your JSON parser using JSON.
110+
111+
CharReaders and StreamWriters are not thread-safe, but they are re-usable.
112+
\code
113+
Json::CharReaderBuilder rbuilder;
114+
cfg >> rbuilder.settings_;
115+
std::unique_ptr<Json::CharReader> const reader(rbuilder.newCharReader());
116+
reader->parse(start, stop, &value1, &errs);
117+
// ...
118+
reader->parse(start, stop, &value2, &errs);
119+
// etc.
120+
\endcode
121+
106122
\section _pbuild Build instructions
107123
The build instructions are located in the file
108124
<a HREF="https://github.com/open-source-parsers/jsoncpp/blob/master/README.md">README.md</a> in the top-directory of the project.
@@ -137,5 +153,7 @@ and recognized in your jurisdiction.
137153

138154
\author Baptiste Lepilleur <[email protected]> (originator)
139155
\version \include version
156+
We make strong guarantees about binary-compatibility, consistent with
157+
<a href="http://apr.apache.org/versioning.html">the Apache versioning scheme</a>.
140158
\sa version.h
141159
*/

include/json/reader.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,14 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
296296
// Note: We use a Json::Value so that we can add data-members to this class
297297
// without a major version bump.
298298
/** Configuration of this builder.
299+
These are case-sensitive.
299300
Available settings (case-sensitive):
300301
- "collectComments": false or true (default=true)
301302
- TODO: other features ...
302-
But don't trust these docs. You can examine 'settings_` yourself
303+
You can examine 'settings_` yourself
303304
to see the defaults. You can also write and read them just like any
304305
JSON Value.
306+
\sa setDefaults(Json::Value*)
305307
*/
306308
Json::Value settings_;
307309

@@ -316,8 +318,16 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
316318
bool validate(Json::Value* invalid) const;
317319
/** Called by ctor, but you can use this to reset settings_.
318320
* \pre 'settings' != NULL (but Json::null is fine)
321+
* \remark Defaults:
322+
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
319323
*/
320324
static void setDefaults(Json::Value* settings);
325+
/** Same as old Features::strictMode().
326+
* \pre 'settings' != NULL (but Json::null is fine)
327+
* \remark Defaults:
328+
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
329+
*/
330+
static void strictMode(Json::Value* settings);
321331
};
322332

323333
/** Consume entire stream and use its begin/end.

include/json/writer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
121121
bool validate(Json::Value* invalid) const;
122122
/** Called by ctor, but you can use this to reset settings_.
123123
* \pre 'settings' != NULL (but Json::null is fine)
124+
* \remark Defaults:
125+
* \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults
124126
*/
125127
static void setDefaults(Json::Value* settings);
126128
};

src/lib_json/json_reader.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,25 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const
952952
return valid;
953953
}
954954
// static
955+
void CharReaderBuilder::strictMode(Json::Value* settings)
956+
{
957+
//! [CharReaderBuilderStrictMode]
958+
(*settings)["allowComments"] = false;
959+
(*settings)["strictRoot"] = true;
960+
(*settings)["allowDroppedNullPlaceholders"] = false;
961+
(*settings)["allowNumericKeys"] = false;
962+
//! [CharReaderBuilderStrictMode]
963+
}
964+
// static
955965
void CharReaderBuilder::setDefaults(Json::Value* settings)
956966
{
967+
//! [CharReaderBuilderDefaults]
957968
(*settings)["collectComments"] = true;
969+
(*settings)["allowComments"] = true;
970+
(*settings)["strictRoot"] = false;
971+
(*settings)["allowDroppedNullPlaceholders"] = false;
972+
(*settings)["allowNumericKeys"] = false;
973+
//! [CharReaderBuilderDefaults]
958974
}
959975

960976
//////////////////////////////////

src/lib_json/json_writer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,10 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const
10081008
// static
10091009
void StreamWriterBuilder::setDefaults(Json::Value* settings)
10101010
{
1011+
//! [StreamWriterBuilderDefaults]
10111012
(*settings)["commentStyle"] = "All";
10121013
(*settings)["indentation"] = "\t";
1014+
//! [StreamWriterBuilderDefaults]
10131015
}
10141016

10151017
/*

0 commit comments

Comments
 (0)