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.sourceforge.net/
11 // Copyright (C) 2001-2013 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