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 /****************************************************************************/
15 // Retrieves a file linewise and reports the lines to a handler.
16 /****************************************************************************/
17 #ifndef LineReader_h
18 #define LineReader_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <fstream>
29 
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class LineHandler;
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
50 class LineReader {
51 public:
53  LineReader();
54 
55 
63  LineReader(const std::string& file);
64 
65 
67  ~LineReader();
68 
69 
73  bool hasMore() const;
74 
75 
82  void readAll(LineHandler& lh);
83 
84 
92  bool readLine(LineHandler& lh);
93 
94 
99  std::string readLine();
100 
101 
103  void close();
104 
105 
109  std::string getFileName() const;
110 
111 
119  bool setFile(const std::string& file);
120 
121 
125  unsigned long getPosition();
126 
127 
129  void reinit();
130 
131 
136  void setPos(unsigned long pos);
137 
138 
142  bool good() const;
143 
144 
145 private:
147  std::string myFileName;
148 
150  std::ifstream myStrm;
151 
153  char myBuffer[1024];
154 
156  std::string myStrBuffer;
157 
159  int myRead;
160 
163 
165  int myRread;
166 
167 };
168 
169 
170 #endif
171 
172 /****************************************************************************/
173 
LineReader::myRread
int myRread
Information how many bytes were read by the reader from the file.
Definition: LineReader.h:165
LineReader::reinit
void reinit()
Reinitialises the reading (of the previous file)
Definition: LineReader.cpp:191
LineReader::setFile
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
Definition: LineReader.cpp:177
LineHandler
Interface definition for a class which retrieves lines from a LineHandler.
Definition: LineHandler.h:44
LineReader::myStrm
std::ifstream myStrm
the stream used
Definition: LineReader.h:150
LineReader::setPos
void setPos(unsigned long pos)
Sets the current position within the file to the given value.
Definition: LineReader.cpp:208
LineReader::myAvailable
int myAvailable
Information how many bytes are available within the used file.
Definition: LineReader.h:162
LineReader::readLine
std::string readLine()
Reads a single (the next) line from the file and returns it.
Definition: LineReader.cpp:120
LineReader::myBuffer
char myBuffer[1024]
To override MSVC++-bugs, we use an own getline which uses this buffer.
Definition: LineReader.h:153
LineReader::LineReader
LineReader()
Constructor.
Definition: LineReader.cpp:38
LineReader::getFileName
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:171
UtilExceptions.h
LineReader::myFileName
std::string myFileName
the name of the file to read the contents from
Definition: LineReader.h:147
LineReader::getPosition
unsigned long getPosition()
Returns the current position within the file.
Definition: LineReader.cpp:185
LineReader::myStrBuffer
std::string myStrBuffer
a string-buffer
Definition: LineReader.h:156
LineReader::hasMore
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:52
LineReader
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:50
LineReader::~LineReader
~LineReader()
Destructor.
Definition: LineReader.cpp:48
LineReader::good
bool good() const
Returns the information whether the stream is readable.
Definition: LineReader.cpp:217
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:58
LineReader::myRead
int myRead
Information about how many characters were supplied to the LineHandler.
Definition: LineReader.h:159