SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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...
 
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...
 
bool readLine (LineHandler &lh)
 Reads a single (the next) line from the file and reports it to the given LineHandler. More...
 
std::string readLine ()
 Reads a single (the next) line from the file and returns it. 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

unsigned 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...
 
unsigned int myRead
 Information about how many characters were supplied to the LineHandler. More...
 
unsigned int myRread
 Information how many bytes were read by the reader from the file. 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 58 of file LineReader.h.

Constructor & Destructor Documentation

LineReader::LineReader ( )

Constructor.

Definition at line 50 of file LineReader.cpp.

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 53 of file LineReader.cpp.

References reinit().

LineReader::~LineReader ( )

Destructor.

Definition at line 60 of file LineReader.cpp.

Member Function Documentation

void LineReader::close ( )

Closes the reading.

std::string LineReader::getFileName ( ) const

Returns the name of the used file.

Returns
The name of the opened file

Definition at line 183 of file LineReader.cpp.

References myFileName.

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

unsigned long LineReader::getPosition ( )

Returns the current position within the file.

Returns
The current position within the opened file

Definition at line 197 of file LineReader.cpp.

References myRread.

Referenced by NIImporter_VISUM::load().

bool LineReader::good ( ) const

Returns the information whether the stream is readable.

Returns
Whether the file is usable (good())

Definition at line 229 of file LineReader.cpp.

References myStrm.

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

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 64 of file LineReader.cpp.

References myAvailable, and myRread.

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

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 70 of file LineReader.cpp.

References myAvailable, myRread, and readLine().

Referenced by NIImporter_DlrNavteq::loadNetwork().

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 80 of file LineReader.cpp.

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

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

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 132 of file LineReader.cpp.

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

Referenced by readAll().

void LineReader::reinit ( )

Reinitialises the reading (of the previous file)

Definition at line 203 of file LineReader.cpp.

References myAvailable, myFileName, myRead, myRread, myStrBuffer, and myStrm.

Referenced by LineReader(), PCLoaderVisum::load(), NIImporter_VISUM::load(), and 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 189 of file LineReader.cpp.

References myFileName, myStrm, and reinit().

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

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 220 of file LineReader.cpp.

References myRead, myRread, myStrBuffer, and myStrm.

Referenced by NIImporter_VISUM::load().

Field Documentation

unsigned int LineReader::myAvailable
private

Information how many bytes are available within the used file.

Definition at line 170 of file LineReader.h.

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

char LineReader::myBuffer[1024]
private

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

Definition at line 161 of file LineReader.h.

Referenced by readLine().

std::string LineReader::myFileName
private

the name of the file to read the contents from

Definition at line 155 of file LineReader.h.

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

unsigned int LineReader::myRead
private

Information about how many characters were supplied to the LineHandler.

Definition at line 167 of file LineReader.h.

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

unsigned int LineReader::myRread
private

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

Definition at line 173 of file LineReader.h.

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

std::string LineReader::myStrBuffer
private

a string-buffer

Definition at line 164 of file LineReader.h.

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

std::ifstream LineReader::myStrm
private

the stream used

Definition at line 158 of file LineReader.h.

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


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