KiCad PCB EDA Suite
WHITESPACE_FILTER_READER Class Reference

Class WHITESPACE_FILTER_READER reads lines of text from another LINE_READER, but only returns non-comment lines and non-blank lines with leading whitespace characters (space and tab) removed from its ReadLine() function. More...

#include <filter_reader.h>

Inheritance diagram for WHITESPACE_FILTER_READER:
LINE_READER

Public Member Functions

 WHITESPACE_FILTER_READER (LINE_READER &aReader)
 Constructor ( LINE_READER& ) does not take ownership over aReader, so will not destroy it. More...
 
 ~WHITESPACE_FILTER_READER ()
 
char * ReadLine () override
 Function ReadLine reads a line of text into the buffer and increments the line number counter. More...
 
const wxString & GetSource () const override
 Function GetSource returns the name of the source of the lines in an abstract sense. More...
 
unsigned LineNumber () const override
 Function Line Number returns the line number of the last line read from this LINE_READER. 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...
 
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 newsize)
 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 length
 no. bytes in line before trailing nul. More...
 
unsigned lineNum
 
char * line
 the read line of UTF8 text More...
 
unsigned capacity
 no. bytes allocated for line. More...
 
unsigned maxLineLength
 maximum allowed capacity using resizing. More...
 
wxString source
 origin of text lines, e.g. filename or "clipboard" More...
 

Private Attributes

LINE_READERreader
 

Detailed Description

Class WHITESPACE_FILTER_READER reads lines of text from another LINE_READER, but only returns non-comment lines and non-blank lines with leading whitespace characters (space and tab) removed from its ReadLine() function.

Definition at line 71 of file filter_reader.h.

Constructor & Destructor Documentation

WHITESPACE_FILTER_READER::WHITESPACE_FILTER_READER ( LINE_READER aReader)

Constructor ( LINE_READER& ) does not take ownership over aReader, so will not destroy it.

Definition at line 69 of file filter_reader.cpp.

References LINE_READER::line.

69  :
70  LINE_READER( 1 ),
71  reader( aReader )
72 {
73  // Not using our own line buffer, will be using aReader's. This changes
74  // the meaning of this->line to be merely a pointer to aReader's line, which of course
75  // is not owned here.
76  delete [] line;
77 
78  line = 0;
79 }
char * line
the read line of UTF8 text
Definition: richio.h:87
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 lengt...
Definition: richio.cpp:103
WHITESPACE_FILTER_READER::~WHITESPACE_FILTER_READER ( )

Definition at line 82 of file filter_reader.cpp.

References LINE_READER::line.

83 {
84  // Our 'line' points to aReader's, and he will delete that buffer.
85  // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own.
86  line = 0;
87 }
char * line
the read line of UTF8 text
Definition: richio.h:87

Member Function Documentation

void LINE_READER::expandCapacity ( unsigned  newsize)
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.

Definition at line 132 of file richio.cpp.

References LINE_READER::capacity, LINE_READER::length, LINE_READER::line, and LINE_READER::maxLineLength.

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

133 {
134  // length can equal maxLineLength and nothing breaks, there's room for
135  // the terminating nul. cannot go over this.
136  if( newsize > maxLineLength+1 )
137  newsize = maxLineLength+1;
138 
139  if( newsize > capacity )
140  {
141  capacity = newsize;
142 
143  // resize the buffer, and copy the original data
144  char* bigger = new char[capacity];
145 
146  wxASSERT( capacity >= length+1 );
147 
148  memcpy( bigger, line, length );
149  bigger[length] = 0;
150 
151  delete[] line;
152  line = bigger;
153  }
154 }
unsigned maxLineLength
maximum allowed capacity using resizing.
Definition: richio.h:90
char * line
the read line of UTF8 text
Definition: richio.h:87
unsigned length
no. bytes in line before trailing nul.
Definition: richio.h:84
unsigned capacity
no. bytes allocated for line.
Definition: richio.h:88
const wxString& WHITESPACE_FILTER_READER::GetSource ( ) const
inlineoverridevirtual

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 from LINE_READER.

Definition at line 87 of file filter_reader.h.

References LINE_READER::GetSource().

88  {
89  return reader.GetSource();
90  }
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
unsigned 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 richio.h.

References LINE_READER::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(), ReadLine(), and DSNLEXER::readLine().

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

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

Definition at line 139 of file richio.h.

References LINE_READER::line.

Referenced by LEGACY_PLUGIN::biuParse(), LEGACY_PLUGIN::checkVersion(), LEGACY_PLUGIN::degParse(), NETLIST_READER::GuessNetlistFileType(), CMP_READER::Load(), SCH_BITMAP::Load(), LIB_PIN::Load(), SCH_SHEET_PIN::Load(), SCH_COMPONENT::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_EDIT_FRAME::LoadOneEEFile(), 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(), LINE_READER::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(), ReadSchemaDescr(), and LP_CACHE::SkipIndex().

140  {
141  return line;
142  }
char * line
the read line of UTF8 text
Definition: richio.h:87
unsigned WHITESPACE_FILTER_READER::LineNumber ( ) const
inlineoverridevirtual

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

Lines start from 1.

Reimplemented from LINE_READER.

Definition at line 92 of file filter_reader.h.

References LINE_READER::LineNumber().

93  {
94  return reader.LineNumber();
95  }
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
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 richio.h.

References LINE_READER::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
char * WHITESPACE_FILTER_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 LINE_READER.

Definition at line 90 of file filter_reader.cpp.

References LINE_READER::length, LINE_READER::Length(), LINE_READER::line, reader, and LINE_READER::ReadLine().

91 {
92  char* s;
93 
94  while( ( s = reader.ReadLine() ) != NULL )
95  {
96  while( s != NULL && strchr( " \t", *s ) )
97  s++;
98 
99  if( s != NULL && !strchr( "#\n\r", *s ) )
100  break;
101  }
102 
103  line = s;
104  length = reader.Length();
105 
106  return length ? line : NULL;
107 }
char * line
the read line of UTF8 text
Definition: richio.h:87
unsigned length
no. bytes in line before trailing nul.
Definition: richio.h:84
unsigned Length() const
Function Length returns the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:168
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter...

Member Data Documentation

unsigned LINE_READER::capacity
protectedinherited
unsigned LINE_READER::length
protectedinherited
unsigned LINE_READER::maxLineLength
protectedinherited

maximum allowed capacity using resizing.

Definition at line 90 of file richio.h.

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

LINE_READER& WHITESPACE_FILTER_READER::reader
private

Definition at line 73 of file filter_reader.h.

Referenced by ReadLine().

wxString LINE_READER::source
protectedinherited

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(), 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: