Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Encapsulates binary reading operations on a file
18 /****************************************************************************/
19 #ifndef BinaryInputDevice_h
20 #define BinaryInputDevice_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <vector>
30 #include <fstream>
31 #include "BinaryFormatter.h"
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class BinaryInputDevice;
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
59 public:
64  BinaryInputDevice(const std::string& name, const bool isTyped = false, const bool doValidate = false);
65 
66 
69 
70 
75  bool good() const;
76 
77 
82  int peek();
83 
84 
90  std::string read(int numBytes);
91 
92 
97  void putback(char c);
98 
99 
106  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, char& c);
107 
108 
115  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned char& c);
116 
117 
124  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, int& i);
125 
126 
133  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, double& f);
134 
135 
142  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
143 
144 
157  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
158 
159 
172  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
173 
174 
187  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<int>& v);
188 
189 
202  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<int> >& v);
203 
204 
212 
213 private:
215 
216 private:
218  std::ifstream myStream;
219 
220  const bool myAmTyped;
221 
223  const bool myEnableValidation;
224 
226  char myBuffer[10000];
227 
228 };
229 
230 
231 #endif
232 
233 /****************************************************************************/
234 
BinaryInputDevice::myBuffer
char myBuffer[10000]
The buffer used for string parsing.
Definition: BinaryInputDevice.h:226
BinaryInputDevice::myAmTyped
const bool myAmTyped
Definition: BinaryInputDevice.h:220
BinaryInputDevice::operator>>
friend BinaryInputDevice & operator>>(BinaryInputDevice &os, char &c)
Reads a char from the file (input operator)
Definition: BinaryInputDevice.cpp:89
BinaryInputDevice::putback
void putback(char c)
Pushes a character back into the stream to be read by the next actual parse.
Definition: BinaryInputDevice.cpp:69
BinaryFormatter::DataType
DataType
data types in binary output
Definition: BinaryFormatter.h:58
BinaryInputDevice::checkType
int checkType(BinaryFormatter::DataType t)
Definition: BinaryInputDevice.cpp:75
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
BinaryInputDevice::~BinaryInputDevice
~BinaryInputDevice()
Destructor.
Definition: BinaryInputDevice.cpp:46
BinaryInputDevice::good
bool good() const
Returns whether the underlying file stream can be used (is good())
Definition: BinaryInputDevice.cpp:50
BinaryInputDevice::myStream
std::ifstream myStream
The encapsulated stream.
Definition: BinaryInputDevice.h:218
BinaryInputDevice::peek
int peek()
Returns the next character to be read by an actual parse.
Definition: BinaryInputDevice.cpp:56
BinaryInputDevice::BinaryInputDevice
BinaryInputDevice(const std::string &name, const bool isTyped=false, const bool doValidate=false)
Constructor.
Definition: BinaryInputDevice.cpp:40
BinaryInputDevice::myEnableValidation
const bool myEnableValidation
Information whether types shall be checked.
Definition: BinaryInputDevice.h:223
config.h
BinaryInputDevice::read
std::string read(int numBytes)
Reads the defined number of bytes and returns them as a string.
Definition: BinaryInputDevice.cpp:62
BinaryFormatter.h
BinaryInputDevice
Encapsulates binary reading operations on a file.
Definition: BinaryInputDevice.h:58