26#ifndef CASA_CANONICALCONVERSION_H
27#define CASA_CANONICALCONVERSION_H
30#include <casacore/casa/aips.h>
31#include <casacore/casa/OS/Conversion.h>
41#define SIZE_CAN_CHAR 1
42#define SIZE_CAN_UCHAR 1
43#define SIZE_CAN_SHORT 2
44#define SIZE_CAN_USHORT 2
46#define SIZE_CAN_UINT 4
47#define SIZE_CAN_INT64 8
48#define SIZE_CAN_UINT64 8
49#define SIZE_CAN_FLOAT 4
50#define SIZE_CAN_DOUBLE 8
65#define CONVERT_CAN_CHAR 0
66#define CONVERT_CAN_UCHAR 0
68#if defined(AIPS_LITTLE_ENDIAN)
69# define CONVERT_CAN_SHORT 1
70# define CONVERT_CAN_USHORT 1
71# define CONVERT_CAN_INT 1
72# define CONVERT_CAN_UINT 1
73# define CONVERT_CAN_INT64 1
74# define CONVERT_CAN_UINT64 1
75# define CONVERT_CAN_FLOAT 1
76# define CONVERT_CAN_DOUBLE 1
82# define CONVERT_CAN_SHORT 0
83# define CONVERT_CAN_USHORT 0
84# define CONVERT_CAN_INT 0
85# define CONVERT_CAN_UINT 0
86# define CONVERT_CAN_INT64 0
87# define CONVERT_CAN_UINT64 0
88# define CONVERT_CAN_FLOAT 0
89# define CONVERT_CAN_DOUBLE 0
165 static size_t toLocal (
char& to,
const void* from);
166 static size_t toLocal (
unsigned char& to,
const void* from);
167 static size_t toLocal (
short& to,
const void* from);
168 static size_t toLocal (
unsigned short& to,
const void* from);
169 static size_t toLocal (
int& to,
const void* from);
170 static size_t toLocal (
unsigned int& to,
const void* from);
173 static size_t toLocal (
float& to,
const void* from);
174 static size_t toLocal (
double& to,
const void* from);
182 static size_t fromLocal (
void* to,
const char& from);
183 static size_t fromLocal (
void* to,
const unsigned char& from);
184 static size_t fromLocal (
void* to,
const short& from);
185 static size_t fromLocal (
void* to,
const unsigned short& from);
186 static size_t fromLocal (
void* to,
const int& from);
187 static size_t fromLocal (
void* to,
const unsigned int& from);
190 static size_t fromLocal (
void* to,
const float& from);
191 static size_t fromLocal (
void* to,
const double& from);
197 static size_t toLocal (
char* to,
const void* from,
199 static size_t toLocal (
unsigned char* to,
const void* from,
201 static size_t toLocal (
short* to,
const void* from,
203 static size_t toLocal (
unsigned short* to,
const void* from,
205 static size_t toLocal (
int* to,
const void* from,
207 static size_t toLocal (
unsigned int* to,
const void* from,
213 static size_t toLocal (
float* to,
const void* from,
215 static size_t toLocal (
double* to,
const void* from,
222 static size_t fromLocal (
void* to,
const char* from,
224 static size_t fromLocal (
void* to,
const unsigned char* from,
226 static size_t fromLocal (
void* to,
const short* from,
228 static size_t fromLocal (
void* to,
const unsigned short* from,
230 static size_t fromLocal (
void* to,
const int* from,
232 static size_t fromLocal (
void* to,
const unsigned int* from,
238 static size_t fromLocal (
void* to,
const float* from,
240 static size_t fromLocal (
void* to,
const double* from,
418 static void reverse2 (
void* to,
const void* from);
421 static void reverse4 (
void* to,
const void* from);
424 static void reverse8 (
void* to,
const void* from);
427 static void move2 (
void* to,
const void* from);
430 static void move4 (
void* to,
const void* from);
433 static void move8 (
void* to,
const void* from);
444 unsigned short x, xsw;
446 xsw = ((x & 0xffu) << 8u) | (x >> 8u);
454#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
455 xsw = __builtin_bswap32(x);
457 xsw = ((x & 0xffu) << 24u) | ((x & 0xff00u) << 8u) |
458 ((x & 0xff0000u) >> 8u) | (x >> 24u);
467#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
468 xsw = __builtin_bswap64(x);
470 xsw = ((x & 0xffULL) << 56ULL) |
471 ((x & 0xff00ULL) << 40ULL) |
472 ((x & 0xff0000ULL) << 24ULL) |
473 ((x & 0xff000000ULL) << 8ULL) |
474 ((x & 0xff00000000ULL) >> 8ULL) |
475 ((x & 0xff0000000000ULL) >> 24ULL) |
476 ((x & 0xff000000000000ULL) >> 40ULL) |
495 if (
sizeof(to) < 8) {
496 memmove(to, from, 8);
514 to = *(
unsigned char*)from;
520 if (
sizeof(
short) != 2) {
521 if (((
signed char*)from)[0] < 0) {
527#if defined(AIPS_LITTLE_ENDIAN)
530 move2 (((
char*)&to)+
sizeof(
short)-2, from);
538 if (
sizeof(
unsigned short) != 2) {
541#if defined(AIPS_LITTLE_ENDIAN)
544 move2 (((
char*)&to)+
sizeof(
unsigned short)-2, from);
551 if (
sizeof(
int) != 4) {
552 if (((
signed char*)from)[0] < 0) {
558#if defined(AIPS_LITTLE_ENDIAN)
561 move4 (((
char*)&to)+
sizeof(
int)-4, from);
569 if (
sizeof(
unsigned int) != 4) {
572#if defined(AIPS_LITTLE_ENDIAN)
575 move4 (((
char*)&to)+
sizeof(
unsigned int)-4, from);
582 if (
sizeof(
Int64) != 8) {
583 if (((
signed char*)from)[0] < 0) {
589#if defined(AIPS_LITTLE_ENDIAN)
599 if (
sizeof(
uInt64) != 8) {
602#if defined(AIPS_LITTLE_ENDIAN)
612#if defined(AIPS_LITTLE_ENDIAN)
613 reverse4 (((
char*)&to)+
sizeof(
float)-4, from);
622#if defined(AIPS_LITTLE_ENDIAN)
623 reverse8 (((
char*)&to)+
sizeof(
double)-8, from);
638 const unsigned char& from)
640 *(
unsigned char*)to = from;
647#if defined(AIPS_LITTLE_ENDIAN)
650 move2 (to, ((
char*)&from)+
sizeof(
short)-2);
656 const unsigned short& from)
658#if defined(AIPS_LITTLE_ENDIAN)
661 move2 (to, ((
char*)&from)+
sizeof(
unsigned short)-2);
669#if defined(AIPS_LITTLE_ENDIAN)
672 move4 (to, ((
char*)&from)+
sizeof(
int)-4);
678 const unsigned int& from)
680#if defined(AIPS_LITTLE_ENDIAN)
683 move4 (to, ((
char*)&from)+
sizeof(
unsigned int)-4);
691#if defined(AIPS_LITTLE_ENDIAN)
702#if defined(AIPS_LITTLE_ENDIAN)
713#if defined(AIPS_LITTLE_ENDIAN)
724#if defined(AIPS_LITTLE_ENDIAN)
801 const unsigned char* from,
813 const unsigned short* from,
825 const unsigned int* from,
862 (
const unsigned char*)
872 (
const unsigned short*)
882 (
const unsigned int*)
913 (
const unsigned char*)
923 (
const unsigned short*)
933 (
const unsigned int*)
#define SIZE_CAN_CHAR
Define the canonical sizes of the built-in data types.
LDOUBLE is 8 bytes on SUN, but 16 bytes canonical.
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...
this file contains all the compiler specific defines
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
unsigned long long uInt64