SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.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 
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)
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:214
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.