LoveBrains  1.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Json::StreamWriterBuilder Class Reference

Build a StreamWriter implementation. More...

#include <json.h>

Inheritance diagram for Json::StreamWriterBuilder:
Json::StreamWriter::Factory Json::StreamWriter::Factory

Public Member Functions

virtual StreamWriternewStreamWriter () const
 
bool validate (Json::Value *invalid) const
 
Valueoperator[] (std::string key)
 
virtual StreamWriternewStreamWriter () const
 
bool validate (Json::Value *invalid) const
 
Valueoperator[] (std::string key)
 

Static Public Member Functions

static void setDefaults (Json::Value *settings)
 
static void setDefaults (Json::Value *settings)
 

Public Attributes

Json::Value settings_
 

Detailed Description

Build a StreamWriter implementation.

Usage:

using namespace Json;
Value value = ...;
builder["commentStyle"] = "None";
builder["indentation"] = " "; // or whatever you like
std::unique_ptr<Json::StreamWriter> writer(
builder.newStreamWriter());
writer->write(value, &std::cout);
std::cout << std::endl; // add lf and flush

Member Function Documentation

StreamWriter * Json::StreamWriterBuilder::newStreamWriter ( ) const
virtual
Exceptions
std::exceptionif something goes wrong (e.g. invalid settings)

Implements Json::StreamWriter::Factory.

virtual StreamWriter* Json::StreamWriterBuilder::newStreamWriter ( ) const
virtual
Exceptions
std::exceptionif something goes wrong (e.g. invalid settings)

Implements Json::StreamWriter::Factory.

Value& Json::StreamWriterBuilder::operator[] ( std::string  key)

A simple way to update a specific setting.

Value & Json::StreamWriterBuilder::operator[] ( std::string  key)

A simple way to update a specific setting.

void Json::StreamWriterBuilder::setDefaults ( Json::Value settings)
static

Called by ctor, but you can use this to reset settings_.

Precondition
'settings' != NULL (but Json::null is fine)
Remarks
Defaults:

[StreamWriterBuilderDefaults]

[StreamWriterBuilderDefaults]

static void Json::StreamWriterBuilder::setDefaults ( Json::Value settings)
static

Called by ctor, but you can use this to reset settings_.

Precondition
'settings' != NULL (but Json::null is fine)
Remarks
Defaults:
bool Json::StreamWriterBuilder::validate ( Json::Value invalid) const
Returns
true if 'settings' are legal and consistent; otherwise, indicate bad settings via 'invalid'.
bool Json::StreamWriterBuilder::validate ( Json::Value invalid) const
Returns
true if 'settings' are legal and consistent; otherwise, indicate bad settings via 'invalid'.

Member Data Documentation

Json::Value Json::StreamWriterBuilder::settings_

Configuration of this builder. Available settings (case-sensitive):

  • "commentStyle": "None" or "All"
  • "indentation": "<anything>"
  • "enableYAMLCompatibility": false or true
    • slightly change the whitespace around colons
  • "dropNullPlaceholders": false or true
    • Drop the "null" string from the writer's output for nullValues. Strictly speaking, this is not valid JSON. But when the output is being fed to a browser's Javascript, it makes for smaller output and the browser can handle the output just fine.

You can examine 'settings_` yourself to see the defaults. You can also write and read them just like any JSON Value.

See also
setDefaults()

The documentation for this class was generated from the following files: