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

Writes output to a path only when the written bytes differ from what was loaded on disk. More...

#include <CompareWriter.hpp>

Inheritance diagram for panini::CompareWriter:
panini::ConfiguredWriter< CompareWriterConfig > panini::Writer

Public Member Functions

 CompareWriter (const CompareWriterConfig &config={})
 
 CompareWriter (const std::filesystem::path &filePath, const WriterConfig &config=WriterConfig())
 
 ~CompareWriter () override
 
bool IsChanged () const override
 
- Public Member Functions inherited from panini::ConfiguredWriter< CompareWriterConfig >
 ConfiguredWriter (const CompareWriterConfig &config=CompareWriterConfig {})
 
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=false) override
 
- Protected Member Functions inherited from panini::ConfiguredWriter< CompareWriterConfig >
void WriteNewLine () override
 

Protected Attributes

bool m_pathExists = false
 
std::string m_writtenPrevious
 
std::string m_writtenCurrent
 
- Protected Attributes inherited from panini::ConfiguredWriter< CompareWriterConfig >
CompareWriterConfig m_config
 

Detailed Description

Writes output to a path only when the written bytes differ from what was loaded on disk.

The CompareWriter stores the contents of the target path first. When the new output differs from what was seen before, the output will be committed to the path.

See also
CompareWriterConfig

Constructor & Destructor Documentation

◆ CompareWriter() [1/2]

panini::CompareWriter::CompareWriter ( const CompareWriterConfig config = {})
inlineexplicit

Construct and configure the writer.

Parameters
configConfiguration instance.

◆ CompareWriter() [2/2]

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

Construct and configure the writer.

Parameters
filePathFile that will be compared against the output.
configConfiguration instance.

◆ ~CompareWriter()

panini::CompareWriter::~CompareWriter ( )
inlineoverride

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

Member Function Documentation

◆ IsChanged()

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

Check if the output was changed compared to what was read from disk when the CompareWriter was created.

Reimplemented from panini::ConfiguredWriter< CompareWriterConfig >.

◆ OnCommit()

bool panini::CompareWriter::OnCommit ( bool  force = false)
inlineoverrideprotectedvirtual

Checks if the writer should commit its output to the target.

Implements panini::Writer.

◆ Write()

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

Writes chunks to the output.

Implements panini::Writer.

Member Data Documentation

◆ m_pathExists

bool panini::CompareWriter::m_pathExists = false
protected

◆ m_writtenCurrent

std::string panini::CompareWriter::m_writtenCurrent
protected

◆ m_writtenPrevious

std::string panini::CompareWriter::m_writtenPrevious
protected

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