Panini 1.4.0
Header-only library for generating C++, written in C++17
panini::FileWriter Class Reference

Writes output to a target file using a file stream. More...

#include <FileWriter.hpp>

Inheritance diagram for panini::FileWriter:
panini::ConfiguredWriter< FileWriterConfig > panini::Writer

Public Member Functions

 FileWriter (const FileWriterConfig &config={})
 
 FileWriter (const std::filesystem::path &path, const WriterConfig &config=WriterConfig())
 
 ~FileWriter () override
 
bool IsChanged () const override
 
- Public Member Functions inherited from panini::ConfiguredWriter< FileWriterConfig >
 ConfiguredWriter (const FileWriterConfig &config=FileWriterConfig {})
 
virtual ~ConfiguredWriter ()=default
 
const WriterConfigGetConfig () const override
 
BraceBreakingStyle GetBraceBreakingStyle () const override
 
IncludeStyle GetIncludeStyle () const override
 
bool IsOnNewLine () const override
 
Writeroperator<< (const std::string &chunk) override
 
Writeroperator<< (const char *chunkString) override
 
Writeroperator<< (const NextLine &command) override
 
Writeroperator<< (const IndentPush &command) override
 
Writeroperator<< (const IndentPop &command) override
 
Writeroperator<< (Command &&command) override
 
void SetIsInCommentBlock (bool value) override
 
bool Commit (bool force=false) override
 
- Public Member Functions inherited from panini::Writer
virtual ~Writer ()=default
 

Protected Member Functions

void Write (const std::string &chunk) override
 
bool OnCommit (bool force) override
 
- Protected Member Functions inherited from panini::ConfiguredWriter< FileWriterConfig >
void WriteNewLine () override
 

Protected Attributes

std::ofstream m_target
 
std::string m_written
 
- Protected Attributes inherited from panini::ConfiguredWriter< FileWriterConfig >
FileWriterConfig m_config
 

Detailed Description

Writes output to a target file using a file stream.

Unlike the CompareWriter, the FileWriter will always write to the target file regardless of whether the output has changed.

The file stream is closed when the writer is committed, which happens automatically when the writer is destroyed.

See also
FileWriterConfig

Constructor & Destructor Documentation

◆ FileWriter() [1/2]

panini::FileWriter::FileWriter ( const FileWriterConfig config = {})
inline

Construct and configure the writer.

Parameters
configConfiguration instance.

◆ FileWriter() [2/2]

panini::FileWriter::FileWriter ( const std::filesystem::path &  path,
const WriterConfig config = WriterConfig() 
)
inline
Deprecated:
This constructor will be removed in the next major release. Prefer using the constructor that takes FileWriterConfig.

Construct and configure the writer.

Parameters
pathPath to the target file.
configConfiguration instance.

◆ ~FileWriter()

panini::FileWriter::~FileWriter ( )
inlineoverride

Will call Commit() automatically when the writer is destroyed.

Member Function Documentation

◆ IsChanged()

bool panini::FileWriter::IsChanged ( ) const
inlineoverridevirtual

Always close the stream when Commit is called.

Reimplemented from panini::ConfiguredWriter< FileWriterConfig >.

◆ OnCommit()

bool panini::FileWriter::OnCommit ( bool  force)
inlineoverrideprotectedvirtual

Close the file stream when the writer is committed.

Implements panini::Writer.

◆ Write()

void panini::FileWriter::Write ( const std::string &  chunk)
inlineoverrideprotectedvirtual

Writes the chunk to the file stream.

Implements panini::Writer.

Member Data Documentation

◆ m_target

std::ofstream panini::FileWriter::m_target
protected

◆ m_written

std::string panini::FileWriter::m_written
protected

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