SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2005-2016 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 
int peek()
Returns the next character to be read by an actual parse.
void putback(char c)
Returns the next character to be read by an actual parse.
DataType
data types in binary output
bool good() const
Returns whether the file can be used (is good())
~BinaryInputDevice()
Destructor.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
std::ifstream myStream
The encapsulated stream.
#define SUMOReal
Definition: config.h:213
const bool myEnableValidation
Information whether types shall be checked.
char myBuffer[10000]
The buffer used for string parsing.
BinaryInputDevice(const std::string &name, const bool isTyped=false, const bool doValidate=false)
Constructor.
friend BinaryInputDevice & operator>>(BinaryInputDevice &os, char &c)
Reads a char from the file (input operator)
Encapsulates binary reading operations on a file.
int checkType(BinaryFormatter::DataType t)
std::string read(int numBytes)
Returns the next character to be read by an actual parse.