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 /****************************************************************************/
16 // Encapsulates binary reading operations on a file
17 /****************************************************************************/
18 #ifndef BinaryInputDevice_h
19 #define BinaryInputDevice_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <vector>
29 #include <fstream>
30 #include "BinaryFormatter.h"
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class BinaryInputDevice;
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
58 public:
63  BinaryInputDevice(const std::string& name, const bool isTyped = false, const bool doValidate = false);
64 
65 
68 
69 
74  bool good() const;
75 
76 
81  int peek();
82 
83 
89  std::string read(int numBytes);
90 
91 
96  void putback(char c);
97 
98 
105  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, char& c);
106 
107 
114  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, unsigned char& c);
115 
116 
123  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, int& i);
124 
125 
132  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, double& f);
133 
134 
141  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, bool& b);
142 
143 
156  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::string& s);
157 
158 
171  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<std::string>& v);
172 
173 
186  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector<int>& v);
187 
188 
201  friend BinaryInputDevice& operator>>(BinaryInputDevice& os, std::vector< std::vector<int> >& v);
202 
203 
211 
212 private:
214 
215 private:
217  std::ifstream myStream;
218 
219  const bool myAmTyped;
220 
222  const bool myEnableValidation;
223 
225  char myBuffer[10000];
226 
227 };
228 
229 
230 #endif
231 
232 /****************************************************************************/
233 
BinaryInputDevice::myBuffer
char myBuffer[10000]
The buffer used for string parsing.
Definition: BinaryInputDevice.h:225
BinaryInputDevice::myAmTyped
const bool myAmTyped
Definition: BinaryInputDevice.h:219
BinaryInputDevice::operator>>
friend BinaryInputDevice & operator>>(BinaryInputDevice &os, char &c)
Reads a char from the file (input operator)
Definition: BinaryInputDevice.cpp:88
BinaryInputDevice::putback
void putback(char c)
Pushes a character back into the stream to be read by the next actual parse.
Definition: BinaryInputDevice.cpp:68
BinaryFormatter::DataType
DataType
data types in binary output
Definition: BinaryFormatter.h:57
BinaryInputDevice::checkType
int checkType(BinaryFormatter::DataType t)
Definition: BinaryInputDevice.cpp:74
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
BinaryInputDevice::~BinaryInputDevice
~BinaryInputDevice()
Destructor.
Definition: BinaryInputDevice.cpp:45
BinaryInputDevice::good
bool good() const
Returns whether the underlying file stream can be used (is good())
Definition: BinaryInputDevice.cpp:49
BinaryInputDevice::myStream
std::ifstream myStream
The encapsulated stream.
Definition: BinaryInputDevice.h:217
BinaryInputDevice::peek
int peek()
Returns the next character to be read by an actual parse.
Definition: BinaryInputDevice.cpp:55
BinaryInputDevice::BinaryInputDevice
BinaryInputDevice(const std::string &name, const bool isTyped=false, const bool doValidate=false)
Constructor.
Definition: BinaryInputDevice.cpp:39
BinaryInputDevice::myEnableValidation
const bool myEnableValidation
Information whether types shall be checked.
Definition: BinaryInputDevice.h:222
config.h
BinaryInputDevice::read
std::string read(int numBytes)
Reads the defined number of bytes and returns them as a string.
Definition: BinaryInputDevice.cpp:61
BinaryFormatter.h
BinaryInputDevice
Encapsulates binary reading operations on a file.
Definition: BinaryInputDevice.h:57