fson  1.0.2
A comment-preserving C++ library for FSON — a human-friendly superset of JSON / JSON5
fedem::fson::FsonWriter Class Referencefinal

#include <FsonWriter.hh>

Public Types

enum class  Dialect { Fson , Json , Json5 }
 
enum class  DisabledMemberPolicy { ConvertToComment , Keep , Drop }
 

Public Member Functions

 FsonWriter ()
 
void setDialect (Dialect dialect) noexcept
 
Dialect getDialect () const noexcept
 
void setDisabledMemberPolicy (DisabledMemberPolicy policy) noexcept
 
DisabledMemberPolicy getDisabledMemberPolicy () const noexcept
 
void setKeepDisabledMembers (bool keep) noexcept
 
bool getKeepDisabledMembers () const noexcept
 
void setPreferBareKeys (bool prefer) noexcept
 
bool getPreferBareKeys () const noexcept
 
void write (Document const &document, std::ostream &stream)
 
std::string write (Document const &document)
 
bool writeFile (Document const &document, std::string const &filename)
 

Static Public Member Functions

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

Private Member Functions

bool isOrdinaryMember (Member const &member) const noexcept
 
bool isConvertedToComment (Member const &member) const noexcept
 
bool isEmittedInclude (Include const &include) const noexcept
 
bool canWriteMultiline (String const &string) const noexcept
 
void writeMultilineString (String const &string, std::ostream &stream)
 
void writeValue (Value const &value, std::ostream &stream)
 
void writeObject (Object const &object, std::ostream &stream)
 
void writeArray (Array const &array, std::ostream &stream)
 
void writeKey (Key const &key, std::ostream &stream)
 
void writeNumber (Number const &number, std::ostream &stream)
 
void writeConvertedMember (Member const &member, std::ostream &stream)
 
void writeComment (Comment const &comment, std::ostream &stream)
 
void writeCommentLines (CommentList const &comments, std::ostream &stream)
 
void writeTrailingComment (Comment const *comment, std::ostream &stream)
 

Static Private Member Functions

static std::string encodeMultilineLine (std::string_view line)
 

Private Attributes

parser::Indentation indentor
 
Dialect dialect
 
DisabledMemberPolicy disabledPolicy
 
bool preferBare
 

Member Enumeration Documentation

◆ Dialect

Enumerator
Fson 
Json 
Json5 

◆ DisabledMemberPolicy

Enumerator
ConvertToComment 
Keep 
Drop 

Constructor & Destructor Documentation

◆ FsonWriter()

fedem::fson::FsonWriter::FsonWriter ( )

Member Function Documentation

◆ setDialect()

void fedem::fson::FsonWriter::setDialect ( FsonWriter::Dialect  dialect)
noexcept

Referenced by main().

+ Here is the caller graph for this function:

◆ getDialect()

FsonWriter::Dialect fedem::fson::FsonWriter::getDialect ( ) const
noexcept

References dialect.

◆ setDisabledMemberPolicy()

void fedem::fson::FsonWriter::setDisabledMemberPolicy ( DisabledMemberPolicy  policy)
noexcept

Referenced by main().

+ Here is the caller graph for this function:

◆ getDisabledMemberPolicy()

FsonWriter::DisabledMemberPolicy fedem::fson::FsonWriter::getDisabledMemberPolicy ( ) const
noexcept

References disabledPolicy.

◆ setKeepDisabledMembers()

void fedem::fson::FsonWriter::setKeepDisabledMembers ( bool  keep)
noexcept

◆ getKeepDisabledMembers()

bool fedem::fson::FsonWriter::getKeepDisabledMembers ( ) const
noexcept

References disabledPolicy, and Keep.

◆ setPreferBareKeys()

void fedem::fson::FsonWriter::setPreferBareKeys ( bool  prefer)
noexcept

Referenced by main().

+ Here is the caller graph for this function:

◆ getPreferBareKeys()

bool fedem::fson::FsonWriter::getPreferBareKeys ( ) const
noexcept

References preferBare.

◆ write() [1/2]

void fedem::fson::FsonWriter::write ( Document const &  document,
std::ostream &  stream 
)

References fedem::fson::Document::getFooterComments(), fedem::fson::Document::getHeaderComments(), fedem::fson::Document::getRootValue(), indentor, writeCommentLines(), and writeValue().

Referenced by main(), write(), and writeFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write() [2/2]

string fedem::fson::FsonWriter::write ( Document const &  document)

References write().

+ Here is the call graph for this function:

◆ writeFile()

bool fedem::fson::FsonWriter::writeFile ( Document const &  document,
std::string const &  filename 
)

References write().

Referenced by main(), and fedem::fson::Fson::save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeString()

string fedem::fson::FsonWriter::encodeString ( std::string const &  text)
static

Referenced by writeKey(), writeObject(), and writeValue().

+ Here is the caller graph for this function:

◆ isOrdinaryMember()

bool fedem::fson::FsonWriter::isOrdinaryMember ( Member const &  member) const
privatenoexcept

Referenced by writeObject().

+ Here is the caller graph for this function:

◆ isConvertedToComment()

bool fedem::fson::FsonWriter::isConvertedToComment ( Member const &  member) const
privatenoexcept

Referenced by writeObject().

+ Here is the caller graph for this function:

◆ isEmittedInclude()

bool fedem::fson::FsonWriter::isEmittedInclude ( Include const &  include) const
privatenoexcept

Referenced by writeObject().

+ Here is the caller graph for this function:

◆ canWriteMultiline()

bool fedem::fson::FsonWriter::canWriteMultiline ( String const &  string) const
privatenoexcept

References fedem::fson::String::Multiline.

Referenced by writeArray(), writeObject(), and writeValue().

+ Here is the caller graph for this function:

◆ writeMultilineString()

void fedem::fson::FsonWriter::writeMultilineString ( String const &  string,
std::ostream &  stream 
)
private

References encodeMultilineLine(), and indentor.

Referenced by writeValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeMultilineLine()

string fedem::fson::FsonWriter::encodeMultilineLine ( std::string_view  line)
staticprivate

Referenced by writeMultilineString().

+ Here is the caller graph for this function:

◆ writeValue()

void fedem::fson::FsonWriter::writeValue ( Value const &  value,
std::ostream &  stream 
)
private

References fedem::fson::Value::Array, fedem::fson::Value::asArray(), fedem::fson::Value::asBoolean(), fedem::fson::Value::asNumber(), fedem::fson::Value::asObject(), fedem::fson::Value::asString(), fedem::fson::Value::Boolean, canWriteMultiline(), encodeString(), fedem::fson::Value::getType(), fedem::fson::Boolean::getValue(), fedem::fson::Value::Null, fedem::fson::Value::Number, fedem::fson::Value::Object, fedem::fson::Value::String, writeArray(), writeMultilineString(), writeNumber(), and writeObject().

Referenced by write(), writeArray(), writeConvertedMember(), and writeObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeObject()

◆ writeArray()

void fedem::fson::FsonWriter::writeArray ( Array const &  array,
std::ostream &  stream 
)
private

References fedem::fson::Value::asString(), canWriteMultiline(), dialect, fedem::fson::Array::getDanglingComments(), fedem::fson::Array::getElement(), fedem::fson::Element::getLeadingComments(), fedem::fson::Element::getTrailingComment(), fedem::fson::Element::getValue(), indentor, index, Json, fedem::fson::Array::size(), writeCommentLines(), writeTrailingComment(), and writeValue().

Referenced by writeValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeKey()

void fedem::fson::FsonWriter::writeKey ( Key const &  key,
std::ostream &  stream 
)
private

References fedem::fson::Key::Bare, dialect, encodeString(), fedem::fson::Key::isValidName(), Json, key, and preferBare.

Referenced by writeConvertedMember(), and writeObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeNumber()

void fedem::fson::FsonWriter::writeNumber ( Number const &  number,
std::ostream &  stream 
)
private

References fedem::fson::Number::asDouble(), fedem::fson::Number::Decimal, dialect, fedem::fson::Number::getKind(), fedem::fson::Number::getLexeme(), fedem::fson::Number::Hex, fedem::fson::Number::Infinity, Json, fedem::fson::Number::NaN, and fedem::fson::Number::NegativeInfinity.

Referenced by writeValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeConvertedMember()

void fedem::fson::FsonWriter::writeConvertedMember ( Member const &  member,
std::ostream &  stream 
)
private

References fedem::fson::Member::getKey(), fedem::fson::Member::getValue(), indentor, index, writeKey(), and writeValue().

Referenced by writeObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeComment()

void fedem::fson::FsonWriter::writeComment ( Comment const &  comment,
std::ostream &  stream 
)
private

References fedem::fson::Comment::getKind(), fedem::fson::Comment::getText(), and fedem::fson::Comment::SingleLine.

Referenced by writeCommentLines(), and writeTrailingComment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeCommentLines()

void fedem::fson::FsonWriter::writeCommentLines ( CommentList const &  comments,
std::ostream &  stream 
)
private

References dialect, indentor, Json, Json5, fedem::fson::Comment::MultiLine, and writeComment().

Referenced by write(), writeArray(), and writeObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeTrailingComment()

void fedem::fson::FsonWriter::writeTrailingComment ( Comment const *  comment,
std::ostream &  stream 
)
private

References dialect, Fson, fedem::fson::Comment::getKind(), fedem::fson::Comment::getText(), indentor, Json, fedem::fson::Comment::SingleLine, and writeComment().

Referenced by writeArray(), and writeObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ indentor

parser::Indentation fedem::fson::FsonWriter::indentor
private

◆ dialect

Dialect fedem::fson::FsonWriter::dialect
private

◆ disabledPolicy

DisabledMemberPolicy fedem::fson::FsonWriter::disabledPolicy
private

◆ preferBare

bool fedem::fson::FsonWriter::preferBare
private

Referenced by getPreferBareKeys(), and writeKey().


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