SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LineReader.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Retrieves a file linewise and reports the lines to a handler.
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef LineReader_h
22 #define LineReader_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <fstream>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class LineHandler;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
58 class LineReader {
59 public:
61  LineReader();
62 
63 
71  LineReader(const std::string& file);
72 
73 
75  ~LineReader();
76 
77 
81  bool hasMore() const;
82 
83 
90  void readAll(LineHandler& lh);
91 
92 
100  bool readLine(LineHandler& lh);
101 
102 
107  std::string readLine();
108 
109 
111  void close();
112 
113 
117  std::string getFileName() const;
118 
119 
127  bool setFile(const std::string& file);
128 
129 
133  unsigned long getPosition();
134 
135 
137  void reinit();
138 
139 
144  void setPos(unsigned long pos);
145 
146 
150  bool good() const;
151 
152 
153 private:
155  std::string myFileName;
156 
158  std::ifstream myStrm;
159 
161  char myBuffer[1024];
162 
164  std::string myStrBuffer;
165 
167  unsigned int myRead;
168 
170  unsigned int myAvailable;
171 
173  unsigned int myRread;
174 
175 };
176 
177 
178 #endif
179 
180 /****************************************************************************/
181 
std::ifstream myStrm
the stream used
Definition: LineReader.h:158
~LineReader()
Destructor.
Definition: LineReader.cpp:60
unsigned long getPosition()
Returns the current position within the file.
Definition: LineReader.cpp:197
void close()
Closes the reading.
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
unsigned int myRead
Information about how many characters were supplied to the LineHandler.
Definition: LineReader.h:167
char myBuffer[1024]
To override MSVC++-bugs, we use an own getline which uses this buffer.
Definition: LineReader.h:161
unsigned int myAvailable
Information how many bytes are available within the used file.
Definition: LineReader.h:170
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
Definition: LineReader.cpp:189
Interface definition for a class which retrieves lines from a LineHandler.
Definition: LineHandler.h:52
void readAll(LineHandler &lh)
Reads the whole file linewise, reporting every line to the given LineHandler.
Definition: LineReader.cpp:70
LineReader()
Constructor.
Definition: LineReader.cpp:50
unsigned int myRread
Information how many bytes were read by the reader from the file.
Definition: LineReader.h:173
bool good() const
Returns the information whether the stream is readable.
Definition: LineReader.cpp:229
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:183
void reinit()
Reinitialises the reading (of the previous file)
Definition: LineReader.cpp:203
std::string readLine()
Reads a single (the next) line from the file and returns it.
Definition: LineReader.cpp:132
void setPos(unsigned long pos)
Sets the current position within the file to the given value.
Definition: LineReader.cpp:220
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:64
std::string myFileName
the name of the file to read the contents from
Definition: LineReader.h:155
std::string myStrBuffer
a string-buffer
Definition: LineReader.h:164