SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryInputDevice.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Encapsulates binary reading operations on a file
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 BinaryInputDevice_h
22 #define BinaryInputDevice_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 <vector>
36 #include <fstream>
37 #include "BinaryFormatter.h"
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class BinaryInputDevice;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
65 public:
70  BinaryInputDevice(const std::string& name, const bool isTyped = false, const bool doValidate = false);
71 
72 
75 
76 
81  bool good() const;
82 
83 
88  int peek();
89 
90 
95  std::string read(int numBytes);
96 
97 
102  void putback(char c);
103 
104 
111  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, char& c);
112 
113 
120  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned char& c);
121 
122 
129  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, int& i);
130 
131 
138  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned int& i);
139 
140 
148 
149 
156  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
157 
158 
171  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
172 
173 
186  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
187 
188 
201  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<unsigned int>& v);
202 
203 
216  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<unsigned int> >& v);
217 
218 
226 
227 private:
229 
230 private:
232  std::ifstream myStream;
233 
234  const bool myAmTyped;
235 
237  const bool myEnableValidation;
238 
240  char myBuffer[10000];
241 
242 };
243 
244 
245 #endif
246 
247 /****************************************************************************/
248