SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryInputDevice Class Reference

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...
 
std::istream & getIStream ()
 Returns the associated istream. More...
 
bool good () const
 Returns whether the file can be used (is good()) More...
 
int peek ()
 Returns the next character to be read by an actual parse. More...
 
void putback (char c)
 Returns the next character to be read by an actual parse. More...
 
std::string read (int numBytes)
 Returns the next character to be read by an actual parse. More...
 
 ~BinaryInputDevice ()
 Destructor. More...
 

Private Member Functions

int checkType (BinaryFormatter::DataType t)
 

Private Attributes

const bool myAmTyped
 
char myBuffer [1000]
 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

BinaryInputDeviceoperator>> (BinaryInputDevice &os, char &c)
 Reads a char from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, unsigned char &c)
 Reads an unsigned char from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, int &i)
 Reads an int from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, unsigned int &i)
 Reads an unsigned int from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, SUMOReal &f)
 Reads a SUMOReal from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, bool &b)
 Reads a bool from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, std::string &s)
 Reads a string from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, std::vector< std::string > &v)
 Reads a string vector from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, std::vector< unsigned int > &v)
 Reads a string vector from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, std::vector< std::vector< unsigned int > > &v)
 Reads a string vector from the file (input operator) More...
 
BinaryInputDeviceoperator>> (BinaryInputDevice &os, Position &p)
 Reads a Position from the file (input operator) More...
 

Detailed Description

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.

Todo:

Recheck whether this class could be replaced by a "normal InputDevice"

Maybe some kind of a well-defined types should be used (so that they have a well-defined length)

Maybe the byte-order should be defined

Definition at line 64 of file BinaryInputDevice.h.

Constructor & Destructor Documentation

BinaryInputDevice::BinaryInputDevice ( const std::string &  name,
const bool  isTyped = false,
const bool  doValidate = false 
)

Constructor.

Parameters
[in]nameThe name of the file to open for reading

Definition at line 50 of file BinaryInputDevice.cpp.

BinaryInputDevice::~BinaryInputDevice ( )

Destructor.

Definition at line 56 of file BinaryInputDevice.cpp.

Member Function Documentation

int BinaryInputDevice::checkType ( BinaryFormatter::DataType  t)
private

Definition at line 88 of file BinaryInputDevice.cpp.

References myAmTyped, myEnableValidation, and myStream.

Referenced by operator>>().

std::istream& BinaryInputDevice::getIStream ( )
inline

Returns the associated istream.

Definition at line 92 of file BinaryInputDevice.h.

References myStream.

bool BinaryInputDevice::good ( ) const

Returns whether the file can be used (is good())

Returns
Whether the file is good

Definition at line 60 of file BinaryInputDevice.cpp.

References myStream.

int BinaryInputDevice::peek ( )

Returns the next character to be read by an actual parse.

Returns
the next character which will be returned

Definition at line 66 of file BinaryInputDevice.cpp.

References myStream.

Referenced by SUMOSAXReader::parseNext(), and SUMOSAXAttributesImpl_Binary::SUMOSAXAttributesImpl_Binary().

void BinaryInputDevice::putback ( char  c)

Returns the next character to be read by an actual parse.

Returns
the next character which will be returned

Definition at line 82 of file BinaryInputDevice.cpp.

References myStream.

Referenced by SUMOSAXAttributesImpl_Binary::SUMOSAXAttributesImpl_Binary().

std::string BinaryInputDevice::read ( int  numBytes)

Returns the next character to be read by an actual parse.

Returns
the next character which will be returned

Definition at line 72 of file BinaryInputDevice.cpp.

References BUF_MAX, myBuffer, and myStream.

Friends And Related Function Documentation

BinaryInputDevice& operator>> ( BinaryInputDevice os,
char &  c 
)
friend

Reads a char from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the char from
[in]cThe char to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 102 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
unsigned char &  c 
)
friend

Reads an unsigned char from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the char from
[in]cThe char to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 110 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
int i 
)
friend

Reads an int from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the int from
[in]iThe int to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 118 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
unsigned int i 
)
friend

Reads an unsigned int from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the unsigned int from
[in]iThe unsigned int to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 126 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
SUMOReal f 
)
friend

Reads a SUMOReal from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the SUMOReal from
[in]iThe SUMOReal to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 134 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
bool b 
)
friend

Reads a bool from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the bool from
[in]iThe bool to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 148 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
std::string &  s 
)
friend

Reads a string from the file (input operator)

Reads the length of the string as an unsigned 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.

Parameters
[in,out]osThe BinaryInputDevice to read the string from
[in]sThe string to store the read value into
Returns
The used BinaryInputDevice for further processing
Todo:
Use either a buffer with a flexible size or report an error if the buffer is too small!

Definition at line 157 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
std::vector< std::string > &  v 
)
friend

Reads a string vector from the file (input operator)

Reads the length of the vector as an unsigned 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.

Parameters
[in,out]osThe BinaryInputDevice to read the string from
[in]vThe string vector to store the read value into
Returns
The used BinaryInputDevice for further processing
Todo:
Use either a buffer with a flexible size or report an error if the buffer is too small!

Definition at line 171 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
std::vector< unsigned int > &  v 
)
friend

Reads a string vector from the file (input operator)

Reads the length of the vector as an unsigned 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.

Parameters
[in,out]osThe BinaryInputDevice to read the string from
[in]vThe string vector to store the read value into
Returns
The used BinaryInputDevice for further processing
Todo:
Use either a buffer with a flexible size or report an error if the buffer is too small!

Definition at line 186 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
std::vector< std::vector< unsigned int > > &  v 
)
friend

Reads a string vector from the file (input operator)

Reads the length of the vector as an unsigned 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.

Parameters
[in,out]osThe BinaryInputDevice to read the string from
[in]vThe string vector to store the read value into
Returns
The used BinaryInputDevice for further processing
Todo:
Use either a buffer with a flexible size or report an error if the buffer is too small!

Definition at line 201 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
Position p 
)
friend

Reads a Position from the file (input operator)

Parameters
[in,out]osThe BinaryInputDevice to read the Position from
[in]pThe Position to store the read value into
Returns
The used BinaryInputDevice for further processing

Definition at line 216 of file BinaryInputDevice.cpp.

Field Documentation

const bool BinaryInputDevice::myAmTyped
private

Definition at line 239 of file BinaryInputDevice.h.

Referenced by checkType().

char BinaryInputDevice::myBuffer[1000]
private

The buffer used for string parsing.

Definition at line 245 of file BinaryInputDevice.h.

Referenced by operator>>(), and read().

const bool BinaryInputDevice::myEnableValidation
private

Information whether types shall be checked.

Definition at line 242 of file BinaryInputDevice.h.

Referenced by checkType().

std::ifstream BinaryInputDevice::myStream
private

The encapsulated stream.

Definition at line 237 of file BinaryInputDevice.h.

Referenced by checkType(), getIStream(), good(), operator>>(), peek(), putback(), and read().


The documentation for this class was generated from the following files: