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 /****************************************************************************/
9 // Encapsulates binary reading operations on a file
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2005-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef BinaryInputDevice_h
23 #define BinaryInputDevice_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <fstream>
38 #include "BinaryFormatter.h"
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class BinaryInputDevice;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
66 public:
71  BinaryInputDevice(const std::string& name, const bool isTyped = false, const bool doValidate = false);
72 
73 
76 
77 
82  bool good() const;
83 
84 
89  int peek();
90 
91 
96  std::string read(int numBytes);
97 
98 
103  void putback(char c);
104 
105 
112  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, char& c);
113 
114 
121  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned char& c);
122 
123 
130  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, int& i);
131 
132 
139  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned int& i);
140 
141 
149 
150 
157  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
158 
159 
172  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
173 
174 
187  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
188 
189 
202  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<unsigned int>& v);
203 
204 
217  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<unsigned int> >& v);
218 
219 
227 
228 private:
230 
231 private:
233  std::ifstream myStream;
234 
235  const bool myAmTyped;
236 
238  const bool myEnableValidation;
239 
241  char myBuffer[10000];
242 
243 };
244 
245 
246 #endif
247 
248 /****************************************************************************/
249