SUMO - Simulation of Urban MObility
BinaryInputDevice.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Encapsulates binary reading operations on a file
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 
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, double& f);
140 
141 
148  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
149 
150 
163  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
164 
165 
178  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
179 
180 
193  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<int>& v);
194 
195 
208  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<int> >& v);
209 
210 
218 
219 private:
221 
222 private:
224  std::ifstream myStream;
225 
226  const bool myAmTyped;
227 
229  const bool myEnableValidation;
230 
232  char myBuffer[10000];
233 
234 };
235 
236 
237 #endif
238 
239 /****************************************************************************/
240 
int peek()
Returns the next character to be read by an actual parse.
void putback(char c)
Pushes a character back into the stream to be read by the next actual parse.
DataType
data types in binary output
~BinaryInputDevice()
Destructor.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
std::ifstream myStream
The encapsulated stream.
bool good() const
Returns whether the underlying file stream can be used (is good())
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)
Reads the defined number of bytes and returns them as a string.