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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Retrieves a file linewise and reports the lines to a handler.
19 /****************************************************************************/
20 #ifndef LineReader_h
21 #define LineReader_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <fstream>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class LineHandler;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
57 class LineReader {
58 public:
60  LineReader();
61 
62 
70  LineReader(const std::string& file);
71 
72 
74  ~LineReader();
75 
76 
80  bool hasMore() const;
81 
82 
89  void readAll(LineHandler& lh);
90 
91 
99  bool readLine(LineHandler& lh);
100 
101 
106  std::string readLine();
107 
108 
110  void close();
111 
112 
116  std::string getFileName() const;
117 
118 
126  bool setFile(const std::string& file);
127 
128 
132  unsigned long getPosition();
133 
134 
136  void reinit();
137 
138 
143  void setPos(unsigned long pos);
144 
145 
149  bool good() const;
150 
151 
152 private:
154  std::string myFileName;
155 
157  std::ifstream myStrm;
158 
160  char myBuffer[1024];
161 
163  std::string myStrBuffer;
164 
166  int myRead;
167 
170 
172  int myRread;
173 
174 };
175 
176 
177 #endif
178 
179 /****************************************************************************/
180 
std::ifstream myStrm
the stream used
Definition: LineReader.h:157
~LineReader()
Destructor.
Definition: LineReader.cpp:55
unsigned long getPosition()
Returns the current position within the file.
Definition: LineReader.cpp:192
void close()
Closes the reading.
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:178
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:57
bool good() const
Returns the information whether the stream is readable.
Definition: LineReader.cpp:224
char myBuffer[1024]
To override MSVC++-bugs, we use an own getline which uses this buffer.
Definition: LineReader.h:160
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
Definition: LineReader.cpp:184
int myAvailable
Information how many bytes are available within the used file.
Definition: LineReader.h:169
Interface definition for a class which retrieves lines from a LineHandler.
Definition: LineHandler.h:51
void readAll(LineHandler &lh)
Reads the whole file linewise, reporting every line to the given LineHandler.
Definition: LineReader.cpp:65
LineReader()
Constructor.
Definition: LineReader.cpp:45
int myRread
Information how many bytes were read by the reader from the file.
Definition: LineReader.h:172
int myRead
Information about how many characters were supplied to the LineHandler.
Definition: LineReader.h:166
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:59
void reinit()
Reinitialises the reading (of the previous file)
Definition: LineReader.cpp:198
std::string readLine()
Reads a single (the next) line from the file and returns it.
Definition: LineReader.cpp:127
void setPos(unsigned long pos)
Sets the current position within the file to the given value.
Definition: LineReader.cpp:215
std::string myFileName
the name of the file to read the contents from
Definition: LineReader.h:154
std::string myStrBuffer
a string-buffer
Definition: LineReader.h:163