#include <BinaryInputDevice.h>
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 54 of file BinaryInputDevice.h.
Public Member Functions | |
| BinaryInputDevice (const std::string &name) throw () | |
| Constructor. | |
| bool | good () const throw () |
| Returns whether the file can be used (is good()). | |
| ~BinaryInputDevice () throw () | |
| Destructor. | |
Private Attributes | |
| char | myBuffer [1000] |
| The buffer used for string parsing. | |
| std::ifstream | myStream |
| The encapsulated stream. | |
Friends | |
| BinaryInputDevice & | operator>> (BinaryInputDevice &os, long &l) throw () |
| Reads a long from the file (input operator). | |
| BinaryInputDevice & | operator>> (BinaryInputDevice &os, std::string &s) throw () |
| Reads a string from the file (input operator). | |
| BinaryInputDevice & | operator>> (BinaryInputDevice &os, bool &b) throw () |
| Reads a bool from the file (input operator). | |
| BinaryInputDevice & | operator>> (BinaryInputDevice &os, SUMOReal &f) throw () |
| Reads a SUMOReal from the file (input operator). | |
| BinaryInputDevice & | operator>> (BinaryInputDevice &os, unsigned int &i) throw () |
| Reads an unsigned int from the file (input operator). | |
| BinaryInputDevice & | operator>> (BinaryInputDevice &os, int &i) throw () |
| Reads an int from the file (input operator). | |
| BinaryInputDevice::BinaryInputDevice | ( | const std::string & | name | ) | throw () |
Constructor.
| [in] | name | The name of the file to open for reading |
Definition at line 46 of file BinaryInputDevice.cpp.
00047 : myStream(name.c_str(), std::fstream::in|std::fstream::binary) {}
| BinaryInputDevice::~BinaryInputDevice | ( | ) | throw () |
| bool BinaryInputDevice::good | ( | ) | const throw () |
Returns whether the file can be used (is good()).
Definition at line 54 of file BinaryInputDevice.cpp.
References myStream.
00054 { 00055 return myStream.good(); 00056 }
| BinaryInputDevice& operator>> | ( | BinaryInputDevice & | os, | |
| long & | l | |||
| ) | throw () [friend] |
Reads a long from the file (input operator).
| [in,out] | os | The BinaryInputDevice to read the long from |
| [in] | i | The int to store the read value into |
Definition at line 103 of file BinaryInputDevice.cpp.
00103 { 00104 os.myStream.read((char*) &l, sizeof(long)); 00105 return os; 00106 }
| BinaryInputDevice& operator>> | ( | BinaryInputDevice & | os, | |
| std::string & | s | |||
| ) | throw () [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.
| [in,out] | os | The BinaryInputDevice to read the string from |
| [in] | i | The string to store the read value into |
Definition at line 89 of file BinaryInputDevice.cpp.
00089 { 00090 unsigned int size; 00091 os >> size; 00092 if (size<BUF_MAX) { 00093 os.myStream.read((char*) &os.myBuffer, sizeof(char)*size); 00094 os.myBuffer[size] = 0; 00095 s = std::string(os.myBuffer); 00096 return os; 00097 } 00098 return os; 00099 }
| BinaryInputDevice& operator>> | ( | BinaryInputDevice & | os, | |
| bool & | b | |||
| ) | throw () [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 81 of file BinaryInputDevice.cpp.
00081 { 00082 b = 0; 00083 os.myStream.read((char*) &b, sizeof(char)); 00084 return os; 00085 }
| BinaryInputDevice& operator>> | ( | BinaryInputDevice & | os, | |
| SUMOReal & | f | |||
| ) | throw () [friend] |
Reads a SUMOReal from the file (input operator).
| [in,out] | os | The BinaryInputDevice to read the SUMOReal from |
| [in] | i | The SUMOReal to store the read value into |
Definition at line 74 of file BinaryInputDevice.cpp.
| BinaryInputDevice& operator>> | ( | BinaryInputDevice & | os, | |
| unsigned int & | i | |||
| ) | throw () [friend] |
Reads an unsigned int from the file (input operator).
| [in,out] | os | The BinaryInputDevice to read the unsigned int from |
| [in] | i | The unsigned int to store the read value into |
Definition at line 67 of file BinaryInputDevice.cpp.
00067 { 00068 os.myStream.read((char*) &i, sizeof(unsigned int)); 00069 return os; 00070 }
| BinaryInputDevice& operator>> | ( | BinaryInputDevice & | os, | |
| int & | i | |||
| ) | throw () [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 60 of file BinaryInputDevice.cpp.
00060 { 00061 os.myStream.read((char*) &i, sizeof(int)); 00062 return os; 00063 }
char BinaryInputDevice::myBuffer[1000] [private] |
std::ifstream BinaryInputDevice::myStream [private] |
The encapsulated stream.
Definition at line 136 of file BinaryInputDevice.h.
Referenced by good(), and operator>>().
1.5.6