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-2017 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 
97  std::string read(int numBytes);
98 
99 
104  void putback(char c);
105 
106 
113  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, char& c);
114 
115 
122  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned char& c);
123 
124 
131  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, int& i);
132 
133 
140  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, double& f);
141 
142 
149  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
150 
151 
164  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
165 
166 
179  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
180 
181 
194  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<int>& v);
195 
196 
209  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<int> >& v);
210 
211 
219 
220 private:
222 
223 private:
225  std::ifstream myStream;
226 
227  const bool myAmTyped;
228 
230  const bool myEnableValidation;
231 
233  char myBuffer[10000];
234 
235 };
236 
237 
238 #endif
239 
240 /****************************************************************************/
241 
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:46
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.