Support Forum G3D Web Page |
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... | |
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.
|
explicit |
Constructs a text output that can later be commited to a string instead of a file.
|
inline |
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.
flush | If true (default) the file is ready for reading when the method returns, otherwise the method returns immediately and writes the file in the background. |
void G3D::TextOutput::commitString | ( | String & | string | ) |
Commits to this string.
String G3D::TextOutput::commitString | ( | ) |
Produces a new string that contains the output.
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.
|
inline |
Returns one plus the number of newlines written since the output was created.
void G3D::TextOutput::popIndent | ( | ) |
Referenced by G3D::enumToJavaScriptDeclaration().
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().
void G3D::TextOutput::printf | ( | const String | fmt, |
... | |||
) |
void G3D::TextOutput::pushIndent | ( | ) |
Increase indent level by 1.
Referenced by G3D::enumToJavaScriptDeclaration().
void G3D::TextOutput::vprintf | ( | const char * | fmt, |
va_list | argPtr | ||
) |
void G3D::TextOutput::writeBoolean | ( | bool | b | ) |
void G3D::TextOutput::writeCNumber | ( | double | n, |
bool | trailingSpace = true , |
||
bool | minimal = false |
||
) |
Guaranteed to parse as a C syntax double.
void G3D::TextOutput::writeCNumber | ( | float | n, |
bool | trailingSpace = true , |
||
bool | minimal = false |
||
) |
Guaranteed to parse as a C syntax float.
void G3D::TextOutput::writeCNumber | ( | int | n, |
bool | trailingSpace = true , |
||
bool | minimal = false |
||
) |
Guaranteed to parse as a C syntax int.
void G3D::TextOutput::writeNewline | ( | ) |
Referenced by G3D::enumToJavaScriptDeclaration().
void G3D::TextOutput::writeNewlines | ( | int | numLines | ) |
void G3D::TextOutput::writeNumber | ( | double | n | ) |
void G3D::TextOutput::writeNumber | ( | int | n | ) |
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.
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.
void G3D::TextOutput::writeSymbol | ( | char | s | ) |