Spicy
Public Member Functions | List of all members
hilti::CodeFormatter Class Reference

#include <code-formatter.h>

Inheritance diagram for hilti::CodeFormatter:
hilti::detail::cxx::Formatter

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 ()
 
CodeFormatterprintString (const std::string &s)
 
 CodeFormatter (const CodeFormatter &)=delete
 
 CodeFormatter (CodeFormatter &&)=delete
 
CodeFormatteroperator= (const CodeFormatter &f)=delete
 
CodeFormatteroperator= (CodeFormatter &&f)=delete
 

Detailed Description

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();.

Constructor & Destructor Documentation

◆ CodeFormatter()

hilti::CodeFormatter::CodeFormatter ( std::string  comment = "//")
inlineexplicit
Parameters
commentstring beginning a comment line in the target language

Member Function Documentation

◆ comment()

void CodeFormatter::comment ( const std::string &  s)

Inserts a comment line, prefixing it with the comment prefix.

◆ dedent()

void hilti::CodeFormatter::dedent ( )
inline

Decreates the indentation by one level.

◆ eol()

void CodeFormatter::eol ( )

Signals the end of a statement. This will insert both a semicolon and a newline.

◆ indent()

void hilti::CodeFormatter::indent ( )
inline

Increates the indentation by one level.

◆ next()

void CodeFormatter::next ( )

Signals the beginning of a new line.

◆ output()

bool hilti::CodeFormatter::output ( std::ostream &  out)
inline

Writes all output generated so far to an external stream.

◆ printString()

CodeFormatter & CodeFormatter::printString ( const std::string &  s)

Adds a string to the output.

◆ quoted()

void CodeFormatter::quoted ( const std::string &  s)

Surrounds a string with quotation mark and escapes it appropiately.

◆ separator()

void CodeFormatter::separator ( )

Inserts an empty line as a separator. Signals the end of a line. This will insert a newline.

◆ str()

auto hilti::CodeFormatter::str ( ) const
inline

Returns a string representation of all output generated so far.

◆ stream()

auto& hilti::CodeFormatter::stream ( )
inline

Returns an stream with the output so far.


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