CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::CodeWriter Class Reference

#include <CeresEngine/Foundation/CodeWriter.hpp>

Inheritance diagram for CeresEngine::CodeWriter:
CeresEngine::IndentHandler

Classes

struct  AlignedLine
 
struct  AlignedLineQueue
 
struct  Options
 
struct  ScopeOptions
 
struct  ScopeState
 
struct  SeparatedList
 

Public Types

using WriterFunctor = FunctionView< void() const >
 

Public Member Functions

 CodeWriter ()
 
 CodeWriter (std::ostream &stream)
 
void setOutputStream (std::ostream &stream)
 Throws std::runtime_error If stream is invalid.
 
void pushOptions (const Options &options)
 
void popOptions ()
 
void beginSeparatedList (String separator=", ")
 Begins a new separated list.
 
void endSeparatedList ()
 Ends a separated list.
 
void separator ()
 Prints the separator, as indicated on the beginSeparatedList call.
 
void beginAlignedLines ()
 
void endAlignedLines ()
 
void alignLine ()
 Inserts spaces to align with the previous groups if line alignment formatting is currently enabled.
 
void beginLine ()
 Begins a new line and inserts the current indentation.
 
void endLine ()
 Ends the current line and inserts the new-line character to the output stream.
 
void write (const StringView &text)
 Writes the given text to the writer stream.
 
template<typename... Args>
void write (const StringView &text1, const StringView &text2, const Args &... rest)
 Writes the given strings to the writer stream.
 
void writeLine (const StringView &text)
 Shortcut for: beginLine(), write(text), endLine().
 
void writeJoined (String separator, const InitializerList< WriterFunctor > &functors)
 Writes multiple entries joined by separator.
 
void beginScope (bool compact=false, bool endWithSemicolon=false, bool useBraces=true)
 Begins a new scope with the '{' character and adds a new line either before or after this character.
 
void endScope ()
 Ends the current scope with the '}' character.
 
void continueScope ()
 Continues the previously ended scope.
 
bool isOpenLine () const
 Returns true if the code writer is currently in an open line (i.e. beginLine was called without closing endLine).
 
- Public Member Functions inherited from CeresEngine::IndentHandler
 IndentHandler (const String &initialIndent=" ")
 
virtual ~IndentHandler ()
 
void setIndent (const String &indent)
 Sets the next indentation string. By default two spaces.
 
void incrementIndent ()
 Increments the indentation.
 
void decrementIndent ()
 Decrements the indentation.
 
const StringgetFullIndent () const
 Returns the current full indentation string.
 

Public Attributes

bool newLineOpenScope = false
 

Private Member Functions

void writeSeparatorIfPending ()
 
const OptionsgetCurrentOptions () const
 
void flushSeparatedLines (AlignedLineQueue &lineQueue)
 
std::ostream & getOutputStream ()
 

Private Attributes

std::ostream * mStream = nullptr
 
Stack< OptionsmOptionsStack
 
bool mOpenLine = true
 
UInt32 mLineAlignmentLevel = 0
 
AlignedLineQueue mQueuedAlignedLines
 
ScopeState mScopeState
 
Stack< ScopeOptionsmScopeOptionStack
 
Stack< SeparatedListmSeparatedLists
 

Member Typedef Documentation

◆ WriterFunctor

Constructor & Destructor Documentation

◆ CodeWriter() [1/2]

CeresEngine::CodeWriter::CodeWriter ( )

◆ CodeWriter() [2/2]

CeresEngine::CodeWriter::CodeWriter ( std::ostream &  stream)
explicit

Member Function Documentation

◆ alignLine()

void CeresEngine::CodeWriter::alignLine ( )

Inserts spaces to align with the previous groups if line alignment formatting is currently enabled.

◆ beginAlignedLines()

void CeresEngine::CodeWriter::beginAlignedLines ( )

◆ beginLine()

void CeresEngine::CodeWriter::beginLine ( )

Begins a new line and inserts the current indentation.

◆ beginScope()

void CeresEngine::CodeWriter::beginScope ( bool  compact = false,
bool  endWithSemicolon = false,
bool  useBraces = true 
)

Begins a new scope with the '{' character and adds a new line either before or after this character.

◆ beginSeparatedList()

void CeresEngine::CodeWriter::beginSeparatedList ( String  separator = ", ")

Begins a new separated list.

While enabled separator will be printed everytime separator() is called, unless it's the last call before endSeparatedList.

Parameters
separatorA separator to used to join items.

◆ continueScope()

void CeresEngine::CodeWriter::continueScope ( )

Continues the previously ended scope.

◆ endAlignedLines()

void CeresEngine::CodeWriter::endAlignedLines ( )

◆ endLine()

void CeresEngine::CodeWriter::endLine ( )

Ends the current line and inserts the new-line character to the output stream.

◆ endScope()

void CeresEngine::CodeWriter::endScope ( )

Ends the current scope with the '}' character.

If next command is not "continueScope", the line wil be ended first.

◆ endSeparatedList()

void CeresEngine::CodeWriter::endSeparatedList ( )

Ends a separated list.

◆ flushSeparatedLines()

void CeresEngine::CodeWriter::flushSeparatedLines ( AlignedLineQueue lineQueue)
private

◆ getCurrentOptions()

const Options & CeresEngine::CodeWriter::getCurrentOptions ( ) const
private

◆ getOutputStream()

std::ostream & CeresEngine::CodeWriter::getOutputStream ( )
inlineprivate

◆ isOpenLine()

bool CeresEngine::CodeWriter::isOpenLine ( ) const
inline

Returns true if the code writer is currently in an open line (i.e. beginLine was called without closing endLine).

◆ popOptions()

void CeresEngine::CodeWriter::popOptions ( )

◆ pushOptions()

void CeresEngine::CodeWriter::pushOptions ( const Options options)

◆ separator()

void CeresEngine::CodeWriter::separator ( )

Prints the separator, as indicated on the beginSeparatedList call.

◆ setOutputStream()

void CeresEngine::CodeWriter::setOutputStream ( std::ostream &  stream)

Throws std::runtime_error If stream is invalid.

◆ write() [1/2]

void CeresEngine::CodeWriter::write ( const StringView text)

Writes the given text to the writer stream.

◆ write() [2/2]

template<typename... Args>
void CeresEngine::CodeWriter::write ( const StringView text1,
const StringView text2,
const Args &...  rest 
)
inline

Writes the given strings to the writer stream.

◆ writeJoined()

void CeresEngine::CodeWriter::writeJoined ( String  separator,
const InitializerList< WriterFunctor > &  functors 
)

Writes multiple entries joined by separator.

Parameters
separatorThe separator to be used when joining the multiple writes.
functorsThe functors to be called for writing entries. If a functor doesn't write anything, no separator will be written as well.

◆ writeLine()

void CeresEngine::CodeWriter::writeLine ( const StringView text)

Shortcut for: beginLine(), write(text), endLine().

◆ writeSeparatorIfPending()

void CeresEngine::CodeWriter::writeSeparatorIfPending ( )
private

Member Data Documentation

◆ mLineAlignmentLevel

UInt32 CeresEngine::CodeWriter::mLineAlignmentLevel = 0
private

◆ mOpenLine

bool CeresEngine::CodeWriter::mOpenLine = true
private

◆ mOptionsStack

Stack<Options> CeresEngine::CodeWriter::mOptionsStack
private

◆ mQueuedAlignedLines

AlignedLineQueue CeresEngine::CodeWriter::mQueuedAlignedLines
private

◆ mScopeOptionStack

Stack<ScopeOptions> CeresEngine::CodeWriter::mScopeOptionStack
private

◆ mScopeState

ScopeState CeresEngine::CodeWriter::mScopeState
private

◆ mSeparatedLists

Stack<SeparatedList> CeresEngine::CodeWriter::mSeparatedLists
private

◆ mStream

std::ostream* CeresEngine::CodeWriter::mStream = nullptr
private

◆ newLineOpenScope

bool CeresEngine::CodeWriter::newLineOpenScope = false

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