26#ifndef CASA_CANONICALCONVERSION_H
27#define CASA_CANONICALCONVERSION_H
30#include <casacore/casa/aips.h>
31#include <casacore/casa/OS/Conversion.h>
40#define SIZE_CAN_CHAR 1
41#define SIZE_CAN_UCHAR 1
42#define SIZE_CAN_SHORT 2
43#define SIZE_CAN_USHORT 2
45#define SIZE_CAN_UINT 4
46#define SIZE_CAN_INT64 8
47#define SIZE_CAN_UINT64 8
48#define SIZE_CAN_FLOAT 4
49#define SIZE_CAN_DOUBLE 8
63#define CONVERT_CAN_CHAR 0
64#define CONVERT_CAN_UCHAR 0
66#if defined(AIPS_LITTLE_ENDIAN)
67#define CONVERT_CAN_SHORT 1
68#define CONVERT_CAN_USHORT 1
69#define CONVERT_CAN_INT 1
70#define CONVERT_CAN_UINT 1
71#define CONVERT_CAN_INT64 1
72#define CONVERT_CAN_UINT64 1
73#define CONVERT_CAN_FLOAT 1
74#define CONVERT_CAN_DOUBLE 1
80#define CONVERT_CAN_SHORT 0
81#define CONVERT_CAN_USHORT 0
82#define CONVERT_CAN_INT 0
83#define CONVERT_CAN_UINT 0
84#define CONVERT_CAN_INT64 0
85#define CONVERT_CAN_UINT64 0
86#define CONVERT_CAN_FLOAT 0
87#define CONVERT_CAN_DOUBLE 0
159 static size_t toLocal(
char& to,
const void* from);
160 static size_t toLocal(
unsigned char& to,
const void* from);
161 static size_t toLocal(
short& to,
const void* from);
162 static size_t toLocal(
unsigned short& to,
const void* from);
163 static size_t toLocal(
int& to,
const void* from);
164 static size_t toLocal(
unsigned int& to,
const void* from);
167 static size_t toLocal(
float& to,
const void* from);
168 static size_t toLocal(
double& to,
const void* from);
176 static size_t fromLocal(
void* to,
const char& from);
177 static size_t fromLocal(
void* to,
const unsigned char& from);
178 static size_t fromLocal(
void* to,
const short& from);
179 static size_t fromLocal(
void* to,
const unsigned short& from);
180 static size_t fromLocal(
void* to,
const int& from);
181 static size_t fromLocal(
void* to,
const unsigned int& from);
184 static size_t fromLocal(
void* to,
const float& from);
185 static size_t fromLocal(
void* to,
const double& from);
191 static size_t toLocal(
char* to,
const void* from,
size_t nr);
192 static size_t toLocal(
unsigned char* to,
const void* from,
size_t nr);
193 static size_t toLocal(
short* to,
const void* from,
size_t nr);
194 static size_t toLocal(
unsigned short* to,
const void* from,
size_t nr);
195 static size_t toLocal(
int* to,
const void* from,
size_t nr);
196 static size_t toLocal(
unsigned int* to,
const void* from,
size_t nr);
197 static size_t toLocal(
Int64* to,
const void* from,
size_t nr);
198 static size_t toLocal(
uInt64* to,
const void* from,
size_t nr);
199 static size_t toLocal(
float* to,
const void* from,
size_t nr);
200 static size_t toLocal(
double* to,
const void* from,
size_t nr);
206 static size_t fromLocal(
void* to,
const char* from,
size_t nr);
207 static size_t fromLocal(
void* to,
const unsigned char* from,
size_t nr);
208 static size_t fromLocal(
void* to,
const short* from,
size_t nr);
209 static size_t fromLocal(
void* to,
const unsigned short* from,
size_t nr);
210 static size_t fromLocal(
void* to,
const int* from,
size_t nr);
211 static size_t fromLocal(
void* to,
const unsigned int* from,
size_t nr);
214 static size_t fromLocal(
void* to,
const float* from,
size_t nr);
215 static size_t fromLocal(
void* to,
const double* from,
size_t nr);
225 static size_t toLocalInt(
void* to,
const void* from,
size_t nr);
352 static void reverse2(
void* to,
const void* from);
355 static void reverse4(
void* to,
const void* from);
358 static void reverse8(
void* to,
const void* from);
361 static void move2(
void* to,
const void* from);
364 static void move4(
void* to,
const void* from);
367 static void move8(
void* to,
const void* from);
376 unsigned short x, xsw;
378 xsw = ((x & 0xffu) << 8u) | (x >> 8u);
385#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
386 xsw = __builtin_bswap32(x);
388 xsw = ((x & 0xffu) << 24u) | ((x & 0xff00u) << 8u) | ((x & 0xff0000u) >> 8u) | (x >> 24u);
396#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
397 xsw = __builtin_bswap64(x);
399 xsw = ((x & 0xffULL) << 56ULL) | ((x & 0xff00ULL) << 40ULL) | ((x & 0xff0000ULL) << 24ULL) |
400 ((x & 0xff000000ULL) << 8ULL) | ((x & 0xff00000000ULL) >> 8ULL) |
401 ((x & 0xff0000000000ULL) >> 24ULL) | ((x & 0xff000000000000ULL) >> 40ULL) | (x >> 56ULL);
412 if (
sizeof(to) < 8) {
413 memmove(to, from, 8);
425 to = *(
unsigned char*)from;
430 if (
sizeof(
short) != 2) {
431 if (((
signed char*)from)[0] < 0) {
437#if defined(AIPS_LITTLE_ENDIAN)
440 move2(((
char*)&to) +
sizeof(
short) - 2, from);
446 if (
sizeof(
unsigned short) != 2) {
449#if defined(AIPS_LITTLE_ENDIAN)
452 move2(((
char*)&to) +
sizeof(
unsigned short) - 2, from);
458 if (
sizeof(
int) != 4) {
459 if (((
signed char*)from)[0] < 0) {
465#if defined(AIPS_LITTLE_ENDIAN)
468 move4(((
char*)&to) +
sizeof(
int) - 4, from);
474 if (
sizeof(
unsigned int) != 4) {
477#if defined(AIPS_LITTLE_ENDIAN)
480 move4(((
char*)&to) +
sizeof(
unsigned int) - 4, from);
486 if (
sizeof(
Int64) != 8) {
487 if (((
signed char*)from)[0] < 0) {
493#if defined(AIPS_LITTLE_ENDIAN)
496 move8(((
char*)&to) +
sizeof(
Int64) - 8, from);
502 if (
sizeof(
uInt64) != 8) {
505#if defined(AIPS_LITTLE_ENDIAN)
514#if defined(AIPS_LITTLE_ENDIAN)
515 reverse4(((
char*)&to) +
sizeof(
float) - 4, from);
523#if defined(AIPS_LITTLE_ENDIAN)
524 reverse8(((
char*)&to) +
sizeof(
double) - 8, from);
536 *(
unsigned char*)to = from;
541#if defined(AIPS_LITTLE_ENDIAN)
544 move2(to, ((
char*)&from) +
sizeof(
short) - 2);
550#if defined(AIPS_LITTLE_ENDIAN)
553 move2(to, ((
char*)&from) +
sizeof(
unsigned short) - 2);
559#if defined(AIPS_LITTLE_ENDIAN)
562 move4(to, ((
char*)&from) +
sizeof(
int) - 4);
568#if defined(AIPS_LITTLE_ENDIAN)
571 move4(to, ((
char*)&from) +
sizeof(
unsigned int) - 4);
577#if defined(AIPS_LITTLE_ENDIAN)
580 move8(to, ((
char*)&from) +
sizeof(
Int64) - 8);
586#if defined(AIPS_LITTLE_ENDIAN)
595#if defined(AIPS_LITTLE_ENDIAN)
604#if defined(AIPS_LITTLE_ENDIAN)
#define SIZE_CAN_CHAR
Define the canonical sizes of the built-in data types.
static void * byteFromLocalShort(void *to, const void *from, size_t nrbytes)
static size_t toLocalChar(void *to, const void *from, size_t nr)
Convert nr values from canonical format to local format.
static unsigned int canonicalSize(const char *)
Return the canonical length for the various data types.
static void * byteFromLocalDouble(void *to, const void *from, size_t nrbytes)
static void * byteToLocalShort(void *to, const void *from, size_t nrbytes)
static Conversion::ByteFunction * getByteToLocal(const short *)
static void * byteToLocalChar(void *to, const void *from, size_t nrbytes)
Convert values from canonical format to local format.
static Conversion::ByteFunction * getByteFromLocal(const double *)
static Conversion::ByteFunction * getByteToLocal(const unsigned int *)
static void reverse8(void *to, const void *from)
Reverse 8 bytes.
static size_t fromLocalChar(void *to, const void *from, size_t nr)
Convert nr values from local format to canonical format.
static size_t fromLocalDouble(void *to, const void *from, size_t nr)
static void * byteToLocalDouble(void *to, const void *from, size_t nrbytes)
static size_t fromLocalUShort(void *to, const void *from, size_t nr)
static Conversion::ValueFunction * getFromLocal(const char *)
static void move8(void *to, const void *from)
Move 8 bytes.
static Conversion::ByteFunction * getByteFromLocal(const Int64 *)
static size_t fromLocalUChar(void *to, const void *from, size_t nr)
static void * byteFromLocalInt(void *to, const void *from, size_t nrbytes)
static void * byteToLocalFloat(void *to, const void *from, size_t nrbytes)
static size_t toLocalInt(void *to, const void *from, size_t nr)
static void * byteToLocalUInt(void *to, const void *from, size_t nrbytes)
static size_t fromLocal(void *to, const char &from)
Convert one value from local format to canonical format.
static void reverse4(void *to, const void *from)
Reverse 4 bytes.
static Conversion::ByteFunction * getByteToLocal(const int *)
CanonicalConversion()
This class should not be constructed (so declare the constructor private).
static Conversion::ByteFunction * getByteToLocal(const unsigned char *)
static Conversion::ByteFunction * getByteFromLocal(const short *)
static size_t toLocalUInt64(void *to, const void *from, size_t nr)
static size_t toLocal(char &to, const void *from)
Convert one value from canonical format to local format.
static void * byteToLocalInt64(void *to, const void *from, size_t nrbytes)
static Conversion::ByteFunction * getByteFromLocal(const int *)
static size_t toLocalUChar(void *to, const void *from, size_t nr)
static Conversion::ByteFunction * getByteFromLocal(const char *)
static size_t fromLocalShort(void *to, const void *from, size_t nr)
static void * byteToLocalUInt64(void *to, const void *from, size_t nrbytes)
static size_t toLocalDouble(void *to, const void *from, size_t nr)
static Conversion::ByteFunction * getByteFromLocal(const unsigned int *)
static Conversion::ByteFunction * getByteFromLocal(const float *)
static size_t fromLocalFloat(void *to, const void *from, size_t nr)
static Conversion::ByteFunction * getByteToLocal(const unsigned short *)
static void reverse2(void *to, const void *from)
Reverse 2 bytes.
static size_t fromLocalUInt64(void *to, const void *from, size_t nr)
static void * byteToLocalUShort(void *to, const void *from, size_t nrbytes)
static size_t toLocalUInt(void *to, const void *from, size_t nr)
static Conversion::ByteFunction * getByteToLocal(const double *)
static Conversion::ByteFunction * getByteToLocal(const Int64 *)
static void move2(void *to, const void *from)
Move 2 bytes.
static Conversion::ByteFunction * getByteToLocal(const float *)
static Conversion::ValueFunction * getToLocal(const char *)
Get the value conversion function for the given type.
static void * byteFromLocalUInt(void *to, const void *from, size_t nrbytes)
static size_t toLocalUShort(void *to, const void *from, size_t nr)
static Conversion::ByteFunction * getByteToLocal(const uInt64 *)
static void * byteToLocalInt(void *to, const void *from, size_t nrbytes)
static size_t toLocalFloat(void *to, const void *from, size_t nr)
static Conversion::ByteFunction * getByteFromLocal(const unsigned short *)
static void * byteFromLocalUShort(void *to, const void *from, size_t nrbytes)
static void move4(void *to, const void *from)
Move 4 bytes.
static void * byteFromLocalUChar(void *to, const void *from, size_t nrbytes)
static size_t fromLocalInt64(void *to, const void *from, size_t nr)
static void * byteToLocalUChar(void *to, const void *from, size_t nrbytes)
static size_t toLocalInt64(void *to, const void *from, size_t nr)
static size_t fromLocalInt(void *to, const void *from, size_t nr)
static size_t toLocalShort(void *to, const void *from, size_t nr)
static void * byteFromLocalInt64(void *to, const void *from, size_t nrbytes)
static Conversion::ByteFunction * getByteToLocal(const char *)
Get the byte conversion function for the given type.
static Conversion::ByteFunction * getByteFromLocal(const uInt64 *)
static void * byteFromLocalUInt64(void *to, const void *from, size_t nrbytes)
static Conversion::ByteFunction * getByteFromLocal(const unsigned char *)
static size_t fromLocalUInt(void *to, const void *from, size_t nr)
static void * byteFromLocalFloat(void *to, const void *from, size_t nrbytes)
static void * byteFromLocalChar(void *to, const void *from, size_t nrbytes)
Convert values from local format to canonical format.
size_t ValueFunction(void *to, const void *from, size_t nvalues)
Define the signature of a function converting nvalues values from internal to external format or vice...
void * ByteFunction(void *to, const void *from, size_t nbytes)
Define the signature of a function converting from one format to another providing the number of byte...
For temporary backward namespace compatibility, use casa as alias for casacore.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
unsigned long long uInt64