Endian Class Reference

A class to perform byte-swapping operations. More...

#include <Endian.h>

List of all members.

Public Member Functions

 Endian (EndianType endian)
 Endian ()
 ~Endian ()
EndianType getEndian () const
bool isBigEndian () const
bool isLittleEndian () const
template<class T>
bool swapValue (T &value) const
template<class T>
swapValue (const T &value) const
template<class T>
bool swapBuffer (T *pBuffer, size_t count) const
bool swapBuffer (FloatComplex *pBuffer, size_t count) const
bool swapBuffer (IntegerComplex *pBuffer, size_t count) const
bool swapBuffer (void *pBuffer, size_t dataSize, size_t count) const

Static Public Member Functions

static EndianType getSystemEndian ()


Detailed Description

A class to perform byte-swapping operations.

The Endian class provides a capability to perform byte-swapping of data values based on the endian type of the system. An Endian object should be created with the target endian type. The swapping methods can then be called to swap data values to the target type. If the target type is the same as the system, no swapping is performed.

See also:
EndianType

Definition at line 27 of file Endian.h.


Constructor & Destructor Documentation

Endian::Endian ( EndianType  endian  ) 

Creates an Endian object of a given endian type.

Parameters:
endian The endian type for the object. This type is used as the target endian type for the byte-swapping methods. If the given type is the same as the system type the byte-swapping methods can still be called, but no swapping is performed.
See also:
EndianType

Endian::Endian (  ) 

Creates an Endian object which will always swap.

See also:
EndianType

Endian::~Endian (  ) 

Destroys the Endian object.


Member Function Documentation

EndianType Endian::getEndian (  )  const

Returns the endian type of this.

Returns:
The endian type.
See also:
getSystemEndian()

bool Endian::isBigEndian (  )  const

Queries the endian type of this for EndianType::BIG_ENDIAN_ORDER.

Returns:
Returns true if the endian type is EndianType::BIG_ENDIAN_ORDER, otherwise returns false.

bool Endian::isLittleEndian (  )  const

Queries the endian type of this for EndianType::LITTLE_ENDIAN_ORDER.

Returns:
Returns true if the endian type is EndianType::LITTLE_ENDIAN_ORDER, otherwise returns false.

template<class T>
bool Endian::swapValue ( T &  value  )  const

Swaps the bytes of a single data value.

This method performs in-place byte swapping of a single data value by modifying the given element. If the original value should not be overwritten, use the swapValue() method instead.

Parameters:
value A reference to the data value to swap.
Returns:
Returns true if byte swapping was actually performed. Returns false if no byte swapping is necessary because the endian type is already the same as the system.
See also:
swapValue(const T &), swapBuffer(T *,size_t)

Definition at line 97 of file Endian.h.

template<class T>
T Endian::swapValue ( const T &  value  )  const

Swaps the bytes of a single data value.

This method performs byte swapping of a single data value and returns the swapped value. The original data element is not modified. For performance reasons, if the original data element can be overwritten, use the swapValue() method instead.

Parameters:
value A data value to swap. The value is not modified.
Returns:
Returns the swapped data value. If no swapping is necessary, a copy of the original data value is returned.
See also:
swapValue(T &)

Definition at line 119 of file Endian.h.

template<class T>
bool Endian::swapBuffer ( T *  pBuffer,
size_t  count 
) const

Swaps the bytes of data elements in an array.

This method swaps the bytes of data elements in an array if the endian type of the system is different than the endian type of this.

This method is provided as a convenience if the data type is known.

Parameters:
pBuffer A pointer to the data to be byte swapped.
count The number of items in the array to byte swap.
Returns:
Returns true if byte swapping was actually performed. Returns false if no byte swapping is necessary because the endian type is already the same as the system.
See also:
swapBuffer(void *,size_t,size_t), swapValue(T &)

Definition at line 147 of file Endian.h.

bool Endian::swapBuffer ( FloatComplex pBuffer,
size_t  count 
) const

This override has the same behavior as the templated function of the same name.

It is needed because the template definition is incorrect for complex data.

Parameters:
pBuffer The FloatComplex buffer to swap
count The number of elements in pBuffer to swap
Returns:
Returns true if byte swapping was actually performed. Returns false if no byte swapping is necessary because the endian type is already the same as the system.

Definition at line 168 of file Endian.h.

bool Endian::swapBuffer ( IntegerComplex pBuffer,
size_t  count 
) const

This override has the same behavior as the templated function of the same name.

It is needed because the template definition is incorrect for complex data.

Parameters:
pBuffer The IntegerComplex buffer to swap
count The number of elements in pBuffer to swap
Returns:
Returns true if byte swapping was actually performed. Returns false if no byte swapping is necessary because the endian type is already the same as the system.

Definition at line 189 of file Endian.h.

bool Endian::swapBuffer ( void *  pBuffer,
size_t  dataSize,
size_t  count 
) const

Swaps the bytes of data elements in an array.

This method swaps the bytes of data elements in an array if the endian type of the system is different than endian type of this.

Parameters:
pBuffer A pointer to the data to be byte swapped.
dataSize The size of each element in the array.
count The number of items in the array to byte swap.
Returns:
Returns true if byte swapping was actually performed. Returns false if no byte swapping is necessary because the endian type is already the same as the system.
See also:
swapBuffer(T *,size_t), swapValue(T &)

Definition at line 213 of file Endian.h.

static EndianType Endian::getSystemEndian (  )  [static]

Returns the endian type of the system.

This value is used in the byte-swapping methods to determine whether the data values should be swapped or not.

Returns:
The system endian type.
See also:
getEndian()


Software Development Kit - Opticks 4.9.0 Build 16218