latest version v1.9 - last update 10 Apr 2010 |
Endianness This class is used to read data from a file with a known endianness. More...
#include <ltiIOFunctor.h>
Classes | |
class | defaultEndian |
This class encapsulates the endianness of the processor used. More... | |
class | oppositeEndian |
if file endianness is the opposite as the system endianness More... | |
Public Types | |
enum | eEndianness { LittleEndian, BigEndian } |
Public Member Functions | |
endianness (const eEndianness fileEndianness=LittleEndian) | |
virtual | ~endianness () |
virtual const char * | getTypeName () const |
byte & | read (std::istream &in, byte &data) const |
ubyte & | read (std::istream &in, ubyte &data) const |
int16 & | read (std::istream &in, int16 &data) const |
uint16 & | read (std::istream &in, uint16 &data) const |
int32 & | read (std::istream &in, int32 &data) const |
uint32 & | read (std::istream &in, uint32 &data) const |
const byte & | write (std::ostream &out, const byte &data) const |
const ubyte & | write (std::ostream &out, const ubyte &data) const |
const int16 & | write (std::ostream &out, const int16 &data) const |
const uint16 & | write (std::ostream &out, const uint16 &data) const |
const int32 & | write (std::ostream &out, const int32 &data) const |
const uint32 & | write (std::ostream &out, const uint32 &data) const |
Endianness This class is used to read data from a file with a known endianness.
The problem this class try to solve is following:
Let us assume we have a binary file (and not an ASCII file) with following byte stream:
0x01 0x02 0x03 0x04 ...
and we use following code to read an int (4 bytes integers):
lti::uint32 integer; // hold the values been readed std::istream in("theFile.dat"); // the input stream ... in.read(&integer,4); // reads 4 bytes on "integer"
With a little endian system (for example Intel Pentium), the contents of integer
will be 0x04030201.
With a big endian system (for example Motorola/IBM PowerPC), the contents of integer
will be 0x01020304.
We need a class, which allow us to load data from a file with the correct endiannes!!!
The actual system endianess should be already defined:
eEndianness which sort of endianness uses the file
LittleEndian |
the file uses little endianness |
BigEndian |
the file uses big endianness |
lti::endianness::endianness | ( | const eEndianness | fileEndianness = LittleEndian |
) |
default constructor
fileEndianness | specify which endianness uses the file stream |
virtual lti::endianness::~endianness | ( | ) | [virtual] |
destructor
virtual const char* lti::endianness::getTypeName | ( | ) | const [virtual] |
returns the name of this class ("endianness")
Reimplemented from lti::object.
read a uint32
in | input stream | |
data | variable where the data should be stored |
read a int32
in | input stream | |
data | variable where the data should be stored |
read a uint16 (2 bytes)
in | input stream | |
data | variable where the data should be stored |
read a int16 (2 bytes)
in | input stream | |
data | variable where the data should be stored |
read an unsigned byte from the stream
in | input stream | |
data | variable where the data should be stored |
read a byte from the stream
in | input stream | |
data | variable where the data should be stored |
write a uint32
out | output stream | |
data | variable with the data to be stored on the file |
write a int32
out | output stream | |
data | variable with the data to be stored on the file |
write a uint16 (2 bytes)
out | output stream | |
data | variable with the data to be stored on the file |
write a int16 (2 bytes)
out | output stream | |
data | variable with the data to be stored on the file |
write a ubyte
out | output stream | |
data | variable with the data to be stored on the file |
write a byte
out | output stream | |
data | variable with the data to be stored on the file |