![]() |
Eclipse 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. | |
| std::string | getFileName () const |
| Returns the name of the used file. | |
| int | getLineNumber () |
| unsigned long | getPosition () |
| Returns the current position within the file. | |
| bool | good () const |
| Returns the information whether the stream is readable. | |
| bool | hasMore () const |
| Returns whether another line may be read (the file was not read completely) | |
| LineReader () | |
| Constructor. | |
| LineReader (const std::string &file) | |
| Constructor. | |
| void | readAll (LineHandler &lh) |
| Reads the whole file linewise, reporting every line to the given LineHandler. | |
| std::string | readLine () |
| Reads a single (the next) line from the file and returns it. | |
| bool | readLine (LineHandler &lh) |
| Reads a single (the next) line from the file and reports it to the given LineHandler. | |
| void | reinit () |
| Reinitialises the reading (of the previous file) | |
| bool | setFile (const std::string &file) |
| Reinitialises the reader for reading from the given file. | |
| void | setPos (unsigned long pos) |
| Sets the current position within the file to the given value. | |
| ~LineReader () | |
| Destructor. | |
Private Attributes | |
| int | myAvailable |
| Information how many bytes are available within the used file. | |
| char | myBuffer [1024] |
| To override MSVC++-bugs, we use an own getline which uses this buffer. | |
| std::string | myFileName |
| the name of the file to read the contents from | |
| int | myLinesRead |
| Information how many lines were read for meaningful error messages. | |
| int | myRead |
| Information about how many characters were supplied to the LineHandler. | |
| int | myRread |
| Information how many bytes were read by the reader from the file. | |
| int | mySkipBOM |
| Number of skipped characters at the file begin (UTF-8 BOM) | |
| std::string | myStrBuffer |
| a string-buffer | |
| std::ifstream | myStrm |
| the stream used | |
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 48 of file LineReader.h.
| LineReader::LineReader | ( | ) |
Constructor.
Definition at line 38 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 41 of file LineReader.cpp.
References reinit().
| LineReader::~LineReader | ( | ) |
Destructor.
Definition at line 48 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 174 of file LineReader.cpp.
References myFileName.
Referenced by ODMatrix::getNextNonCommentLine(), main(), RODFDetFlowLoader::read(), ODMatrix::readO(), and ODMatrix::readV().
|
inline |
Definition at line 143 of file LineReader.h.
References myLinesRead.
Referenced by NIImporter_VISUM::load(), and RODFDetFlowLoader::read().
| unsigned long LineReader::getPosition | ( | ) |
Returns the current position within the file.
Definition at line 188 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 232 of file LineReader.cpp.
References myStrm.
Referenced by ODMatrix::getNextNonCommentLine(), ODMatrix::loadMatrix(), and main().
| bool LineReader::hasMore | ( | ) | const |
Returns whether another line may be read (the file was not read completely)
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().
| 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 58 of file LineReader.cpp.
References myAvailable, myRread, and readLine().
Referenced by NIImporter_DlrNavteq::loadNetwork().
| std::string LineReader::readLine | ( | ) |
Reads a single (the next) line from the file and returns it.
Definition at line 120 of file LineReader.cpp.
References myAvailable, myBuffer, myLinesRead, myRead, myRread, myStrBuffer, and myStrm.
Referenced by readAll().
| 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 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().
| 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().
| 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 180 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 223 of file LineReader.cpp.
References myRead, myRread, mySkipBOM, myStrBuffer, and myStrm.
Referenced by NIImporter_VISUM::load().
|
private |
Information how many bytes are available within the used file.
Definition at line 164 of file LineReader.h.
Referenced by hasMore(), readAll(), readLine(), readLine(), and reinit().
|
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(), readLine(), and reinit().
|
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().
|
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().
|
private |
Information about how many characters were supplied to the LineHandler.
Definition at line 161 of file LineReader.h.
Referenced by readLine(), readLine(), reinit(), and setPos().
|
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(), readLine(), reinit(), and setPos().
|
private |
Number of skipped characters at the file begin (UTF-8 BOM)
Definition at line 173 of file LineReader.h.
|
private |
a string-buffer
Definition at line 158 of file LineReader.h.
Referenced by readLine(), readLine(), reinit(), and setPos().
|
private |
the stream used
Definition at line 152 of file LineReader.h.
Referenced by good(), readLine(), readLine(), reinit(), setFile(), and setPos().