Support Forum       G3D Web Page     
Classes | Public Member Functions | List of all members
G3D::TextOutput Class Reference

Convenient formatting of ASCII text written to a file. More...

Classes

class  Settings
 

Public Member Functions

 TextOutput (const String &filename, const Settings &options=Settings())
 
 TextOutput (const Settings &options=Settings())
 Constructs a text output that can later be commited to a string instead of a file. More...
 
int column () const
 
void commit (bool flush=true)
 Commit to the filename specified on the constructor. More...
 
void commitString (String &string)
 Commits to this string. More...
 
String commitString ()
 Produces a new string that contains the output. More...
 
bool deleteSpace ()
 If the most recently written character was a space, remove it and return true. More...
 
int line () const
 Returns one plus the number of newlines written since the output was created. More...
 
void popIndent ()
 
void printf (const char *fmt,...)
 Normal printf conventions. More...
 
void printf (const String fmt,...)
 
void pushIndent ()
 Increase indent level by 1. More...
 
void vprintf (const char *fmt, va_list argPtr)
 
void writeBoolean (bool b)
 
void writeCNumber (double n, bool trailingSpace=true, bool minimal=false)
 Guaranteed to parse as a C syntax double. More...
 
void writeCNumber (float n, bool trailingSpace=true, bool minimal=false)
 Guaranteed to parse as a C syntax float. More...
 
void writeCNumber (int n, bool trailingSpace=true, bool minimal=false)
 Guaranteed to parse as a C syntax int. More...
 
void writeNewline ()
 
void writeNewlines (int numLines)
 
void writeNumber (double n)
 
void writeNumber (int n)
 
void writeString (const String &string)
 Writes a quoted string. More...
 
void writeSymbol (const String &string)
 The symbol is written without quotes. More...
 
void writeSymbol (char s)
 
void writeSymbols (const String &a, const String &b="", const String &c="", const String &d="", const String &e="", const String &f="")
 Convenient idiom for writing multiple symbols in a row, e.g. More...
 

Detailed Description

Convenient formatting of ASCII text written to a file.

The core writeString, writeNumber, and writeSymbol methods map to TextInput's methods. Number and Symbol each print an additional space that is used to separate adjacent tokens.

TextOutput::printf allows arbitrary text to be conveniently dumped en-masse. Use [de]serialize(bool, TextOutput) and other overloads to read/write primitive types in a standardized manner and

When a word-wrap line break occurs, all whitespace between words is replaced with a single newline (the newline may be two characters– see G3D::TextOutput::Options::NewlineStyle). Word wrapping occurs against the number of columns specified by Options::numColumns, minus the current indent level.

Indenting adds the specified number of spaces immediately after a newline. If a newline was followed by spaces in the original string, these are added to the indent spaces. Indenting will indent blank lines and will leave indents after the last newline of a file (if the indent level is non-zero at the end).

Serialization/Marshalling

Text serialization is accomplished using TextOutput by defining the pair of methods:

void serialize(TextOutput& to) const;
void deserialize(TextInput& ti);

See also G3D::TextInput.

BETA API

This API is subject to change in future versions.

Constructor & Destructor Documentation

◆ TextOutput() [1/2]

G3D::TextOutput::TextOutput ( const String filename,
const Settings options = Settings() 
)
explicit

◆ TextOutput() [2/2]

G3D::TextOutput::TextOutput ( const Settings options = Settings())
explicit

Constructs a text output that can later be commited to a string instead of a file.

Member Function Documentation

◆ column()

int G3D::TextOutput::column ( ) const
inline

◆ commit()

void G3D::TextOutput::commit ( bool  flush = true)

Commit to the filename specified on the constructor.

Not called from the destructor; you must call it yourself.

Parameters
flushIf true (default) the file is ready for reading when the method returns, otherwise the method returns immediately and writes the file in the background.

◆ commitString() [1/2]

void G3D::TextOutput::commitString ( String string)

Commits to this string.

◆ commitString() [2/2]

String G3D::TextOutput::commitString ( )

Produces a new string that contains the output.

◆ deleteSpace()

bool G3D::TextOutput::deleteSpace ( )

If the most recently written character was a space, remove it and return true.

Can be called repeatedly to back up over multiple spaces.

◆ line()

int G3D::TextOutput::line ( ) const
inline

Returns one plus the number of newlines written since the output was created.

◆ popIndent()

void G3D::TextOutput::popIndent ( )

◆ printf() [1/2]

void G3D::TextOutput::printf ( const char *  fmt,
  ... 
)

Normal printf conventions.

Note that the output will be reformatted for word-wrapping and newlines

Referenced by G3D::enumToJavaScriptDeclaration().

◆ printf() [2/2]

void G3D::TextOutput::printf ( const String  fmt,
  ... 
)

◆ pushIndent()

void G3D::TextOutput::pushIndent ( )

Increase indent level by 1.

Referenced by G3D::enumToJavaScriptDeclaration().

◆ vprintf()

void G3D::TextOutput::vprintf ( const char *  fmt,
va_list  argPtr 
)

◆ writeBoolean()

void G3D::TextOutput::writeBoolean ( bool  b)

◆ writeCNumber() [1/3]

void G3D::TextOutput::writeCNumber ( double  n,
bool  trailingSpace = true,
bool  minimal = false 
)

Guaranteed to parse as a C syntax double.

◆ writeCNumber() [2/3]

void G3D::TextOutput::writeCNumber ( float  n,
bool  trailingSpace = true,
bool  minimal = false 
)

Guaranteed to parse as a C syntax float.

◆ writeCNumber() [3/3]

void G3D::TextOutput::writeCNumber ( int  n,
bool  trailingSpace = true,
bool  minimal = false 
)

Guaranteed to parse as a C syntax int.

◆ writeNewline()

void G3D::TextOutput::writeNewline ( )

◆ writeNewlines()

void G3D::TextOutput::writeNewlines ( int  numLines)

◆ writeNumber() [1/2]

void G3D::TextOutput::writeNumber ( double  n)

◆ writeNumber() [2/2]

void G3D::TextOutput::writeNumber ( int  n)

◆ writeString()

void G3D::TextOutput::writeString ( const String string)

Writes a quoted string.

Special characters in the string (e.g., \, \t, \n) are escaped so that TextInput will produce the identical string on reading.

◆ writeSymbol() [1/2]

void G3D::TextOutput::writeSymbol ( const String string)

The symbol is written without quotes.

Symbols are required to begin with a letter or underscore and contain only letters, underscores, and numbers or be a C++ symbol (e.g. "{", "(", "++", etc.) so that they may be properly parsed by TextInput::readSymbol. Symbols are printed with a trailing space.

◆ writeSymbol() [2/2]

void G3D::TextOutput::writeSymbol ( char  s)

◆ writeSymbols()

void G3D::TextOutput::writeSymbols ( const String a,
const String b = "",
const String c = "",
const String d = "",
const String e = "",
const String f = "" 
)

Convenient idiom for writing multiple symbols in a row, e.g.

writeSymbols("name", "="); The empty symbols are not written.


documentation generated on Wed Nov 24 2021 08:02:01 using doxygen 1.8.15