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)
 Constructor.
bool good () const
 Returns whether the file can be used (is good())
 ~BinaryInputDevice ()
 Destructor.

Private Attributes

char myBuffer [1000]
 The buffer used for string parsing.
std::ifstream myStream
 The encapsulated stream.

Friends

BinaryInputDeviceoperator>> (BinaryInputDevice &os, int &i)
 Reads an int from the file (input operator)
BinaryInputDeviceoperator>> (BinaryInputDevice &os, unsigned int &i)
 Reads an unsigned int from the file (input operator)
BinaryInputDeviceoperator>> (BinaryInputDevice &os, SUMOReal &f)
 Reads a SUMOReal from the file (input operator)
BinaryInputDeviceoperator>> (BinaryInputDevice &os, bool &b)
 Reads a bool from the file (input operator)
BinaryInputDeviceoperator>> (BinaryInputDevice &os, std::string &s)
 Reads a string from the file (input operator)
BinaryInputDeviceoperator>> (BinaryInputDevice &os, long &l)
 Reads a long from the file (input operator)

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 56 of file BinaryInputDevice.h.


Constructor & Destructor Documentation

BinaryInputDevice::BinaryInputDevice ( const std::string &  name)

Constructor.

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

Definition at line 48 of file BinaryInputDevice.cpp.

BinaryInputDevice::~BinaryInputDevice ( )

Destructor.

Definition at line 52 of file BinaryInputDevice.cpp.


Member Function Documentation

bool BinaryInputDevice::good ( ) const

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

Returns:
Whether the file is good

Definition at line 56 of file BinaryInputDevice.cpp.

References myStream.


Friends And Related Function Documentation

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 62 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 69 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 76 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 83 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]iThe 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 91 of file BinaryInputDevice.cpp.

BinaryInputDevice& operator>> ( BinaryInputDevice os,
long l 
)
friend

Reads a long from the file (input operator)

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

Definition at line 105 of file BinaryInputDevice.cpp.


Field Documentation

char BinaryInputDevice::myBuffer[1000]
private

The buffer used for string parsing.

Definition at line 141 of file BinaryInputDevice.h.

Referenced by operator>>().

std::ifstream BinaryInputDevice::myStream
private

The encapsulated stream.

Definition at line 138 of file BinaryInputDevice.h.

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


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