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-2012 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 
92  std::istream& getIStream() {
93  return myStream;
94  }
95 
100  std::string read(int numBytes);
101 
102 
107  void putback(char c);
108 
109 
116  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, char& c);
117 
118 
125  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned char& c);
126 
127 
134  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, int& i);
135 
136 
143  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned int& i);
144 
145 
153 
154 
161  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
162 
163 
176  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
177 
178 
191  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
192 
193 
206  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<unsigned int>& v);
207 
208 
221  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<unsigned int> >& v);
222 
223 
231 
232 private:
234 
235 private:
237  std::ifstream myStream;
238 
239  const bool myAmTyped;
240 
242  const bool myEnableValidation;
243 
245  char myBuffer[1000];
246 
247 };
248 
249 
250 #endif
251 
252 /****************************************************************************/
253