Eclipse SUMO - Simulation of Urban MObility
LineReader Class Reference

Retrieves a file linewise and reports the lines to a handler. More...

#include <LineReader.h>

Public Member Functions

void close ()
 Closes the reading. More...
 
std::string getFileName () const
 Returns the name of the used file. More...
 
int getLineNumber ()
 
unsigned long getPosition ()
 Returns the current position within the file. More...
 
bool good () const
 Returns the information whether the stream is readable. More...
 
bool hasMore () const
 Returns whether another line may be read (the file was not read completely) More...
 
 LineReader ()
 Constructor. More...
 
 LineReader (const std::string &file)
 Constructor. More...
 
void readAll (LineHandler &lh)
 Reads the whole file linewise, reporting every line to the given LineHandler. More...
 
std::string readLine ()
 Reads a single (the next) line from the file and returns it. More...
 
bool readLine (LineHandler &lh)
 Reads a single (the next) line from the file and reports it to the given LineHandler. More...
 
void reinit ()
 Reinitialises the reading (of the previous file) More...
 
bool setFile (const std::string &file)
 Reinitialises the reader for reading from the given file. More...
 
void setPos (unsigned long pos)
 Sets the current position within the file to the given value. More...
 
 ~LineReader ()
 Destructor. More...
 

Private Attributes

int myAvailable
 Information how many bytes are available within the used file. More...
 
char myBuffer [1024]
 To override MSVC++-bugs, we use an own getline which uses this buffer. More...
 
std::string myFileName
 the name of the file to read the contents from More...
 
int myLinesRead
 Information how many lines were read for meaningful error messages. More...
 
int myRead
 Information about how many characters were supplied to the LineHandler. More...
 
int myRread
 Information how many bytes were read by the reader from the file. More...
 
int mySkipBOM
 Number of skipped characters at the file begin (UTF-8 BOM) More...
 
std::string myStrBuffer
 a string-buffer More...
 
std::ifstream myStrm
 the stream used More...
 

Detailed Description

Retrieves a file linewise and reports the lines to a handler.

This class reads the contents from a file line by line and report them to a LineHandler-derivate.

See also
LineHandler
Todo:

No checks are done so far during reading/setting position etc.

Should not IOError be thrown if something fails?

Definition at line 48 of file LineReader.h.

Constructor & Destructor Documentation

◆ LineReader() [1/2]

LineReader::LineReader ( )

Constructor.

Definition at line 38 of file LineReader.cpp.

◆ LineReader() [2/2]

LineReader::LineReader ( const std::string &  file)

Constructor.

Initialises reading from the file with the given name using setFile.

Parameters
[in]fileThe name of the file to open
See also
setFile

Definition at line 41 of file LineReader.cpp.

References reinit().

◆ ~LineReader()

LineReader::~LineReader ( )

Destructor.

Definition at line 48 of file LineReader.cpp.

Member Function Documentation

◆ close()

void LineReader::close ( )

Closes the reading.

◆ getFileName()

std::string LineReader::getFileName ( ) const

Returns the name of the used file.

Returns
The name of the opened file

Definition at line 174 of file LineReader.cpp.

References myFileName.

Referenced by ODMatrix::getNextNonCommentLine(), main(), RODFDetFlowLoader::read(), ODMatrix::readO(), and ODMatrix::readV().

Here is the caller graph for this function:

◆ getLineNumber()

int LineReader::getLineNumber ( )
inline

Definition at line 143 of file LineReader.h.

References myLinesRead.

Referenced by NIImporter_VISUM::load(), and RODFDetFlowLoader::read().

Here is the caller graph for this function:

◆ getPosition()

unsigned long LineReader::getPosition ( )

Returns the current position within the file.

Returns
The current position within the opened file

Definition at line 188 of file LineReader.cpp.

References myRread.

Referenced by NIImporter_VISUM::load().

Here is the caller graph for this function:

◆ good()

bool LineReader::good ( ) const

Returns the information whether the stream is readable.

Returns
Whether the file is usable (good())

Definition at line 232 of file LineReader.cpp.

References myStrm.

Referenced by ODMatrix::getNextNonCommentLine(), ODMatrix::loadMatrix(), and main().

Here is the caller graph for this function:

◆ hasMore()

bool LineReader::hasMore ( ) const

Returns whether another line may be read (the file was not read completely)

Returns
Whether further reading is possible

Definition at line 52 of file LineReader.cpp.

References myAvailable, and myRread.

Referenced by ODMatrix::getNextNonCommentLine(), NIImporter_VISUM::load(), PCLoaderVisum::load(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), main(), RODFDetFlowLoader::read(), ODMatrix::readO(), and ODMatrix::readV().

Here is the caller graph for this function:

◆ readAll()

void LineReader::readAll ( LineHandler lh)

Reads the whole file linewise, reporting every line to the given LineHandler.

When the LineHandler returns false, the reading will be aborted

Parameters
[in]lhThe LineHandler to report read lines to

Definition at line 58 of file LineReader.cpp.

References myAvailable, myRread, and readLine().

Referenced by NIImporter_DlrNavteq::loadNetwork().

Here is the caller graph for this function:

◆ readLine() [1/2]

std::string LineReader::readLine ( )

Reads a single (the next) line from the file and returns it.

Returns
The next line in the file

Definition at line 120 of file LineReader.cpp.

References myAvailable, myBuffer, myLinesRead, myRead, myRread, myStrBuffer, and myStrm.

Referenced by readAll().

Here is the caller graph for this function:

◆ readLine() [2/2]

bool LineReader::readLine ( LineHandler lh)

Reads a single (the next) line from the file and reports it to the given LineHandler.

When the LineHandler returns false, the reading will be aborted

Parameters
[in]lhThe LineHandler to report read lines to
Returns
Whether a further line exists

Definition at line 68 of file LineReader.cpp.

References myAvailable, myBuffer, myRead, myRread, myStrBuffer, myStrm, and LineHandler::report().

Referenced by ODMatrix::getNextNonCommentLine(), NIImporter_VISUM::load(), PCLoaderVisum::load(), ODMatrix::loadMatrix(), PCLoaderDlrNavteq::loadPOIFile(), PCLoaderDlrNavteq::loadPolyFile(), main(), and RODFDetFlowLoader::read().

Here is the caller graph for this function:

◆ reinit()

void LineReader::reinit ( )

Reinitialises the reading (of the previous file)

Definition at line 194 of file LineReader.cpp.

References myAvailable, myBuffer, myFileName, myLinesRead, myRead, myRread, mySkipBOM, myStrBuffer, and myStrm.

Referenced by LineReader(), NIImporter_VISUM::load(), PCLoaderVisum::load(), and setFile().

Here is the caller graph for this function:

◆ setFile()

bool LineReader::setFile ( const std::string &  file)

Reinitialises the reader for reading from the given file.

Returns false when the file is not readable

Parameters
[in]fileThe name of the file to open
Returns
Whether the file could be opened

Definition at line 180 of file LineReader.cpp.

References myFileName, myStrm, and reinit().

Referenced by NIImporter_VISUM::load(), and NIImporter_DlrNavteq::loadNetwork().

Here is the caller graph for this function:

◆ setPos()

void LineReader::setPos ( unsigned long  pos)

Sets the current position within the file to the given value.

Parameters
[in]posThe new position within the file

Definition at line 223 of file LineReader.cpp.

References myRead, myRread, mySkipBOM, myStrBuffer, and myStrm.

Referenced by NIImporter_VISUM::load().

Here is the caller graph for this function:

Field Documentation

◆ myAvailable

int LineReader::myAvailable
private

Information how many bytes are available within the used file.

Definition at line 164 of file LineReader.h.

Referenced by hasMore(), readAll(), readLine(), and reinit().

◆ myBuffer

char LineReader::myBuffer[1024]
private

To override MSVC++-bugs, we use an own getline which uses this buffer.

Definition at line 155 of file LineReader.h.

Referenced by readLine(), and reinit().

◆ myFileName

std::string LineReader::myFileName
private

the name of the file to read the contents from

Definition at line 149 of file LineReader.h.

Referenced by getFileName(), reinit(), and setFile().

◆ myLinesRead

int LineReader::myLinesRead
private

Information how many lines were read for meaningful error messages.

Definition at line 170 of file LineReader.h.

Referenced by getLineNumber(), readLine(), and reinit().

◆ myRead

int LineReader::myRead
private

Information about how many characters were supplied to the LineHandler.

Definition at line 161 of file LineReader.h.

Referenced by readLine(), reinit(), and setPos().

◆ myRread

int LineReader::myRread
private

Information how many bytes were read by the reader from the file.

Definition at line 167 of file LineReader.h.

Referenced by getPosition(), hasMore(), readAll(), readLine(), reinit(), and setPos().

◆ mySkipBOM

int LineReader::mySkipBOM
private

Number of skipped characters at the file begin (UTF-8 BOM)

Definition at line 173 of file LineReader.h.

Referenced by reinit(), and setPos().

◆ myStrBuffer

std::string LineReader::myStrBuffer
private

a string-buffer

Definition at line 158 of file LineReader.h.

Referenced by readLine(), reinit(), and setPos().

◆ myStrm

std::ifstream LineReader::myStrm
private

the stream used

Definition at line 152 of file LineReader.h.

Referenced by good(), readLine(), reinit(), setFile(), and setPos().


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