CVR-Lib last update 20 Sep 2009

cvr::endianness< E > Class Template Reference

Endianness. More...

#include <cvrEndianness.h>

List of all members.

Public Member Functions

 endianness ()
 ~endianness ()

Static Public Member Functions

static bool read (std::istream &in, byte &data)
static bool read (std::istream &in, ubyte &data)
static bool read (std::istream &in, int16 &data)
static bool read (std::istream &in, uint16 &data)
static bool read (std::istream &in, int32 &data)
static bool read (std::istream &in, uint32 &data)
static bool write (std::ostream &out, const byte &data)
static bool write (std::ostream &out, const ubyte &data)
static bool write (std::ostream &out, const int16 &data)
static bool write (std::ostream &out, const uint16 &data)
static bool write (std::ostream &out, const int32 &data)
static bool write (std::ostream &out, const uint32 &data)


Detailed Description

template<eEndiannessType E>
class cvr::endianness< E >

Endianness.

This template class is used to read from or write data to a file that was created with a known endianness. For example, Windows BMP image files have a header with some integers written with little endianness.

To be more specific, the problem this class tries to solve is the 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 32 bit integer (i.e. 4 bytes long):

   cvr::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 therefore need a class, which allow us to load data from a file with the correct endiannes!

The detection of the system endianness will be done at configuration time of the library.:

Template behaviour.

The class cvr::endianness is a template class of an enumerate that can be LittleEndian or BigEndian, defined in the lti namespace.

cvr::endianness<cvr::LittleEndian> cvr::endianness<cvr::BigEndian>

You can check for the endianness used as default by your system with systemEndianness().

Please note that all methods are static, so that you don't need an instance of the class to use them.


Constructor & Destructor Documentation

template<eEndiannessType E>
cvr::endianness< E >::endianness (  ) 

Default constructor.

template<eEndiannessType E>
cvr::endianness< E >::~endianness (  ) 

Destructor.


Member Function Documentation

template<eEndiannessType E>
static bool cvr::endianness< E >::read ( std::istream &  in,
uint32 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::read ( std::istream &  in,
int32 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::read ( std::istream &  in,
uint16 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::read ( std::istream &  in,
int16 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::read ( std::istream &  in,
ubyte data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::read ( std::istream &  in,
byte data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::write ( std::ostream &  out,
const uint32 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::write ( std::ostream &  out,
const int32 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::write ( std::ostream &  out,
const uint16 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::write ( std::ostream &  out,
const int16 data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::write ( std::ostream &  out,
const ubyte data 
) [static]

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

template<eEndiannessType E>
static bool cvr::endianness< E >::write ( std::ostream &  out,
const byte data 
) [static]

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 Sun Sep 20 22:08:53 2009 for CVR-Lib by Doxygen 1.5.8