![]() |
Eclipse SUMO - Simulation of Urban MObility
|
Encapsulates binary reading operations on a file. More...
#include <BinaryInputDevice.h>
Public Member Functions | |
BinaryInputDevice (const std::string &name, const bool isTyped=false, const bool doValidate=false) | |
Constructor. More... | |
bool | good () const |
Returns whether the underlying file stream can be used (is good()) More... | |
int | peek () |
Returns the next character to be read by an actual parse. More... | |
void | putback (char c) |
Pushes a character back into the stream to be read by the next actual parse. More... | |
std::string | read (int numBytes) |
Reads the defined number of bytes and returns them as a string. More... | |
~BinaryInputDevice () | |
Destructor. More... | |
Private Member Functions | |
int | checkType (BinaryFormatter::DataType t) |
Private Attributes | |
const bool | myAmTyped |
char | myBuffer [10000] |
The buffer used for string parsing. More... | |
const bool | myEnableValidation |
Information whether types shall be checked. More... | |
std::ifstream | myStream |
The encapsulated stream. More... | |
Friends | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, bool &b) |
Reads a bool from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, char &c) |
Reads a char from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, double &f) |
Reads a double from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, int &i) |
Reads an int from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, Position &p) |
Reads a Position from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, std::string &s) |
Reads a string from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, std::vector< int > &v) |
Reads a string vector from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, std::vector< std::string > &v) |
Reads a string vector from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, std::vector< std::vector< int > > &v) |
Reads a string vector from the file (input operator) More... | |
BinaryInputDevice & | operator>> (BinaryInputDevice &os, unsigned char &c) |
Reads an unsigned char from the file (input operator) More... | |
Encapsulates binary reading operations on a file.
This class opens a binary file stream for reading and offers read access functions on it.
Please note that the byte order is undefined. Also the length of each type is not defined on a global scale and may differ across compilers or platforms.
Definition at line 57 of file BinaryInputDevice.h.
BinaryInputDevice::BinaryInputDevice | ( | const std::string & | name, |
const bool | isTyped = false , |
||
const bool | doValidate = false |
||
) |
Constructor.
[in] | name | The name of the file to open for reading |
Definition at line 39 of file BinaryInputDevice.cpp.
BinaryInputDevice::~BinaryInputDevice | ( | ) |
Destructor.
Definition at line 45 of file BinaryInputDevice.cpp.
|
private |
Definition at line 74 of file BinaryInputDevice.cpp.
References myAmTyped, myEnableValidation, and myStream.
Referenced by operator>>().
bool BinaryInputDevice::good | ( | ) | const |
Returns whether the underlying file stream can be used (is good())
Definition at line 49 of file BinaryInputDevice.cpp.
References myStream.
int BinaryInputDevice::peek | ( | ) |
Returns the next character to be read by an actual parse.
Definition at line 55 of file BinaryInputDevice.cpp.
References myStream.
Referenced by SUMOSAXReader::parseNext(), and SUMOSAXAttributesImpl_Binary::SUMOSAXAttributesImpl_Binary().
void BinaryInputDevice::putback | ( | char | c | ) |
Pushes a character back into the stream to be read by the next actual parse.
[in] | c | The char to store in the stream |
Definition at line 68 of file BinaryInputDevice.cpp.
References myStream.
Referenced by SUMOSAXReader::parseNext(), and SUMOSAXAttributesImpl_Binary::SUMOSAXAttributesImpl_Binary().
std::string BinaryInputDevice::read | ( | int | numBytes | ) |
Reads the defined number of bytes and returns them as a string.
[in] | numBytes | The number of bytes to read |
Definition at line 61 of file BinaryInputDevice.cpp.
References myBuffer, and myStream.
Referenced by SUMOSAXReader::parseNext().
|
friend |
Reads a bool from the file (input operator)
[in,out] | os | The BinaryInputDevice to read the bool from |
[in] | i | The bool to store the read value into |
Definition at line 126 of file BinaryInputDevice.cpp.
|
friend |
Reads a char from the file (input operator)
[in,out] | os | The BinaryInputDevice to read the char from |
[in] | c | The char to store the read value into |
Definition at line 88 of file BinaryInputDevice.cpp.
|
friend |
Reads a double from the file (input operator)
[in,out] | os | The BinaryInputDevice to read the double from |
[in] | i | The double to store the read value into |
Definition at line 112 of file BinaryInputDevice.cpp.
|
friend |
Reads an int from the file (input operator)
[in,out] | os | The BinaryInputDevice to read the int from |
[in] | i | The int to store the read value into |
Definition at line 104 of file BinaryInputDevice.cpp.
|
friend |
Reads a Position from the file (input operator)
[in,out] | os | The BinaryInputDevice to read the Position from |
[in] | p | The Position to store the read value into |
Definition at line 197 of file BinaryInputDevice.cpp.
|
friend |
Reads a string from the file (input operator)
Reads the length of the string as an int, first. Reads then the specified number of chars into "myBuffer". Please note that the buffer has a fixed size - longer strings will cause an error.
[in,out] | os | The BinaryInputDevice to read the string from |
[in] | s | The string to store the read value into |
Definition at line 135 of file BinaryInputDevice.cpp.
|
friend |
Reads a string vector from the file (input operator)
Reads the length of the vector as an int, first. Reads then the specified number of strings using the string input operator. Please note that the buffer has a fixed size - longer strings will cause an error.
[in,out] | os | The BinaryInputDevice to read the string from |
[in] | v | The string vector to store the read value into |
Definition at line 167 of file BinaryInputDevice.cpp.
|
friend |
Reads a string vector from the file (input operator)
Reads the length of the vector as an int, first. Reads then the specified number of strings using the string input operator. Please note that the buffer has a fixed size - longer strings will cause an error.
[in,out] | os | The BinaryInputDevice to read the string from |
[in] | v | The string vector to store the read value into |
Definition at line 152 of file BinaryInputDevice.cpp.
|
friend |
Reads a string vector from the file (input operator)
Reads the length of the vector as an int, first. Reads then the specified number of strings using the string input operator. Please note that the buffer has a fixed size - longer strings will cause an error.
[in,out] | os | The BinaryInputDevice to read the string from |
[in] | v | The string vector to store the read value into |
Definition at line 182 of file BinaryInputDevice.cpp.
|
friend |
Reads an unsigned char from the file (input operator)
[in,out] | os | The BinaryInputDevice to read the char from |
[in] | c | The char to store the read value into |
Definition at line 96 of file BinaryInputDevice.cpp.
|
private |
Definition at line 219 of file BinaryInputDevice.h.
Referenced by checkType().
|
private |
The buffer used for string parsing.
Definition at line 225 of file BinaryInputDevice.h.
Referenced by operator>>(), and read().
|
private |
Information whether types shall be checked.
Definition at line 222 of file BinaryInputDevice.h.
Referenced by checkType().
|
private |
The encapsulated stream.
Definition at line 217 of file BinaryInputDevice.h.
Referenced by checkType(), good(), operator>>(), peek(), putback(), and read().