KiCad PCB EDA Suite
numEval::FILE_LINE_READER Class Reference

Class FILE_LINE_READER is a LINE_READER that reads from an open file. More...

Inheritance diagram for numEval::FILE_LINE_READER:
numEval::LINE_READER

Public Member Functions

 FILE_LINE_READER (const wxString &aFileName, unsigned aStartingLineNumber=0, unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
 Constructor FILE_LINE_READER takes aFileName and the size of the desired line buffer and opens the file and assumes the obligation to close it. More...
 
 FILE_LINE_READER (FILE *aFile, const wxString &aFileName, bool doOwn=true, unsigned aStartingLineNumber=0, unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
 Constructor FILE_LINE_READER takes an open FILE and the size of the desired line buffer and takes ownership of the open file, i.e. More...
 
 ~FILE_LINE_READER ()
 Destructor may or may not close the open file, depending on doOwn in constructor. More...
 
char * ReadLine () override
 Function ReadLine reads a line of text into the buffer and increments the line number counter. More...
 
void Rewind ()
 Function Rewind rewinds the file and resets the line number back to zero. More...
 
virtual const wxString & GetSource () const
 Function GetSource returns the name of the source of the lines in an abstract sense. More...
 
char * Line () const
 Function Line returns a pointer to the last line that was read in. More...
 
 operator char * () const
 Operator char* is a casting operator that returns a char* pointer to the start of the line buffer. More...
 
virtual unsigned LineNumber () const
 Function Line Number returns the line number of the last line read from this LINE_READER. More...
 
unsigned Length () const
 Function Length returns the number of bytes in the last line read from this LINE_READER. More...
 

Protected Member Functions

void expandCapacity (unsigned aNewsize)
 Function expandCapacity will expand the capacity of line up to maxLineLength but not greater, so be careful about making assumptions of capacity after calling this. More...
 

Protected Attributes

bool m_iOwn
 if I own the file, I'll promise to close it, else not. More...
 
FILE * m_fp
 I may own this file, but might not. More...
 
unsigned m_length
 no. bytes in line before trailing nul. More...
 
unsigned m_lineNum
 
char * m_line
 the read line of UTF8 text More...
 
unsigned m_capacity
 no. bytes allocated for line. More...
 
unsigned m_maxLineLength
 maximum allowed capacity using resizing. More...
 
wxString m_source
 origin of text lines, e.g. filename or "clipboard" More...
 

Detailed Description

Class FILE_LINE_READER is a LINE_READER that reads from an open file.

File must be already open so that this class can exist without any UI policy.

Definition at line 180 of file numeric_evaluator.cpp.

Constructor & Destructor Documentation

numEval::FILE_LINE_READER::FILE_LINE_READER ( const wxString &  aFileName,
unsigned  aStartingLineNumber = 0,
unsigned  aMaxLineLength = LINE_READER_LINE_DEFAULT_MAX 
)

Constructor FILE_LINE_READER takes aFileName and the size of the desired line buffer and opens the file and assumes the obligation to close it.

Parameters
aFileNameis the name of the file to open and to use for error reporting purposes.
aStartingLineNumberis 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.
aMaxLineLengthis the number of bytes to use in the line buffer.
Exceptions
IO_ERRORif aFileName cannot be opened.
numEval::FILE_LINE_READER::FILE_LINE_READER ( FILE *  aFile,
const wxString &  aFileName,
bool  doOwn = true,
unsigned  aStartingLineNumber = 0,
unsigned  aMaxLineLength = LINE_READER_LINE_DEFAULT_MAX 
)

Constructor FILE_LINE_READER takes 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.

Parameters
aFileis an open file.
aFileNameis the name of the file for error reporting purposes.
doOwnif true, means I should close the open file, else not.
aStartingLineNumberis 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.
aMaxLineLengthis the number of bytes to use in the line buffer.
numEval::FILE_LINE_READER::~FILE_LINE_READER ( )

Destructor may or may not close the open file, depending on doOwn in constructor.

Member Function Documentation

void numEval::LINE_READER::expandCapacity ( unsigned  aNewsize)
protectedinherited

Function expandCapacity will expand the capacity of line up to maxLineLength but not greater, so be careful about making assumptions of capacity after calling this.

virtual const wxString& numEval::LINE_READER::GetSource ( ) const
inlinevirtualinherited

Function GetSource 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.

Definition at line 130 of file numeric_evaluator.cpp.

131 {
132  // Feed parser token after token until end of input.
133 
unsigned numEval::LINE_READER::Length ( ) const
inlineinherited

Function Length returns the number of bytes in the last line read from this LINE_READER.

Definition at line 168 of file numeric_evaluator.cpp.

char* numEval::LINE_READER::Line ( ) const
inlineinherited

Function Line returns a pointer to the last line that was read in.

Definition at line 139 of file numeric_evaluator.cpp.

140  {
141  m_parseFinished = true;
142  return true;
virtual unsigned numEval::LINE_READER::LineNumber ( ) const
inlinevirtualinherited

Function Line Number returns the line number of the last line read from this LINE_READER.

Lines start from 1.

Definition at line 159 of file numeric_evaluator.cpp.

163 {
numEval::LINE_READER::operator char * ( ) const
inlineinherited

Operator char* is a casting operator that returns a char* pointer to the start of the line buffer.

Definition at line 149 of file numeric_evaluator.cpp.

151  {
152  // Reset parser by passing zero as token ID, value is ignored.
char* numEval::FILE_LINE_READER::ReadLine ( )
overridevirtual

Function ReadLine reads a line of text into the buffer and increments the line number counter.

If the line is larger than aMaxLineLength passed to the constructor, then an exception is thrown. The line is nul terminated.

Returns
char* - The beginning of the read line, or NULL if EOF.
Exceptions
IO_ERRORwhen a line is too long.

Implements numEval::LINE_READER.

void numEval::FILE_LINE_READER::Rewind ( )
inline

Function Rewind rewinds the file and resets the line number back to zero.

Line number will go to 1 on first ReadLine().

Definition at line 242 of file numeric_evaluator.cpp.

References numEval::NUMERIC_EVALUATOR::m_token, numEval::NUMERIC_EVALUATOR::Metric, and numEval::NUMERIC_EVALUATOR::TokenStat::pos.

242  {
243  m_token.pos += 2;
244  return Unit::Metric;
245  }
246 

Member Data Documentation

unsigned numEval::LINE_READER::m_capacity
protectedinherited

no. bytes allocated for line.

Definition at line 88 of file numeric_evaluator.cpp.

FILE* numEval::FILE_LINE_READER::m_fp
protected

I may own this file, but might not.

Definition at line 185 of file numeric_evaluator.cpp.

bool numEval::FILE_LINE_READER::m_iOwn
protected

if I own the file, I'll promise to close it, else not.

Definition at line 184 of file numeric_evaluator.cpp.

unsigned numEval::LINE_READER::m_length
protectedinherited

no. bytes in line before trailing nul.

Definition at line 84 of file numeric_evaluator.cpp.

char* numEval::LINE_READER::m_line
protectedinherited

the read line of UTF8 text

Definition at line 87 of file numeric_evaluator.cpp.

unsigned numEval::LINE_READER::m_lineNum
protectedinherited

Definition at line 85 of file numeric_evaluator.cpp.

unsigned numEval::LINE_READER::m_maxLineLength
protectedinherited

maximum allowed capacity using resizing.

Definition at line 90 of file numeric_evaluator.cpp.

wxString numEval::LINE_READER::m_source
protectedinherited

origin of text lines, e.g. filename or "clipboard"

Definition at line 92 of file numeric_evaluator.cpp.


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