![]() |
SUMO - Simulation of Urban MObility
|
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 | |
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 | 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... | |
std::string | myStrBuffer |
a string-buffer More... | |
std::ifstream | myStrm |
the stream used More... | |
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.
No checks are done so far during reading/setting position etc.
Should not IOError be thrown if something fails?
Definition at line 51 of file LineReader.h.
LineReader::LineReader | ( | ) |
Constructor.
Definition at line 39 of file LineReader.cpp.
LineReader::LineReader | ( | const std::string & | file | ) |
Constructor.
Initialises reading from the file with the given name using setFile.
[in] | file | The name of the file to open |
Definition at line 42 of file LineReader.cpp.
References reinit().
LineReader::~LineReader | ( | ) |
Destructor.
Definition at line 49 of file LineReader.cpp.
void LineReader::close | ( | ) |
Closes the reading.
std::string LineReader::getFileName | ( | ) | const |
Returns the name of the used file.
Definition at line 172 of file LineReader.cpp.
References myFileName.
Referenced by ODMatrix::getNextNonCommentLine(), RODFDetFlowLoader::read(), ODMatrix::readO(), and ODMatrix::readV().
unsigned long LineReader::getPosition | ( | ) |
Returns the current position within the file.
Definition at line 186 of file LineReader.cpp.
References myRread.
Referenced by NIImporter_VISUM::load().
bool LineReader::good | ( | ) | const |
Returns the information whether the stream is readable.
Definition at line 218 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)
Definition at line 53 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
[in] | lh | The LineHandler to report read lines to |
Definition at line 59 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
[in] | lh | The LineHandler to report read lines to |
Definition at line 69 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(), main(), and RODFDetFlowLoader::read().
std::string LineReader::readLine | ( | ) |
Reads a single (the next) line from the file and returns it.
Definition at line 121 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 192 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
[in] | file | The name of the file to open |
Definition at line 178 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.
[in] | pos | The new position within the file |
Definition at line 209 of file LineReader.cpp.
References myRead, myRread, myStrBuffer, and myStrm.
Referenced by NIImporter_VISUM::load().
|
private |
Information how many bytes are available within the used file.
Definition at line 163 of file LineReader.h.
Referenced by hasMore(), readAll(), readLine(), and reinit().
|
private |
To override MSVC++-bugs, we use an own getline which uses this buffer.
Definition at line 154 of file LineReader.h.
Referenced by readLine().
|
private |
the name of the file to read the contents from
Definition at line 148 of file LineReader.h.
Referenced by getFileName(), reinit(), and setFile().
|
private |
Information about how many characters were supplied to the LineHandler.
Definition at line 160 of file LineReader.h.
Referenced by readLine(), reinit(), and setPos().
|
private |
Information how many bytes were read by the reader from the file.
Definition at line 166 of file LineReader.h.
Referenced by getPosition(), hasMore(), readAll(), readLine(), reinit(), and setPos().
|
private |
a string-buffer
Definition at line 157 of file LineReader.h.
Referenced by readLine(), reinit(), and setPos().
|
private |
the stream used
Definition at line 151 of file LineReader.h.
Referenced by good(), readLine(), reinit(), setFile(), and setPos().