LECanonicalConversion.h

Classes

LECanonicalConversion -- A class with static functions to convert little endian canonical format (full description)

class LECanonicalConversion

Interface

Public Members
static unsigned int toLocal (char& to, const void* from)
static unsigned int toLocal (unsigned char& to, const void* from)
static unsigned int toLocal (short& to, const void* from)
static unsigned int toLocal (unsigned short& to, const void* from)
static unsigned int toLocal (int& to, const void* from)
static unsigned int toLocal (unsigned int& to, const void* from)
static unsigned int toLocal (Int64& to, const void* from)
static unsigned int toLocal (uInt64& to, const void* from)
static unsigned int toLocal (float& to, const void* from)
static unsigned int toLocal (double& to, const void* from)
static unsigned int fromLocal (void* to, const char& from)
static unsigned int fromLocal (void* to, const unsigned char& from)
static unsigned int fromLocal (void* to, const short& from)
static unsigned int fromLocal (void* to, const unsigned short& from)
static unsigned int fromLocal (void* to, const int& from)
static unsigned int fromLocal (void* to, const unsigned int& from)
static unsigned int fromLocal (void* to, const Int64& from)
static unsigned int fromLocal (void* to, const uInt64& from)
static unsigned int fromLocal (void* to, const float& from)
static unsigned int fromLocal (void* to, const double& from)
static unsigned int toLocal (char* to, const void* from, unsigned int nr)
static unsigned int toLocal (unsigned char* to, const void* from, unsigned int nr)
static unsigned int toLocal (short* to, const void* from, unsigned int nr)
static unsigned int toLocal (unsigned short* to, const void* from, unsigned int nr)
static unsigned int toLocal (int* to, const void* from, unsigned int nr)
static unsigned int toLocal (unsigned int* to, const void* from, unsigned int nr)
static unsigned int toLocal (Int64* to, const void* from, unsigned int nr)
static unsigned int toLocal (uInt64* to, const void* from, unsigned int nr)
static unsigned int toLocal (float* to, const void* from, unsigned int nr)
static unsigned int toLocal (double* to, const void* from, unsigned int nr)
static unsigned int fromLocal (void* to, const char* from, unsigned int nr)
static unsigned int fromLocal (void* to, const unsigned char* from, unsigned int nr)
static unsigned int fromLocal (void* to, const short* from, unsigned int nr)
static unsigned int fromLocal (void* to, const unsigned short* from, unsigned int nr)
static unsigned int fromLocal (void* to, const int* from, unsigned int nr)
static unsigned int fromLocal (void* to, const unsigned int* from, unsigned int nr)
static unsigned int fromLocal (void* to, const Int64* from, unsigned int nr)
static unsigned int fromLocal (void* to, const uInt64* from, unsigned int nr)
static unsigned int fromLocal (void* to, const float* from, unsigned int nr)
static unsigned int fromLocal (void* to, const double* from, unsigned int nr)
static unsigned int toLocalChar (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUChar (void* to, const void* from, unsigned int nr)
static unsigned int toLocalShort (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUShort (void* to, const void* from, unsigned int nr)
static unsigned int toLocalInt (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUInt (void* to, const void* from, unsigned int nr)
static unsigned int toLocalInt64 (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUInt64 (void* to, const void* from, unsigned int nr)
static unsigned int toLocalFloat (void* to, const void* from, unsigned int nr)
static unsigned int toLocalDouble (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalChar (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUChar (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalShort (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUShort (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalInt (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUInt (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalInt64 (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUInt64 (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalFloat (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalDouble (void* to, const void* from, unsigned int nr)
static void* byteToLocalChar (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUChar (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalShort (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUShort (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalInt (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUInt (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalFloat (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalDouble (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalChar (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUChar (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalShort (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUShort (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalInt (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUInt (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalFloat (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalDouble (void* to, const void* from, unsigned int nrbytes)
static Conversion::ValueFunction* getToLocal (const char*)
static Conversion::ValueFunction* getToLocal (const unsigned char*)
static Conversion::ValueFunction* getToLocal (const short*)
static Conversion::ValueFunction* getToLocal (const unsigned short*)
static Conversion::ValueFunction* getToLocal (const int*)
static Conversion::ValueFunction* getToLocal (const unsigned int*)
static Conversion::ValueFunction* getToLocal (const Int64*)
static Conversion::ValueFunction* getToLocal (const uInt64*)
static Conversion::ValueFunction* getToLocal (const float*)
static Conversion::ValueFunction* getToLocal (const double*)
static Conversion::ValueFunction* getFromLocal (const char*)
static Conversion::ValueFunction* getFromLocal (const unsigned char*)
static Conversion::ValueFunction* getFromLocal (const short*)
static Conversion::ValueFunction* getFromLocal (const unsigned short*)
static Conversion::ValueFunction* getFromLocal (const int*)
static Conversion::ValueFunction* getFromLocal (const unsigned int*)
static Conversion::ValueFunction* getFromLocal (const Int64*)
static Conversion::ValueFunction* getFromLocal (const uInt64*)
static Conversion::ValueFunction* getFromLocal (const float*)
static Conversion::ValueFunction* getFromLocal (const double*)
static Conversion::ByteFunction* getByteToLocal (const char*)
static Conversion::ByteFunction* getByteToLocal (const unsigned char*)
static Conversion::ByteFunction* getByteToLocal (const short*)
static Conversion::ByteFunction* getByteToLocal (const unsigned short*)
static Conversion::ByteFunction* getByteToLocal (const int*)
static Conversion::ByteFunction* getByteToLocal (const unsigned int*)
static Conversion::ByteFunction* getByteToLocal (const Int64*)
static Conversion::ByteFunction* getByteToLocal (const uInt64*)
static Conversion::ByteFunction* getByteToLocal (const float*)
static Conversion::ByteFunction* getByteToLocal (const double*)
static Conversion::ByteFunction* getByteFromLocal (const char*)
static Conversion::ByteFunction* getByteFromLocal (const unsigned char*)
static Conversion::ByteFunction* getByteFromLocal (const short*)
static Conversion::ByteFunction* getByteFromLocal (const unsigned short*)
static Conversion::ByteFunction* getByteFromLocal (const int*)
static Conversion::ByteFunction* getByteFromLocal (const unsigned int*)
static Conversion::ByteFunction* getByteFromLocal (const Int64*)
static Conversion::ByteFunction* getByteFromLocal (const uInt64*)
static Conversion::ByteFunction* getByteFromLocal (const float*)
static Conversion::ByteFunction* getByteFromLocal (const double*)
static unsigned int canonicalSize (const char*)
static unsigned int canonicalSize (const unsigned char*)
static unsigned int canonicalSize (const short*)
static unsigned int canonicalSize (const unsigned short*)
static unsigned int canonicalSize (const int*)
static unsigned int canonicalSize (const unsigned int*)
static unsigned int canonicalSize (const Int64*)
static unsigned int canonicalSize (const uInt64*)
static unsigned int canonicalSize (const float*)
static unsigned int canonicalSize (const double*)
static void reverse2 (void* to, const void* from)
static void reverse4 (void* to, const void* from)
static void reverse8 (void* to, const void* from)
static void move2 (void* to, const void* from)
static void move4 (void* to, const void* from)
static void move8 (void* to, const void* from)
Private Members
LECanonicalConversion()

Description

Review Status

Reviewed By:
Friso Olnon
Date Reviewed:
1996/11/06
Programs:
Tests:

Synopsis

This class consists of several static functions to convert data from local (=native) format to a little endian canonical format. The canonical length of each data type is:
- Bool: 1 bit
- char: 1 byte
- short: 2 bytes
- int: 4 bytes
- Int64: 8 bytes
- float: 4 bytes
- double: 8 bytes
This canonical format is little-endian IEEE format, so on PCs the conversion is only a copy operation. On e.g. SUNs however, it involves a byte swap to convert from little endian to big endian.

The class also contains conversion functions making it possible to specify the number of bytes (in local format) instead of the number of values. These functions are included to make it possible to have the same signature as memcpy.

The current implementation of this class works on big- and little-endian machines using IEEE format. When using on other machines (e.g. VAX) the toLocal and fromLocal functions have to be changed.

Note that no functions are provided to handle Bools. Instead class Conversion provides functions to convert Bools to/from bits.

Example

    void someFunction (const uInt* data, uInt nrval)
    {
        char* buffer = new char[nrval*LECanonicalConversion::canonicalSize(data)];
        LECanonicalConversion::fromLocal (buffer, data, nrval);
        ....
        delete [] buffer;
    }
    

Motivation

AIPS++ data will be stored in a canonical format. To read these data conversion functions are needed. However, these functions do not use any other AIPS++ classes, so they can easily be used in any other software system.

To Do

Member Description

static unsigned int toLocal (char& to, const void* from)
static unsigned int toLocal (unsigned char& to, const void* from)
static unsigned int toLocal (short& to, const void* from)
static unsigned int toLocal (unsigned short& to, const void* from)
static unsigned int toLocal (int& to, const void* from)
static unsigned int toLocal (unsigned int& to, const void* from)
static unsigned int toLocal (Int64& to, const void* from)
static unsigned int toLocal (uInt64& to, const void* from)
static unsigned int toLocal (float& to, const void* from)
static unsigned int toLocal (double& to, const void* from)

Convert one value from canonical format to local format. The from and to buffer should not overlap.

static unsigned int fromLocal (void* to, const char& from)
static unsigned int fromLocal (void* to, const unsigned char& from)
static unsigned int fromLocal (void* to, const short& from)
static unsigned int fromLocal (void* to, const unsigned short& from)
static unsigned int fromLocal (void* to, const int& from)
static unsigned int fromLocal (void* to, const unsigned int& from)
static unsigned int fromLocal (void* to, const Int64& from)
static unsigned int fromLocal (void* to, const uInt64& from)
static unsigned int fromLocal (void* to, const float& from)
static unsigned int fromLocal (void* to, const double& from)

Convert one value from local format to canonical format. The from and to buffer should not overlap.

static unsigned int toLocal (char* to, const void* from, unsigned int nr)
static unsigned int toLocal (unsigned char* to, const void* from, unsigned int nr)
static unsigned int toLocal (short* to, const void* from, unsigned int nr)
static unsigned int toLocal (unsigned short* to, const void* from, unsigned int nr)
static unsigned int toLocal (int* to, const void* from, unsigned int nr)
static unsigned int toLocal (unsigned int* to, const void* from, unsigned int nr)
static unsigned int toLocal (Int64* to, const void* from, unsigned int nr)
static unsigned int toLocal (uInt64* to, const void* from, unsigned int nr)
static unsigned int toLocal (float* to, const void* from, unsigned int nr)
static unsigned int toLocal (double* to, const void* from, unsigned int nr)

Convert nr values from canonical format to local format. The from and to buffer should not overlap.

static unsigned int fromLocal (void* to, const char* from, unsigned int nr)
static unsigned int fromLocal (void* to, const unsigned char* from, unsigned int nr)
static unsigned int fromLocal (void* to, const short* from, unsigned int nr)
static unsigned int fromLocal (void* to, const unsigned short* from, unsigned int nr)
static unsigned int fromLocal (void* to, const int* from, unsigned int nr)
static unsigned int fromLocal (void* to, const unsigned int* from, unsigned int nr)
static unsigned int fromLocal (void* to, const Int64* from, unsigned int nr)
static unsigned int fromLocal (void* to, const uInt64* from, unsigned int nr)
static unsigned int fromLocal (void* to, const float* from, unsigned int nr)
static unsigned int fromLocal (void* to, const double* from, unsigned int nr)

Convert nr values from local format to canonical format. The from and to buffer should not overlap.

static unsigned int toLocalChar (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUChar (void* to, const void* from, unsigned int nr)
static unsigned int toLocalShort (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUShort (void* to, const void* from, unsigned int nr)
static unsigned int toLocalInt (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUInt (void* to, const void* from, unsigned int nr)
static unsigned int toLocalInt64 (void* to, const void* from, unsigned int nr)
static unsigned int toLocalUInt64 (void* to, const void* from, unsigned int nr)
static unsigned int toLocalFloat (void* to, const void* from, unsigned int nr)
static unsigned int toLocalDouble (void* to, const void* from, unsigned int nr)

Convert nr values from canonical format to local format. The from and to buffer should not overlap.

static unsigned int fromLocalChar (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUChar (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalShort (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUShort (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalInt (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUInt (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalInt64 (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalUInt64 (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalFloat (void* to, const void* from, unsigned int nr)
static unsigned int fromLocalDouble (void* to, const void* from, unsigned int nr)

Convert nr values from local format to canonical format. The from and to buffer should not overlap.

static void* byteToLocalChar (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUChar (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalShort (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUShort (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalInt (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUInt (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalUInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalFloat (void* to, const void* from, unsigned int nrbytes)
static void* byteToLocalDouble (void* to, const void* from, unsigned int nrbytes)

Convert values from canonical format to local format. The from and to buffer should not overlap. The number of values involved is determined from the argument nrbytes, which gives the number of bytes in local format. The signature of this function is the same as memcpy, so that memcpy can directly be used if no conversion is needed.

static void* byteFromLocalChar (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUChar (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalShort (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUShort (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalInt (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUInt (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalUInt64 (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalFloat (void* to, const void* from, unsigned int nrbytes)
static void* byteFromLocalDouble (void* to, const void* from, unsigned int nrbytes)

Convert values from local format to canonical format. The from and to buffer should not overlap. The number of values involved is determined from the argument nrbytes, which gives the number of bytes in local format. The signature of this function is the same as memcpy, so that memcpy can directly be used if no conversion is needed.

static Conversion::ValueFunction* getToLocal (const char*)
static Conversion::ValueFunction* getToLocal (const unsigned char*)
static Conversion::ValueFunction* getToLocal (const short*)
static Conversion::ValueFunction* getToLocal (const unsigned short*)
static Conversion::ValueFunction* getToLocal (const int*)
static Conversion::ValueFunction* getToLocal (const unsigned int*)
static Conversion::ValueFunction* getToLocal (const Int64*)
static Conversion::ValueFunction* getToLocal (const uInt64*)
static Conversion::ValueFunction* getToLocal (const float*)
static Conversion::ValueFunction* getToLocal (const double*)
static Conversion::ValueFunction* getFromLocal (const char*)
static Conversion::ValueFunction* getFromLocal (const unsigned char*)
static Conversion::ValueFunction* getFromLocal (const short*)
static Conversion::ValueFunction* getFromLocal (const unsigned short*)
static Conversion::ValueFunction* getFromLocal (const int*)
static Conversion::ValueFunction* getFromLocal (const unsigned int*)
static Conversion::ValueFunction* getFromLocal (const Int64*)
static Conversion::ValueFunction* getFromLocal (const uInt64*)
static Conversion::ValueFunction* getFromLocal (const float*)
static Conversion::ValueFunction* getFromLocal (const double*)

Get the value conversion function for the given type.

static Conversion::ByteFunction* getByteToLocal (const char*)
static Conversion::ByteFunction* getByteToLocal (const unsigned char*)
static Conversion::ByteFunction* getByteToLocal (const short*)
static Conversion::ByteFunction* getByteToLocal (const unsigned short*)
static Conversion::ByteFunction* getByteToLocal (const int*)
static Conversion::ByteFunction* getByteToLocal (const unsigned int*)
static Conversion::ByteFunction* getByteToLocal (const Int64*)
static Conversion::ByteFunction* getByteToLocal (const uInt64*)
static Conversion::ByteFunction* getByteToLocal (const float*)
static Conversion::ByteFunction* getByteToLocal (const double*)
static Conversion::ByteFunction* getByteFromLocal (const char*)
static Conversion::ByteFunction* getByteFromLocal (const unsigned char*)
static Conversion::ByteFunction* getByteFromLocal (const short*)
static Conversion::ByteFunction* getByteFromLocal (const unsigned short*)
static Conversion::ByteFunction* getByteFromLocal (const int*)
static Conversion::ByteFunction* getByteFromLocal (const unsigned int*)
static Conversion::ByteFunction* getByteFromLocal (const Int64*)
static Conversion::ByteFunction* getByteFromLocal (const uInt64*)
static Conversion::ByteFunction* getByteFromLocal (const float*)
static Conversion::ByteFunction* getByteFromLocal (const double*)

Get the byte conversion function for the given type. The function memcpy is returned when a conversion is not needed.

static unsigned int canonicalSize (const char*)
static unsigned int canonicalSize (const unsigned char*)
static unsigned int canonicalSize (const short*)
static unsigned int canonicalSize (const unsigned short*)
static unsigned int canonicalSize (const int*)
static unsigned int canonicalSize (const unsigned int*)
static unsigned int canonicalSize (const Int64*)
static unsigned int canonicalSize (const uInt64*)
static unsigned int canonicalSize (const float*)
static unsigned int canonicalSize (const double*)

Return the canonical length for the various data types.

static void reverse2 (void* to, const void* from)

Reverse 2 bytes.

static void reverse4 (void* to, const void* from)

Reverse 4 bytes.

static void reverse8 (void* to, const void* from)

Reverse 8 bytes.

static void move2 (void* to, const void* from)

Move 2 bytes.

static void move4 (void* to, const void* from)

Move 4 bytes.

static void move8 (void* to, const void* from)

Move 8 bytes.

LECanonicalConversion()

This class should not be constructed (so declare the constructor private).