KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PRETTIFIED_FILE_OUTPUTFORMATTER Class Reference

#include <richio.h>

Inheritance diagram for PRETTIFIED_FILE_OUTPUTFORMATTER:
OUTPUTFORMATTER

Public Member Functions

 PRETTIFIED_FILE_OUTPUTFORMATTER (const wxString &aFileName, KICAD_FORMAT::FORMAT_MODE aFormatMode=KICAD_FORMAT::FORMAT_MODE::NORMAL, const wxChar *aMode=wxT("wt"), char aQuoteChar='"' )
 
 ~PRETTIFIED_FILE_OUTPUTFORMATTER ()
 
bool Finish () override
 Runs prettification over the buffered bytes, writes them to the sibling temp file, fsyncs, and atomically renames the temp file over the final target.
 
virtual const char * GetQuoteChar (const char *wrapee) const
 Perform quote character need determination.
 
int PRINTF_FUNC_N Print (int nestLevel, const char *fmt,...)
 Format and write text to the output stream.
 
int PRINTF_FUNC Print (const char *fmt,...)
 Format and write text to the output stream.
 
virtual std::string Quotes (const std::string &aWrapee) const
 Check aWrapee input string for a need to be quoted (e.g.
 
std::string Quotew (const wxString &aWrapee) const
 

Protected Member Functions

void write (const char *aOutBuf, int aCount) override
 Should be coded in the interface implementation (derived) classes.
 

Static Protected Member Functions

static const char * GetQuoteChar (const char *wrapee, const char *quote_char)
 Perform quote character need determination according to the Specctra DSN specification.
 

Private Member Functions

int sprint (const char *fmt,...)
 
int vprint (const char *fmt, va_list ap)
 

Private Attributes

FILE * m_fp
 
wxString m_filename
 final destination path
 
wxString m_tempPath
 sibling temp file being written
 
bool m_committed
 set true once rename has landed
 
std::string m_buf
 
KICAD_FORMAT::FORMAT_MODE m_mode
 
std::vector< char > m_buffer
 
char quoteChar [2]
 

Detailed Description

Definition at line 510 of file richio.h.

Constructor & Destructor Documentation

◆ PRETTIFIED_FILE_OUTPUTFORMATTER()

PRETTIFIED_FILE_OUTPUTFORMATTER::PRETTIFIED_FILE_OUTPUTFORMATTER ( const wxString & aFileName,
KICAD_FORMAT::FORMAT_MODE aFormatMode = KICAD_FORMAT::FORMAT_MODE::NORMAL,
const wxChar * aMode = wxT( "wt" ),
char aQuoteChar = '"' )

◆ ~PRETTIFIED_FILE_OUTPUTFORMATTER()

PRETTIFIED_FILE_OUTPUTFORMATTER::~PRETTIFIED_FILE_OUTPUTFORMATTER ( )

Definition at line 693 of file richio.cpp.

References Finish(), m_committed, m_filename, m_fp, and m_tempPath.

Member Function Documentation

◆ Finish()

bool PRETTIFIED_FILE_OUTPUTFORMATTER::Finish ( )
overridevirtual

Runs prettification over the buffered bytes, writes them to the sibling temp file, fsyncs, and atomically renames the temp file over the final target.

A crash or power loss anywhere in this sequence leaves the final target byte-identical to its prior contents.

Returns
true on successful commit.
Exceptions
IO_ERRORif prettification, fwrite, fsync, or rename fails.

Reimplemented from OUTPUTFORMATTER.

Definition at line 700 of file richio.cpp.

References _, m_buf, m_committed, m_filename, m_fp, m_mode, m_tempPath, KICAD_FORMAT::Prettify(), and THROW_IO_ERROR.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CopySexprFile(), LIBRARY_MANAGER::CreateGlobalTable(), FP_CACHE::Save(), LIBRARY_TABLE::Save(), PCB_IO_KICAD_SEXPR::SaveBoard(), SCH_IO_KICAD_SEXPR::SaveSchematicFile(), NETLIST_EXPORTER_KICAD::WriteNetlist(), and ~PRETTIFIED_FILE_OUTPUTFORMATTER().

◆ GetQuoteChar() [1/2]

const char * OUTPUTFORMATTER::GetQuoteChar ( const char * wrapee) const
virtualinherited

Perform quote character need determination.

It returns the quote character as a single character string for a given input wrapee string. If the wrappee does not need to be quoted, the return value is "" (the null string), such as when there are no delimiters in the input wrapee string. If you want the quote_char to be assuredly not "", then pass in "(" as the wrappee.

Implementations are free to override the default behavior, which is to call the static function of the same name.

Parameters
wrapeeA string that might need wrapping on each end.
Returns
the quote_char as a single character string, or "" if the wrapee does not need to be wrapped.

Definition at line 382 of file richio.cpp.

References GetQuoteChar(), and quoteChar.

◆ GetQuoteChar() [2/2]

const char * OUTPUTFORMATTER::GetQuoteChar ( const char * wrapee,
const char * quote_char )
staticprotectedinherited

◆ Print() [1/2]

int OUTPUTFORMATTER::Print ( const char * fmt,
... )
inherited

Format and write text to the output stream.

Parameters
fmtA printf() style format string.
...a variable list of parameters that will get blended into the output under control of the format string.
Returns
int - the number of characters output.
Exceptions
IO_ERROR,ifthere is a problem outputting, such as a full disk.

Definition at line 455 of file richio.cpp.

References result, and vprint().

◆ Print() [2/2]

int OUTPUTFORMATTER::Print ( int nestLevel,
const char * fmt,
... )
inherited

Format and write text to the output stream.

Parameters
nestLevelThe multiple of spaces to precede the output with.
fmtA printf() style format string.
...a variable list of parameters that will get blended into the output under control of the format string.
Returns
int - the number of characters output.
Exceptions
IO_ERROR,ifthere is a problem outputting, such as a full disk.

Definition at line 426 of file richio.cpp.

References NESTWIDTH, result, sprint(), and vprint().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CopySexprFile(), COMPONENT::Format(), COMPONENT_NET::Format(), DSN::ANCESTOR::Format(), DSN::BOUNDARY::Format(), DSN::CIRCLE::Format(), DSN::CLASS::Format(), DSN::COMP_ORDER::Format(), DSN::COMPONENT::Format(), DSN::CONTROL::Format(), DSN::ELEM::Format(), DSN::FROMTO::Format(), DSN::GRID::Format(), DSN::IMAGE::Format(), DSN::KEEPOUT::Format(), DSN::LAYER::Format(), DSN::LAYER_NOISE_WEIGHT::Format(), DSN::LAYER_RULE::Format(), DSN::NET::Format(), DSN::NET_OUT::Format(), DSN::PADSTACK::Format(), DSN::PATH::Format(), DSN::PCB::Format(), DSN::PIN::Format(), DSN::PLACE::Format(), DSN::POINT::Format(), DSN::PROPERTY::Format(), DSN::QARC::Format(), DSN::RECTANGLE::Format(), DSN::RULE::Format(), DSN::SESSION::Format(), DSN::SHAPE::Format(), DSN::SPECCTRA_LAYER_PAIR::Format(), DSN::STRINGPROP::Format(), DSN::SUPPLY_PIN::Format(), DSN::TOKPROP::Format(), DSN::UNIT_RES::Format(), DSN::VIA::Format(), DSN::WINDOW::Format(), DSN::WIRE::Format(), DSN::WIRE_VIA::Format(), EDA_TEXT::Format(), NETLIST::Format(), PAGE_INFO::Format(), PCB_CALCULATOR_DATAFILE::Format(), PCB_PLOT_PARAMS::Format(), STROKE_PARAMS::Format(), TEMPLATE_FIELDNAME::Format(), TEMPLATES::Format(), TITLE_BLOCK::Format(), XNODE::Format(), formatArc(), formatBezier(), BOARD_STACKUP::FormatBoardStackup(), KICAD_FORMAT::FormatBool(), formatCircle(), DSN::CLASSES::FormatContents(), DSN::HISTORY::FormatContents(), DSN::IMAGE::FormatContents(), DSN::PADSTACK::FormatContents(), DSN::PARSER::FormatContents(), DSN::PLACEMENT::FormatContents(), DSN::REGION::FormatContents(), DSN::ROUTE::FormatContents(), DSN::WAS_IS::FormatContents(), XNODE::FormatContents(), formatFill(), DSN::PIN_REF::FormatIt(), SCH_IO_KICAD_SEXPR_LIB_CACHE::formatLibraryHeader(), formatNode(), KICAD_FORMAT::FormatOptBool(), formatPoly(), formatRect(), KICAD_FORMAT::FormatStreamData(), KICAD_FORMAT::FormatUuid(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveArc(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveBezier(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveCircle(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveDocFile(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveField(), SCH_IO_KICAD_SEXPR_LIB_CACHE::saveField(), SCH_IO_KICAD_LEGACY_LIB_CACHE::savePin(), SCH_IO_KICAD_SEXPR_LIB_CACHE::savePin(), SCH_IO_KICAD_LEGACY_LIB_CACHE::savePolyLine(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveRectangle(), SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol(), SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol(), SCH_IO_KICAD_LEGACY_LIB_CACHE::saveText(), SCH_IO_KICAD_SEXPR_LIB_CACHE::saveText(), SCH_IO_KICAD_SEXPR_LIB_CACHE::saveTextBox(), PANEL_REGULATOR::WriteDataFile(), NETLIST_EXPORTER_SPICE::WriteDirectives(), SPICE_CIRCUIT_MODEL::WriteDirectives(), EMBEDDED_FILES::WriteEmbeddedFiles(), NETLIST_EXPORTER_SPICE::WriteHead(), NETLIST_EXPORTER_SPICE_MODEL::WriteHead(), PCB_CALCULATOR_DATAFILE::WriteHeader(), NETLIST_EXPORTER_SPICE::writeInclude(), NETLIST_EXPORTER_SPICE::writeItems(), NETLIST_EXPORTER_SPICE::writeModels(), NETLIST_EXPORTER_SPICE::WriteTail(), and NETLIST_EXPORTER_SPICE_MODEL::WriteTail().

◆ Quotes()

std::string OUTPUTFORMATTER::Quotes ( const std::string & aWrapee) const
virtualinherited

Check aWrapee input string for a need to be quoted (e.g.

contains a ')' character or a space), and for " double quotes within the string that need to be escaped such that the DSNLEXER will correctly parse the string from a file later.

Parameters
aWrapeeis a string that might need wrapping in double quotes, and it might need to have its internal content escaped, or not.
Returns
a std::string- whose c_str() function can be called for passing to printf() style functions that output UTF8 encoded s-expression streams.
Exceptions
IO_ERROR,ifthere is any kind of problem with the input string.

Definition at line 472 of file richio.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), formatNode(), Quotew(), and SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().

◆ Quotew()

◆ sprint()

int OUTPUTFORMATTER::sprint ( const char * fmt,
... )
privateinherited

Definition at line 414 of file richio.cpp.

References vprint().

Referenced by Print().

◆ vprint()

int OUTPUTFORMATTER::vprint ( const char * fmt,
va_list ap )
privateinherited

Definition at line 388 of file richio.cpp.

References m_buffer, and write().

Referenced by Print(), Print(), and sprint().

◆ write()

void PRETTIFIED_FILE_OUTPUTFORMATTER::write ( const char * aOutBuf,
int aCount )
overrideprotectedvirtual

Should be coded in the interface implementation (derived) classes.

Parameters
aOutBufis the start of a byte buffer to write.
aCounttells how many bytes to write.
Exceptions
IO_ERROR,ifthere is a problem outputting, such as a full disk.

Implements OUTPUTFORMATTER.

Definition at line 731 of file richio.cpp.

References m_buf.

Member Data Documentation

◆ m_buf

std::string PRETTIFIED_FILE_OUTPUTFORMATTER::m_buf
private

Definition at line 538 of file richio.h.

Referenced by Finish(), and write().

◆ m_buffer

std::vector<char> OUTPUTFORMATTER::m_buffer
privateinherited

Definition at line 407 of file richio.h.

Referenced by OUTPUTFORMATTER(), and vprint().

◆ m_committed

bool PRETTIFIED_FILE_OUTPUTFORMATTER::m_committed
private

set true once rename has landed

Definition at line 537 of file richio.h.

Referenced by Finish(), PRETTIFIED_FILE_OUTPUTFORMATTER(), and ~PRETTIFIED_FILE_OUTPUTFORMATTER().

◆ m_filename

wxString PRETTIFIED_FILE_OUTPUTFORMATTER::m_filename
private

final destination path

Definition at line 535 of file richio.h.

Referenced by Finish(), PRETTIFIED_FILE_OUTPUTFORMATTER(), and ~PRETTIFIED_FILE_OUTPUTFORMATTER().

◆ m_fp

FILE* PRETTIFIED_FILE_OUTPUTFORMATTER::m_fp
private

◆ m_mode

KICAD_FORMAT::FORMAT_MODE PRETTIFIED_FILE_OUTPUTFORMATTER::m_mode
private

Definition at line 539 of file richio.h.

Referenced by Finish(), and PRETTIFIED_FILE_OUTPUTFORMATTER().

◆ m_tempPath

wxString PRETTIFIED_FILE_OUTPUTFORMATTER::m_tempPath
private

sibling temp file being written

Definition at line 536 of file richio.h.

Referenced by Finish(), PRETTIFIED_FILE_OUTPUTFORMATTER(), and ~PRETTIFIED_FILE_OUTPUTFORMATTER().

◆ quoteChar

char OUTPUTFORMATTER::quoteChar[2]
privateinherited

Definition at line 408 of file richio.h.

Referenced by GetQuoteChar(), and OUTPUTFORMATTER().


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