KiCad PCB EDA Suite
|
A LINE_READER that reads from an open file. More...
#include <richio.h>
Public Member Functions | |
FILE_LINE_READER (const wxString &aFileName, unsigned aStartingLineNumber=0, unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX) | |
Take aFileName and the size of the desired line buffer and opens the file and assumes the obligation to close it. | |
FILE_LINE_READER (FILE *aFile, const wxString &aFileName, bool doOwn=true, unsigned aStartingLineNumber=0, unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX) | |
Take an open FILE and the size of the desired line buffer and takes ownership of the open file, i.e. | |
~FILE_LINE_READER () | |
May or may not close the open file, depending on doOwn in constructor. | |
char * | ReadLine () override |
Read a line of text into the buffer and increments the line number counter. | |
void | Rewind () |
Rewind the file and resets the line number back to zero. | |
long int | FileLength () |
long int | CurPos () |
virtual const wxString & | GetSource () const |
Returns the name of the source of the lines in an abstract sense. | |
char * | Line () const |
Return a pointer to the last line that was read in. | |
operator char * () const | |
A casting operator that returns a char* pointer to the start of the line buffer. | |
virtual unsigned | LineNumber () const |
Return the line number of the last line read from this LINE_READER. | |
unsigned | Length () const |
Return the number of bytes in the last line read from this LINE_READER. | |
Protected Member Functions | |
void | expandCapacity (unsigned aNewsize) |
Will expand the capacity of line up to maxLineLength but not greater, so be careful about making assumptions of capacity after calling this. | |
Protected Attributes | |
bool | m_iOwn |
if I own the file, I'll promise to close it, else not. | |
FILE * | m_fp |
I may own this file, but might not. | |
unsigned | m_length |
no. bytes in line before trailing nul. | |
unsigned | m_lineNum |
char * | m_line |
the read line of UTF8 text | |
unsigned | m_capacity |
no. bytes allocated for line. | |
unsigned | m_maxLineLength |
maximum allowed capacity using resizing. | |
wxString | m_source |
origin of text lines, e.g. filename or "clipboard" | |
A LINE_READER that reads from an open file.
File must be already open so that this class can exist without any UI policy.
FILE_LINE_READER::FILE_LINE_READER | ( | const wxString & | aFileName, |
unsigned | aStartingLineNumber = 0 , |
||
unsigned | aMaxLineLength = LINE_READER_LINE_DEFAULT_MAX |
||
) |
Take aFileName and the size of the desired line buffer and opens the file and assumes the obligation to close it.
aFileName | is the name of the file to open and to use for error reporting purposes. |
aStartingLineNumber | is the initial line number to report on error, and is accessible here for the case where multiple DSNLEXERs are reading from the same file in sequence, all from the same open file (with doOwn = false). Internally it is incremented by one after each ReadLine(), so the first reported line number will always be one greater than what is provided here. |
aMaxLineLength | is the number of bytes to use in the line buffer. |
IO_ERROR | if aFileName cannot be opened. |
Definition at line 192 of file richio.cpp.
References _, m_fp, LINE_READER::m_lineNum, LINE_READER::m_source, KIPLATFORM::IO::SeqFOpen(), and THROW_IO_ERROR.
FILE_LINE_READER::FILE_LINE_READER | ( | FILE * | aFile, |
const wxString & | aFileName, | ||
bool | doOwn = true , |
||
unsigned | aStartingLineNumber = 0 , |
||
unsigned | aMaxLineLength = LINE_READER_LINE_DEFAULT_MAX |
||
) |
Take an open FILE and the size of the desired line buffer and takes ownership of the open file, i.e.
assumes the obligation to close it.
aFile | is an open file. |
aFileName | is the name of the file for error reporting purposes. |
doOwn | if true, means I should close the open file, else not. |
aStartingLineNumber | is the initial line number to report on error, and is accessible here for the case where multiple DSNLEXERs are reading from the same file in sequence, all from the same open file (with doOwn = false). Internally it is incremented by one after each ReadLine(), so the first reported line number will always be one greater than what is provided here. |
aMaxLineLength | is the number of bytes to use in the line buffer. |
Definition at line 210 of file richio.cpp.
References LINE_READER::m_lineNum, and LINE_READER::m_source.
FILE_LINE_READER::~FILE_LINE_READER | ( | ) |
May or may not close the open file, depending on doOwn in constructor.
Definition at line 221 of file richio.cpp.
long int FILE_LINE_READER::CurPos | ( | ) |
Definition at line 238 of file richio.cpp.
References m_fp.
|
protectedinherited |
Will expand the capacity of line up to maxLineLength but not greater, so be careful about making assumptions of capacity after calling this.
Definition at line 165 of file richio.cpp.
References LINE_READER::m_capacity, LINE_READER::m_length, LINE_READER::m_line, and LINE_READER::m_maxLineLength.
Referenced by ReadLine(), STRING_LINE_READER::ReadLine(), and INPUTSTREAM_LINE_READER::ReadLine().
long int FILE_LINE_READER::FileLength | ( | ) |
Definition at line 228 of file richio.cpp.
References m_fp.
|
inlinevirtualinherited |
Returns the name of the source of the lines in an abstract sense.
This may be a file or it may be the clipboard or any other source of lines of text. The returned string is useful for reporting error messages.
Reimplemented in FILTER_READER, and WHITESPACE_FILTER_READER.
Definition at line 121 of file richio.h.
Referenced by PCB_IO_KICAD_LEGACY::biuParse(), PCB_IO_KICAD_LEGACY::degParse(), WRLPROC::GetFileName(), FILTER_READER::GetSource(), WHITESPACE_FILTER_READER::GetSource(), PCB_IO_KICAD_LEGACY::getVersion(), CMP_READER::Load(), LEGACY_NETLIST_READER::loadComponent(), LEGACY_NETLIST_READER::loadFootprintFilters(), LEGACY_NETLIST_READER::loadNet(), PCB_IO_KICAD_LEGACY::loadPAD(), SCH_IO_KICAD_LEGACY_LIB_CACHE::LoadPart(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin(), PCB_IO_KICAD_LEGACY::loadSETUP(), SCH_IO_KICAD_LEGACY::loadSymbol(), GPCB_FPL_CACHE::parseFOOTPRINT(), and WRLPROC::WRLPROC().
|
inlineinherited |
Return the number of bytes in the last line read from this LINE_READER.
Definition at line 155 of file richio.h.
Referenced by LEGACY_NETLIST_READER::loadComponent(), LEGACY_NETLIST_READER::loadFootprintFilters(), LEGACY_NETLIST_READER::loadNet(), FILTER_READER::ReadLine(), and WHITESPACE_FILTER_READER::ReadLine().
|
inlineinherited |
Return a pointer to the last line that was read in.
Definition at line 129 of file richio.h.
Referenced by bench_string_lr(), bench_string_lr_reuse(), bench_wxbis(), bench_wxbis_reuse(), bench_wxis(), bench_wxis_reuse(), PCB_IO_KICAD_LEGACY::biuParse(), PCB_IO_KICAD_LEGACY::CanReadFootprint(), PCB_IO_KICAD_LEGACY::degParse(), PCB_IO_KICAD_LEGACY::getVersion(), NETLIST_READER::GuessNetlistFileType(), PCB_IO_GEDA::ImportFootprint(), SCH_IO_KICAD_LEGACY_LIB_CACHE::Load(), CMP_READER::Load(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadAliases(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadArc(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadBezier(), SCH_IO_KICAD_LEGACY::loadBitmap(), SCH_IO_KICAD_LEGACY::loadBusAlias(), SCH_IO_KICAD_LEGACY::loadBusEntry(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadCircle(), SCH_IO_KICAD_LEGACY::LoadContent(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadDocs(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadDrawEntries(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField(), SCH_IO_KICAD_LEGACY::loadFile(), EXCELLON_IMAGE::LoadFile(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadFootprintFilters(), PCB_IO_KICAD_LEGACY::loadFP_SHAPE(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadHeader(), SCH_IO_KICAD_LEGACY::loadHeader(), SCH_IO_KICAD_LEGACY::loadJunction(), BITMAP_BASE::LoadLegacyData(), PCB_IO_KICAD_LEGACY::loadMODULE_TEXT(), LP_CACHE::LoadModules(), LEGACY_NETLIST_READER::LoadNetlist(), SCH_IO_KICAD_LEGACY::loadNoConnect(), SCH_IO_KICAD_LEGACY::loadPageSettings(), SCH_IO_KICAD_LEGACY_LIB_CACHE::LoadPart(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPolyLine(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadRect(), SCH_IO_KICAD_LEGACY::loadSymbol(), SCH_IO_KICAD_LEGACY::loadText(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadText(), PCB_IO_KICAD_LEGACY::loadTrackList(), SCH_IO_KICAD_LEGACY::loadWire(), GPCB_FPL_CACHE::parseParameters(), DSNLEXER::PopReader(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr(), FILTER_READER::ReadLine(), SafeReadFile(), LP_CACHE::SkipIndex(), EXCELLON_IMAGE::TestFileIsExcellon(), and GERBER_FILE_IMAGE::TestFileIsRS274().
|
inlinevirtualinherited |
Return the line number of the last line read from this LINE_READER.
Lines start from 1.
Reimplemented in FILTER_READER, and WHITESPACE_FILTER_READER.
Definition at line 147 of file richio.h.
Referenced by PCB_IO_KICAD_LEGACY::biuParse(), SCH_IO_KICAD_LEGACY::checkpoint(), SCH_IO_KICAD_SEXPR_PARSER::checkpoint(), PCB_IO_KICAD_LEGACY::checkpoint(), PCB_IO_KICAD_LEGACY::degParse(), FILTER_READER::LineNumber(), WHITESPACE_FILTER_READER::LineNumber(), CMP_READER::Load(), LEGACY_NETLIST_READER::loadComponent(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadDocs(), LEGACY_NETLIST_READER::loadFootprintFilters(), PCB_IO_KICAD_LEGACY::loadFP_SHAPE(), LEGACY_NETLIST_READER::loadNet(), PCB_IO_KICAD_LEGACY::loadPAD(), SCH_IO_KICAD_LEGACY_LIB_CACHE::LoadPart(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin(), PCB_IO_KICAD_LEGACY::loadSHEET(), SCH_IO_KICAD_LEGACY::loadSymbol(), and GPCB_FPL_CACHE::parseFOOTPRINT().
|
inlineinherited |
|
overridevirtual |
Read a line of text into the buffer and increments the line number counter.
If the line is larger than the maximum length passed to the constructor, then an exception is thrown. The line is nul terminated.
IO_ERROR | when a line is too long. |
Implements LINE_READER.
Definition at line 244 of file richio.cpp.
References _, LINE_READER::expandCapacity(), getc_unlocked, LINE_READER::m_capacity, m_fp, LINE_READER::m_length, LINE_READER::m_line, LINE_READER::m_lineNum, LINE_READER::m_maxLineLength, and THROW_IO_ERROR.
Referenced by SCH_IO_KICAD_LEGACY_LIB_CACHE::Load(), PCB_IO_KICAD_LEGACY::LoadBoard(), PCB_IO_KICAD_SEXPR::LoadBoard(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadDocs(), SCH_IO_KICAD_LEGACY::loadFile(), SCH_IO_KICAD_SEXPR::loadFile(), EXCELLON_IMAGE::LoadFile(), SCH_IO_KICAD_LEGACY_LIB_CACHE::loadHeader(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), GERBER_JOBFILE_READER::ReadGerberJobFile(), SafeReadFile(), GERBV::IFACE::SaveFileAs(), EXCELLON_IMAGE::TestFileIsExcellon(), and GERBER_FILE_IMAGE::TestFileIsRS274().
|
inline |
Rewind the file and resets the line number back to zero.
Line number will go to 1 on first ReadLine().
Definition at line 234 of file richio.h.
Referenced by PCB_IO_KICAD_LEGACY::LoadBoard(), PCB_IO_KICAD_SEXPR::LoadBoard(), SCH_IO_KICAD_LEGACY::loadFile(), and SCH_IO_KICAD_SEXPR::loadFile().
|
protectedinherited |
no. bytes allocated for line.
Definition at line 171 of file richio.h.
Referenced by LINE_READER::expandCapacity(), LINE_READER::LINE_READER(), ReadLine(), STRING_LINE_READER::ReadLine(), and INPUTSTREAM_LINE_READER::ReadLine().
|
protected |
I may own this file, but might not.
Definition at line 245 of file richio.h.
Referenced by CurPos(), FILE_LINE_READER(), FileLength(), ReadLine(), and ~FILE_LINE_READER().
|
protected |
if I own the file, I'll promise to close it, else not.
Definition at line 244 of file richio.h.
Referenced by ~FILE_LINE_READER().
|
protectedinherited |
no. bytes in line before trailing nul.
Definition at line 167 of file richio.h.
Referenced by LINE_READER::expandCapacity(), BLOB_READER::ReadLine(), FILTER_READER::ReadLine(), WHITESPACE_FILTER_READER::ReadLine(), ReadLine(), STRING_LINE_READER::ReadLine(), INPUTSTREAM_LINE_READER::ReadLine(), and STDISTREAM_LINE_READER::ReadLine().
|
protectedinherited |
the read line of UTF8 text
Definition at line 170 of file richio.h.
Referenced by BLOB_READER::BLOB_READER(), LINE_READER::expandCapacity(), FILTER_READER::FILTER_READER(), LINE_READER::LINE_READER(), BLOB_READER::ReadLine(), FILTER_READER::ReadLine(), WHITESPACE_FILTER_READER::ReadLine(), ReadLine(), STRING_LINE_READER::ReadLine(), INPUTSTREAM_LINE_READER::ReadLine(), STDISTREAM_LINE_READER::ReadLine(), STDISTREAM_LINE_READER::STDISTREAM_LINE_READER(), WHITESPACE_FILTER_READER::WHITESPACE_FILTER_READER(), FILTER_READER::~FILTER_READER(), LINE_READER::~LINE_READER(), STDISTREAM_LINE_READER::~STDISTREAM_LINE_READER(), and WHITESPACE_FILTER_READER::~WHITESPACE_FILTER_READER().
|
protectedinherited |
Definition at line 168 of file richio.h.
Referenced by BLOB_READER::BLOB_READER(), FILE_LINE_READER(), BLOB_READER::ReadLine(), ReadLine(), STRING_LINE_READER::ReadLine(), INPUTSTREAM_LINE_READER::ReadLine(), STDISTREAM_LINE_READER::ReadLine(), STDISTREAM_LINE_READER::STDISTREAM_LINE_READER(), and STRING_LINE_READER::STRING_LINE_READER().
|
protectedinherited |
maximum allowed capacity using resizing.
Definition at line 173 of file richio.h.
Referenced by LINE_READER::expandCapacity(), ReadLine(), STRING_LINE_READER::ReadLine(), and INPUTSTREAM_LINE_READER::ReadLine().
|
protectedinherited |
origin of text lines, e.g. filename or "clipboard"
Definition at line 175 of file richio.h.
Referenced by FILE_LINE_READER(), IFSTREAM_LINE_READER::IFSTREAM_LINE_READER(), INPUTSTREAM_LINE_READER::INPUTSTREAM_LINE_READER(), and STRING_LINE_READER::STRING_LINE_READER().