![]() |
Spicy
|
#include <code-formatter.h>
Public Member Functions | |
CodeFormatter (std::string comment="//") | |
bool | output (std::ostream &out) |
auto | str () const |
void | next () |
void | separator () |
void | eol () |
void | eos () |
void | quoted (const std::string &s) |
void | comment (const std::string &s) |
void | indent () |
void | dedent () |
auto & | stream () |
CodeFormatter & | printString (const std::string &s) |
CodeFormatter (const CodeFormatter &)=delete | |
CodeFormatter (CodeFormatter &&)=delete | |
CodeFormatter & | operator= (const CodeFormatter &f)=delete |
CodeFormatter & | operator= (CodeFormatter &&f)=delete |
Base class providing support for generating "C-style" code.
The class handles basic formatting, such as code indentation and white space insertion. The main output method for user code is printString()
. For most of the formatting methods, there are corresponding i/o stream manipulators so that one can writem, e.g., my_formatter << eol();
.
|
inlineexplicit |
comment | string beginning a comment line in the target language |
void CodeFormatter::comment | ( | const std::string & | s | ) |
Inserts a comment line, prefixing it with the comment prefix.
|
inline |
Decreates the indentation by one level.
void CodeFormatter::eol | ( | ) |
Signals the end of a statement. This will insert both a semicolon and a newline.
|
inline |
Increates the indentation by one level.
void CodeFormatter::next | ( | ) |
Signals the beginning of a new line.
|
inline |
Writes all output generated so far to an external stream.
CodeFormatter & CodeFormatter::printString | ( | const std::string & | s | ) |
Adds a string to the output.
void CodeFormatter::quoted | ( | const std::string & | s | ) |
Surrounds a string with quotation mark and escapes it appropiately.
void CodeFormatter::separator | ( | ) |
Inserts an empty line as a separator. Signals the end of a line. This will insert a newline.
|
inline |
Returns a string representation of all output generated so far.
|
inline |
Returns an stream with the output so far.