IOSS  2.0
Json::StyledStreamWriter Class Reference

Writes a Value in JSON format in a human friendly way, to a stream rather than to a string. More...

#include <json.h>

Public Member Functions

 StyledStreamWriter (std::string indentation="\)
 
 ~StyledStreamWriter ()
 
void write (std::ostream &out, const Value &root)
 Serialize a Value in JSON format. More...
 

Private Types

typedef std::vector< std::string > ChildValues
 

Private Member Functions

void writeValue (const Value &value)
 
void writeArrayValue (const Value &value)
 
bool isMultineArray (const Value &value)
 
void pushValue (const std::string &value)
 
void writeIndent ()
 
void writeWithIndent (const std::string &value)
 
void indent ()
 
void unindent ()
 
void writeCommentBeforeValue (const Value &root)
 
void writeCommentAfterValueOnSameLine (const Value &root)
 
bool hasCommentForValue (const Value &value)
 

Static Private Member Functions

static std::string normalizeEOL (const std::string &text)
 

Private Attributes

ChildValues childValues_
 
std::ostream * document_
 
std::string indentString_
 
int rightMargin_
 
std::string indentation_
 
bool addChildValues_: 1
 
bool indented_: 1
 

Detailed Description

Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.

The rules for line break and indent are as follow:

  • Object value:
    • if empty then print {} without indent and line break
    • if not empty the print '{', line break & indent, print one value per line and then unindent and line break and print '}'.
  • Array value:
    • if empty then print [] without indent and line break
    • if the array contains no object value, empty array or some other value types, and all the values fit on one lines, then print the array on a single line.
    • otherwise, it the values do not fit on one line, or the array contains object or non empty array, then print one value per line.

If the Value have comments then they are outputed according to their CommentPlacement.

Parameters
indentationEach level will be indented by this amount extra.
See also
Reader, Value, Value::setComment()
Deprecated:
Use StreamWriterBuilder.

Member Typedef Documentation

◆ ChildValues

typedef std::vector<std::string> Json::StyledStreamWriter::ChildValues
private

Constructor & Destructor Documentation

◆ StyledStreamWriter()

Json::StyledStreamWriter::StyledStreamWriter ( )

◆ ~StyledStreamWriter()

Json::StyledStreamWriter::~StyledStreamWriter ( )
inline

Member Function Documentation

◆ hasCommentForValue()

bool Json::StyledStreamWriter::hasCommentForValue ( const Value value)
private

◆ indent()

void Json::StyledStreamWriter::indent ( )
private

◆ isMultineArray()

bool Json::StyledStreamWriter::isMultineArray ( const Value value)
private

◆ normalizeEOL()

static std::string Json::StyledStreamWriter::normalizeEOL ( const std::string &  text)
staticprivate

◆ pushValue()

void Json::StyledStreamWriter::pushValue ( const std::string &  value)
private

◆ unindent()

void Json::StyledStreamWriter::unindent ( )
private

◆ write()

void Json::StyledStreamWriter::write ( std::ostream &  out,
const Value root 
)

Serialize a Value in JSON format.

Parameters
outStream to write to. (Can be ostringstream, e.g.)
rootValue to serialize.
Note
There is no point in deriving from Writer, since write() should not return a value.

◆ writeArrayValue()

void Json::StyledStreamWriter::writeArrayValue ( const Value value)
private

◆ writeCommentAfterValueOnSameLine()

void Json::StyledStreamWriter::writeCommentAfterValueOnSameLine ( const Value root)
private

◆ writeCommentBeforeValue()

void Json::StyledStreamWriter::writeCommentBeforeValue ( const Value root)
private

◆ writeIndent()

void Json::StyledStreamWriter::writeIndent ( )
private

◆ writeValue()

void Json::StyledStreamWriter::writeValue ( const Value value)
private

◆ writeWithIndent()

void Json::StyledStreamWriter::writeWithIndent ( const std::string &  value)
private

Member Data Documentation

◆ addChildValues_

bool Json::StyledStreamWriter::addChildValues_
private

◆ childValues_

ChildValues Json::StyledStreamWriter::childValues_
private

◆ document_

std::ostream* Json::StyledStreamWriter::document_
private

◆ indentation_

std::string Json::StyledStreamWriter::indentation_
private

◆ indented_

bool Json::StyledStreamWriter::indented_
private

◆ indentString_

std::string Json::StyledStreamWriter::indentString_
private

◆ rightMargin_

int Json::StyledStreamWriter::rightMargin_
private

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