LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::endianness Class Reference

Endianness This class is used to read data from a file with a known endianness. More...

#include <ltiIOFunctor.h>

Inheritance diagram for lti::endianness:
Inheritance graph
[legend]
Collaboration diagram for lti::endianness:
Collaboration graph
[legend]

List of all members.

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
byteread (std::istream &in, byte &data) const
ubyteread (std::istream &in, ubyte &data) const
int16read (std::istream &in, int16 &data) const
uint16read (std::istream &in, uint16 &data) const
int32read (std::istream &in, int32 &data) const
uint32read (std::istream &in, uint32 &data) const
const bytewrite (std::ostream &out, const byte &data) const
const ubytewrite (std::ostream &out, const ubyte &data) const
const int16write (std::ostream &out, const int16 &data) const
const uint16write (std::ostream &out, const uint16 &data) const
const int32write (std::ostream &out, const int32 &data) const
const uint32write (std::ostream &out, const uint32 &data) const

Detailed Description

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:


Member Enumeration Documentation

eEndianness which sort of endianness uses the file

Enumerator:
LittleEndian 

the file uses little endianness

BigEndian 

the file uses big endianness


Constructor & Destructor Documentation

lti::endianness::endianness ( const eEndianness  fileEndianness = LittleEndian  ) 

default constructor

Parameters:
fileEndianness specify which endianness uses the file stream
virtual lti::endianness::~endianness (  )  [virtual]

destructor


Member Function Documentation

virtual const char* lti::endianness::getTypeName (  )  const [virtual]

returns the name of this class ("endianness")

Reimplemented from lti::object.

uint32& lti::endianness::read ( std::istream &  in,
uint32 data 
) const

read a uint32

Parameters:
in input stream
data variable where the data should be stored
Returns:
a reference to the variable with the readed data
int32& lti::endianness::read ( std::istream &  in,
int32 data 
) const

read a int32

Parameters:
in input stream
data variable where the data should be stored
Returns:
a reference to the variable with the readed data
uint16& lti::endianness::read ( std::istream &  in,
uint16 data 
) const

read a uint16 (2 bytes)

Parameters:
in input stream
data variable where the data should be stored
Returns:
a reference to the variable with the readed data
int16& lti::endianness::read ( std::istream &  in,
int16 data 
) const

read a int16 (2 bytes)

Parameters:
in input stream
data variable where the data should be stored
Returns:
a reference to the variable with the readed data
ubyte& lti::endianness::read ( std::istream &  in,
ubyte data 
) const

read an unsigned byte from the stream

Parameters:
in input stream
data variable where the data should be stored
Returns:
a reference to the variable with the readed data
byte& lti::endianness::read ( std::istream &  in,
byte data 
) const

read a byte from the stream

Parameters:
in input stream
data variable where the data should be stored
Returns:
a reference to the variable with the readed data
const uint32& lti::endianness::write ( std::ostream &  out,
const uint32 data 
) const

write a uint32

Parameters:
out output stream
data variable with the data to be stored on the file
Returns:
a reference to the variable with the data
const int32& lti::endianness::write ( std::ostream &  out,
const int32 data 
) const

write a int32

Parameters:
out output stream
data variable with the data to be stored on the file
Returns:
a reference to the variable with the data
const uint16& lti::endianness::write ( std::ostream &  out,
const uint16 data 
) const

write a uint16 (2 bytes)

Parameters:
out output stream
data variable with the data to be stored on the file
Returns:
a reference to the variable with the data
const int16& lti::endianness::write ( std::ostream &  out,
const int16 data 
) const

write a int16 (2 bytes)

Parameters:
out output stream
data variable with the data to be stored on the file
Returns:
a reference to the variable with the data
const ubyte& lti::endianness::write ( std::ostream &  out,
const ubyte data 
) const

write a ubyte

Parameters:
out output stream
data variable with the data to be stored on the file
Returns:
a reference to the variable with the data
const byte& lti::endianness::write ( std::ostream &  out,
const byte data 
) const

write a byte

Parameters:
out output stream
data variable with the data to be stored on the file
Returns:
a reference to the variable with the data

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

Generated on Sat Apr 10 15:28:02 2010 for LTI-Lib by Doxygen 1.6.1