Return to Index

LineReader

A highly configurable line-based reader. It can read directly from a FILE* pointer or a String. It is capable of automatically trimming whitespace, handling line continuation characters, comments, partial comments, and comment exceptions. The reader is configured with the configure(..) method, and the following commands and options:
   LR_SET_TRIM_LINES: (int: 1 or 0)
   LR_SET_WHITESPACE: (char* : string of whitespace delimiters)
   LR_SET_CASE_SENSITIVE: (int: 1 or 0)
   LR_ADD_EOL_CONTINUE: (char* : pattern string)
   LR_ADD_BNL_CONTINUE: (char* : pattern string)
   LR_ADD_COMMENT_START: (char* : string)
   LR_ADD_COMMENT_EXCEPTION: (char* : string)
   LR_ADD_PARTIAL_COMMENT: (int: 1 or 0)
Pattern strings are simply normal strings where a '|' character stands for 0 or more characters of whitespace. Thus, the pattern "*extractelement|+" would match all of the following strings:
   '*extractelement +'
   '*extractelement+'
   '*extractelement      +'
The same pattern format is used for 'beginning-of-next-line' continuations (BNL_CONTINUE) and 'end-of-line' continuations (EOL_CONTINUE).

Comments extend from the beginning of a line to the end of it. By setting the ALLOW_PARTIAL_COMMENTS to true (1), then a comment starting in the middle of a line extending to the end of it will be remove from the input. Otherwise, comments starting in the middle of a line will remain in the return line. If a comment start is also a EOL continuation, and partial line comments are allowed, the characters after the comment start are stripped, but the line will be continued as expected.

Sample code to configure a reader for Cadence Spectre Netlists:

   LineReader reader(file, 2048);

   reader.configure(LR_SET_TRIM_LINES, LR_ARG(1));
   reader.configure(LR_SET_WHITESPACE, LR_ARG(" \t\r"));
   reader.configure(LR_SET_CASE_SENSITIVE, LR_ARG(0));
   reader.configure(LR_ADD_PARTIAL_COMMENT, LR_ARG("//"));
   reader.configure(LR_ADD_COMMENT_START, LR_ARG("//"));
   reader.configure(LR_ADD_COMMENT_START, LR_ARG("*"));
   reader.configure(LR_ADD_COMMENT_EXCEPTION, LR_ARG("*extractelement"));
   reader.configure(LR_ADD_EOL_CONTINUE, LR_ARG("\\"));
   reader.configure(LR_ADD_BNL_CONTINUE, LR_ARG("*extractelement|+"));

   String line;
   while(reader.getLine(line)) {
      ....
   }
   ....


Method Summary:
LineReader::LineReader(FILE* finput, int max_line_length);
LineReader::LineReader(const String& cinput, int max_line_length);
void LineReader::configure(LineReaderSetting type, void* pat);
bool LineReader::getLine(String& line);
int LineReader::linesRead();



LineReader::LineReader
LineReader::LineReader(FILE* finput, int max_line_length);

Constructs a new LineReader object for a FILE.
Parameters:
FILE* finputThe file to read from.
int max_line_lengthThe maximum length of a line in the file.

LineReader::LineReader
LineReader::LineReader(const String& cinput, int max_line_length);

Constructs a new LineReader object for a String.
Parameters:
const String& cinputThe string to read from.
int max_line_lengthThe maximum length of a line in the file.

void LineReader::configure
void LineReader::configure(LineReaderSetting type, void* pat);

Configure the reading options of the line reader. See the class description above for greater detail and examples.
Parameters:
LineReaderSetting typeThe configuration command.
void* patThe configuration parameter. For integer (1/0) values, use the macro LR_ARG(0) or LR_ARG(1).

bool LineReader::getLine
bool LineReader::getLine(String& line);

Read one line from the reader.

Returns: Returns false if the end of the file was reached, otherwise true.
Parameters:
String& lineThe line is assigned to this parameter.

int LineReader::linesRead
int LineReader::linesRead();

Returns the number of lines read so far.


Generated automatically by docgen 0.0.1
© 2003 Aron Dobos