Eclipse SUMO - Simulation of Urban MObility
LineReader.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Retrieves a file linewise and reports the lines to a handler.
17 /****************************************************************************/
18 #ifndef LineReader_h
19 #define LineReader_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <fstream>
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 class LineHandler;
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
51 class LineReader {
52 public:
54  LineReader();
55 
56 
64  LineReader(const std::string& file);
65 
66 
68  ~LineReader();
69 
70 
74  bool hasMore() const;
75 
76 
83  void readAll(LineHandler& lh);
84 
85 
93  bool readLine(LineHandler& lh);
94 
95 
100  std::string readLine();
101 
102 
104  void close();
105 
106 
110  std::string getFileName() const;
111 
112 
120  bool setFile(const std::string& file);
121 
122 
126  unsigned long getPosition();
127 
128 
130  void reinit();
131 
132 
137  void setPos(unsigned long pos);
138 
139 
143  bool good() const;
144 
145 
146 private:
148  std::string myFileName;
149 
151  std::ifstream myStrm;
152 
154  char myBuffer[1024];
155 
157  std::string myStrBuffer;
158 
160  int myRead;
161 
164 
166  int myRread;
167 
168 };
169 
170 
171 #endif
172 
173 /****************************************************************************/
174 
LineReader::myRread
int myRread
Information how many bytes were read by the reader from the file.
Definition: LineReader.h:166
LineReader::reinit
void reinit()
Reinitialises the reading (of the previous file)
Definition: LineReader.cpp:192
LineReader::setFile
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
Definition: LineReader.cpp:178
LineHandler
Interface definition for a class which retrieves lines from a LineHandler.
Definition: LineHandler.h:45
LineReader::myStrm
std::ifstream myStrm
the stream used
Definition: LineReader.h:151
LineReader::setPos
void setPos(unsigned long pos)
Sets the current position within the file to the given value.
Definition: LineReader.cpp:209
LineReader::myAvailable
int myAvailable
Information how many bytes are available within the used file.
Definition: LineReader.h:163
LineReader::readLine
std::string readLine()
Reads a single (the next) line from the file and returns it.
Definition: LineReader.cpp:121
LineReader::myBuffer
char myBuffer[1024]
To override MSVC++-bugs, we use an own getline which uses this buffer.
Definition: LineReader.h:154
LineReader::LineReader
LineReader()
Constructor.
Definition: LineReader.cpp:39
LineReader::getFileName
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:172
UtilExceptions.h
LineReader::myFileName
std::string myFileName
the name of the file to read the contents from
Definition: LineReader.h:148
LineReader::getPosition
unsigned long getPosition()
Returns the current position within the file.
Definition: LineReader.cpp:186
LineReader::myStrBuffer
std::string myStrBuffer
a string-buffer
Definition: LineReader.h:157
LineReader::hasMore
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:53
LineReader
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:51
LineReader::~LineReader
~LineReader()
Destructor.
Definition: LineReader.cpp:49
LineReader::good
bool good() const
Returns the information whether the stream is readable.
Definition: LineReader.cpp:218
config.h
LineReader::close
void close()
Closes the reading.
LineReader::readAll
void readAll(LineHandler &lh)
Reads the whole file linewise, reporting every line to the given LineHandler.
Definition: LineReader.cpp:59
LineReader::myRead
int myRead
Information about how many characters were supplied to the LineHandler.
Definition: LineReader.h:160