KiCad PCB EDA Suite
LINE_READER Class Referenceabstract

Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to read single lines of text and manage a line number counter. More...

#include <richio.h>

Inheritance diagram for LINE_READER:
FILE_LINE_READER FILTER_READER INPUTSTREAM_LINE_READER STRING_LINE_READER WHITESPACE_FILTER_READER

Public Member Functions

 LINE_READER (unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
 Constructor LINE_READER builds a line reader and fixes the length of the maximum supported line length to aMaxLineLength. More...
 
virtual ~LINE_READER ()
 
virtual char * ReadLine ()=0
 Function ReadLine reads a line of text into the buffer and increments the line number counter. 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

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 LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to read single lines of text and manage a line number counter.

Definition at line 81 of file richio.h.

Constructor & Destructor Documentation

LINE_READER::LINE_READER ( unsigned  aMaxLineLength = LINE_READER_LINE_DEFAULT_MAX)

Constructor LINE_READER builds a line reader and fixes the length of the maximum supported line length to aMaxLineLength.

Definition at line 102 of file richio.cpp.

References LINE_READER_LINE_INITIAL_SIZE, m_capacity, and m_line.

102  :
103  m_length( 0 ), m_lineNum( 0 ), m_line( NULL ),
104  m_capacity( 0 ), m_maxLineLength( aMaxLineLength )
105 {
106  if( aMaxLineLength != 0 )
107  {
108  // start at the INITIAL size, expand as needed up to the MAX size in maxLineLength
110 
111  // but never go above user's aMaxLineLength, and leave space for trailing nul
112  if( m_capacity > aMaxLineLength+1 )
113  m_capacity = aMaxLineLength+1;
114 
115  // Be sure there is room for a null EOL char, so reserve at least capacity+1 bytes
116  // to ensure capacity line lenght and avoid corner cases
117  // Use capacity+5 to cover and corner case
118  m_line = new char[m_capacity+5];
119 
120  m_line[0] = '\0';
121  }
122 }
#define LINE_READER_LINE_INITIAL_SIZE
Definition: richio.h:74
char * m_line
the read line of UTF8 text
Definition: richio.h:87
unsigned m_lineNum
Definition: richio.h:85
unsigned m_capacity
no. bytes allocated for line.
Definition: richio.h:88
unsigned m_length
no. bytes in line before trailing nul.
Definition: richio.h:84
unsigned m_maxLineLength
maximum allowed capacity using resizing.
Definition: richio.h:90
LINE_READER::~LINE_READER ( )
virtual

Definition at line 125 of file richio.cpp.

References m_line.

126 {
127  delete[] m_line;
128 }
char * m_line
the read line of UTF8 text
Definition: richio.h:87

Member Function Documentation

void LINE_READER::expandCapacity ( unsigned  aNewsize)
protected

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.

Definition at line 131 of file richio.cpp.

References m_capacity, m_length, m_line, and m_maxLineLength.

Referenced by FILE_LINE_READER::ReadLine(), STRING_LINE_READER::ReadLine(), and INPUTSTREAM_LINE_READER::ReadLine().

132 {
133  // m_length can equal maxLineLength and nothing breaks, there's room for
134  // the terminating nul. cannot go over this.
135  if( aNewsize > m_maxLineLength+1 )
136  aNewsize = m_maxLineLength+1;
137 
138  if( aNewsize > m_capacity )
139  {
140  m_capacity = aNewsize;
141 
142  // resize the buffer, and copy the original data
143  // Be sure there is room for the null EOL char, so reserve capacity+1 bytes
144  // to ensure capacity line lenght. Use capacity+5 to cover and corner case
145  char* bigger = new char[m_capacity+5];
146 
147  wxASSERT( m_capacity >= m_length+1 );
148 
149  memcpy( bigger, m_line, m_length );
150  bigger[m_length] = 0;
151 
152  delete[] m_line;
153  m_line = bigger;
154  }
155 }
char * m_line
the read line of UTF8 text
Definition: richio.h:87
unsigned m_capacity
no. bytes allocated for line.
Definition: richio.h:88
unsigned m_length
no. bytes in line before trailing nul.
Definition: richio.h:84
unsigned m_maxLineLength
maximum allowed capacity using resizing.
Definition: richio.h:90
virtual const wxString& LINE_READER::GetSource ( ) const
inlinevirtual

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.

Reimplemented in WHITESPACE_FILTER_READER, and FILTER_READER.

Definition at line 130 of file richio.h.

References m_source.

Referenced by LEGACY_PLUGIN::biuParse(), LEGACY_PLUGIN::checkVersion(), DSNLEXER::CurSource(), LEGACY_PLUGIN::degParse(), FILTER_READER::GetSource(), WHITESPACE_FILTER_READER::GetSource(), CMP_READER::Load(), LEGACY_NETLIST_READER::loadComponent(), LEGACY_NETLIST_READER::loadFootprintFilters(), LEGACY_NETLIST_READER::loadNet(), LEGACY_PLUGIN::loadSETUP(), GPCB_FPL_CACHE::parseMODULE(), and KICAD_NETLIST_PARSER::parseNet().

131  {
132  return m_source;
133  }
wxString m_source
origin of text lines, e.g. filename or "clipboard"
Definition: richio.h:92
unsigned LINE_READER::Length ( ) const
inline

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

Definition at line 168 of file richio.h.

References m_length.

Referenced by LIB_FIELD::Load(), LEGACY_NETLIST_READER::loadComponent(), LEGACY_NETLIST_READER::loadFootprintFilters(), LEGACY_NETLIST_READER::loadNet(), KICAD_NETLIST_PARSER::parseNet(), FILTER_READER::ReadLine(), WHITESPACE_FILTER_READER::ReadLine(), and DSNLEXER::readLine().

169  {
170  return m_length;
171  }
unsigned m_length
no. bytes in line before trailing nul.
Definition: richio.h:84
char* LINE_READER::Line ( ) const
inline

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

Definition at line 139 of file richio.h.

References m_line.

Referenced by LEGACY_PLUGIN::biuParse(), LEGACY_PLUGIN::checkVersion(), LEGACY_PLUGIN::degParse(), NETLIST_READER::GuessNetlistFileType(), CMP_READER::Load(), LIB_PIN::Load(), LIB_PART::Load(), SCH_LEGACY_PLUGIN_CACHE::loadAliases(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), SCH_LEGACY_PLUGIN_CACHE::loadBezier(), SCH_LEGACY_PLUGIN::loadBitmap(), SCH_LEGACY_PLUGIN::loadBusEntry(), SCH_LEGACY_PLUGIN_CACHE::loadCircle(), SCH_LEGACY_PLUGIN::loadComponent(), BITMAP_BASE::LoadData(), SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries(), SCH_LEGACY_PLUGIN_CACHE::loadField(), EXCELLON_IMAGE::LoadFile(), SCH_LEGACY_PLUGIN::loadFile(), SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters(), SCH_LEGACY_PLUGIN::loadHeader(), SCH_LEGACY_PLUGIN_CACHE::loadHeader(), SCH_LEGACY_PLUGIN::loadJunction(), LEGACY_PLUGIN::loadMODULE_EDGE(), LEGACY_PLUGIN::loadMODULE_TEXT(), LP_CACHE::LoadModules(), LEGACY_NETLIST_READER::LoadNetlist(), SCH_LEGACY_PLUGIN::loadNoConnect(), SCH_LEGACY_PLUGIN::loadPageSettings(), SCH_LEGACY_PLUGIN_CACHE::loadPart(), SCH_LEGACY_PLUGIN_CACHE::loadPin(), SCH_LEGACY_PLUGIN_CACHE::loadPolyLine(), SCH_LEGACY_PLUGIN_CACHE::loadRectangle(), SCH_LEGACY_PLUGIN::loadText(), SCH_LEGACY_PLUGIN_CACHE::loadText(), LEGACY_PLUGIN::loadTrackList(), SCH_LEGACY_PLUGIN::loadWire(), operator char *(), KICAD_NETLIST_PARSER::parseNet(), GPCB_FPL_CACHE::parseParameters(), DSNLEXER::PopReader(), SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile(), MWAVE_POLYGONAL_SHAPE_DLG::ReadDataShapeDescr(), FILTER_READER::ReadLine(), DSNLEXER::readLine(), and LP_CACHE::SkipIndex().

140  {
141  return m_line;
142  }
char * m_line
the read line of UTF8 text
Definition: richio.h:87
LINE_READER::operator char * ( ) const
inline

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

Definition at line 149 of file richio.h.

References Line().

150  {
151  return Line();
152  }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual char* LINE_READER::ReadLine ( )
pure virtual

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.

Implemented in INPUTSTREAM_LINE_READER, STRING_LINE_READER, FILE_LINE_READER, WHITESPACE_FILTER_READER, and FILTER_READER.

Referenced by LEGACY_PLUGIN::checkVersion(), NETLIST_READER::GuessNetlistFileType(), CMP_READER::Load(), LIB_PART::Load(), BITMAP_BASE::LoadData(), LIB_PART::LoadDrawEntries(), LEGACY_NETLIST_READER::loadFootprintFilters(), LIB_PART::LoadFootprints(), LP_CACHE::LoadModules(), LEGACY_NETLIST_READER::LoadNetlist(), GPCB_FPL_CACHE::parseMODULE(), GPCB_FPL_CACHE::parseParameters(), LP_CACHE::ReadAndVerifyHeader(), FILTER_READER::ReadLine(), WHITESPACE_FILTER_READER::ReadLine(), DSNLEXER::readLine(), and LP_CACHE::SkipIndex().

Member Data Documentation

unsigned LINE_READER::m_capacity
protected

no. bytes allocated for line.

Definition at line 88 of file richio.h.

Referenced by expandCapacity(), LINE_READER(), FILE_LINE_READER::ReadLine(), STRING_LINE_READER::ReadLine(), and INPUTSTREAM_LINE_READER::ReadLine().

unsigned LINE_READER::m_length
protected
unsigned LINE_READER::m_maxLineLength
protected

maximum allowed capacity using resizing.

Definition at line 90 of file richio.h.

Referenced by expandCapacity(), FILE_LINE_READER::ReadLine(), STRING_LINE_READER::ReadLine(), and INPUTSTREAM_LINE_READER::ReadLine().

wxString LINE_READER::m_source
protected

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

Definition at line 92 of file richio.h.

Referenced by FILE_LINE_READER::FILE_LINE_READER(), GetSource(), INPUTSTREAM_LINE_READER::INPUTSTREAM_LINE_READER(), and STRING_LINE_READER::STRING_LINE_READER().


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