28 #ifndef CASA_CANONICALCONVERSION_H
29 #define CASA_CANONICALCONVERSION_H
43 #define SIZE_CAN_CHAR 1
44 #define SIZE_CAN_UCHAR 1
45 #define SIZE_CAN_SHORT 2
46 #define SIZE_CAN_USHORT 2
47 #define SIZE_CAN_INT 4
48 #define SIZE_CAN_UINT 4
49 #define SIZE_CAN_INT64 8
50 #define SIZE_CAN_UINT64 8
51 #define SIZE_CAN_FLOAT 4
52 #define SIZE_CAN_DOUBLE 8
67 #define CONVERT_CAN_CHAR 0
68 #define CONVERT_CAN_UCHAR 0
70 #if defined(AIPS_LITTLE_ENDIAN)
71 # define CONVERT_CAN_SHORT 1
72 # define CONVERT_CAN_USHORT 1
73 # define CONVERT_CAN_INT 1
74 # define CONVERT_CAN_UINT 1
75 # define CONVERT_CAN_INT64 1
76 # define CONVERT_CAN_UINT64 1
77 # define CONVERT_CAN_FLOAT 1
78 # define CONVERT_CAN_DOUBLE 1
84 # define CONVERT_CAN_SHORT 0
85 # define CONVERT_CAN_USHORT 0
86 # define CONVERT_CAN_INT 0
87 # define CONVERT_CAN_UINT 0
88 # define CONVERT_CAN_INT64 0
89 # define CONVERT_CAN_UINT64 0
90 # define CONVERT_CAN_FLOAT 0
91 # define CONVERT_CAN_DOUBLE 0
167 static size_t toLocal (
char& to,
const void* from);
168 static size_t toLocal (
unsigned char& to,
const void* from);
169 static size_t toLocal (
short& to,
const void* from);
170 static size_t toLocal (
unsigned short& to,
const void* from);
171 static size_t toLocal (
int& to,
const void* from);
172 static size_t toLocal (
unsigned int& to,
const void* from);
175 static size_t toLocal (
float& to,
const void* from);
176 static size_t toLocal (
double& to,
const void* from);
184 static size_t fromLocal (
void* to,
const char& from);
185 static size_t fromLocal (
void* to,
const unsigned char& from);
186 static size_t fromLocal (
void* to,
const short& from);
187 static size_t fromLocal (
void* to,
const unsigned short& from);
188 static size_t fromLocal (
void* to,
const int& from);
189 static size_t fromLocal (
void* to,
const unsigned int& from);
192 static size_t fromLocal (
void* to,
const float& from);
193 static size_t fromLocal (
void* to,
const double& from);
199 static size_t toLocal (
char* to,
const void* from,
201 static size_t toLocal (
unsigned char* to,
const void* from,
203 static size_t toLocal (
short* to,
const void* from,
205 static size_t toLocal (
unsigned short* to,
const void* from,
207 static size_t toLocal (
int* to,
const void* from,
209 static size_t toLocal (
unsigned int* to,
const void* from,
215 static size_t toLocal (
float* to,
const void* from,
217 static size_t toLocal (
double* to,
const void* from,
224 static size_t fromLocal (
void* to,
const char* from,
226 static size_t fromLocal (
void* to,
const unsigned char* from,
228 static size_t fromLocal (
void* to,
const short* from,
230 static size_t fromLocal (
void* to,
const unsigned short* from,
232 static size_t fromLocal (
void* to,
const int* from,
234 static size_t fromLocal (
void* to,
const unsigned int* from,
240 static size_t fromLocal (
void* to,
const float* from,
242 static size_t fromLocal (
void* to,
const double* from,
249 static size_t toLocalChar (
void* to,
const void* from,
257 static size_t toLocalInt (
void* to,
const void* from,
259 static size_t toLocalUInt (
void* to,
const void* from,
420 static void reverse2 (
void* to,
const void* from);
423 static void reverse4 (
void* to,
const void* from);
426 static void reverse8 (
void* to,
const void* from);
429 static void move2 (
void* to,
const void* from);
432 static void move4 (
void* to,
const void* from);
435 static void move8 (
void* to,
const void* from);
446 unsigned short x, xsw;
448 xsw = ((x & 0xffu) << 8u) | (x >> 8u);
456 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
457 xsw = __builtin_bswap32(x);
459 xsw = ((x & 0xffu) << 24u) | ((x & 0xff00u) << 8u) |
460 ((x & 0xff0000u) >> 8u) | (x >> 24u);
469 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
470 xsw = __builtin_bswap64(x);
472 xsw = ((x & 0xffULL) << 56ULL) |
473 ((x & 0xff00ULL) << 40ULL) |
474 ((x & 0xff0000ULL) << 24ULL) |
475 ((x & 0xff000000ULL) << 8ULL) |
476 ((x & 0xff00000000ULL) >> 8ULL) |
477 ((x & 0xff0000000000ULL) >> 24ULL) |
478 ((x & 0xff000000000000ULL) >> 40ULL) |
497 if (
sizeof(to) < 8) {
498 memmove(to, from, 8);
516 to = *(
unsigned char*)from;
522 if (
sizeof(
short) != 2) {
523 if (((
signed char*)from)[0] < 0) {
529 #if defined(AIPS_LITTLE_ENDIAN)
532 move2 (((
char*)&to)+
sizeof(
short)-2, from);
540 if (
sizeof(
unsigned short) != 2) {
543 #if defined(AIPS_LITTLE_ENDIAN)
546 move2 (((
char*)&to)+
sizeof(
unsigned short)-2, from);
553 if (
sizeof(
int) != 4) {
554 if (((
signed char*)from)[0] < 0) {
560 #if defined(AIPS_LITTLE_ENDIAN)
563 move4 (((
char*)&to)+
sizeof(
int)-4, from);
571 if (
sizeof(
unsigned int) != 4) {
574 #if defined(AIPS_LITTLE_ENDIAN)
577 move4 (((
char*)&to)+
sizeof(
unsigned int)-4, from);
584 if (
sizeof(
Int64) != 8) {
585 if (((
signed char*)from)[0] < 0) {
591 #if defined(AIPS_LITTLE_ENDIAN)
601 if (
sizeof(
uInt64) != 8) {
604 #if defined(AIPS_LITTLE_ENDIAN)
614 #if defined(AIPS_LITTLE_ENDIAN)
615 reverse4 (((
char*)&to)+
sizeof(
float)-4, from);
624 #if defined(AIPS_LITTLE_ENDIAN)
625 reverse8 (((
char*)&to)+
sizeof(
double)-8, from);
640 const unsigned char& from)
642 *(
unsigned char*)to = from;
649 #if defined(AIPS_LITTLE_ENDIAN)
652 move2 (to, ((
char*)&from)+
sizeof(
short)-2);
658 const unsigned short& from)
660 #if defined(AIPS_LITTLE_ENDIAN)
663 move2 (to, ((
char*)&from)+
sizeof(
unsigned short)-2);
671 #if defined(AIPS_LITTLE_ENDIAN)
674 move4 (to, ((
char*)&from)+
sizeof(
int)-4);
680 const unsigned int& from)
682 #if defined(AIPS_LITTLE_ENDIAN)
685 move4 (to, ((
char*)&from)+
sizeof(
unsigned int)-4);
693 #if defined(AIPS_LITTLE_ENDIAN)
704 #if defined(AIPS_LITTLE_ENDIAN)
715 #if defined(AIPS_LITTLE_ENDIAN)
726 #if defined(AIPS_LITTLE_ENDIAN)
803 const unsigned char* from,
815 const unsigned short* from,
827 const unsigned int* from,
864 (
const unsigned char*)
874 (
const unsigned short*)
876 return toLocalUShort;
884 (
const unsigned int*)
896 return toLocalUInt64;
906 return toLocalDouble;
912 return fromLocalChar;
915 (
const unsigned char*)
917 return fromLocalUChar;
922 return fromLocalShort;
925 (
const unsigned short*)
927 return fromLocalUShort;
935 (
const unsigned int*)
937 return fromLocalUInt;
942 return fromLocalInt64;
947 return fromLocalUInt64;
952 return fromLocalFloat;
957 return fromLocalDouble;
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
static void move2(void *to, const void *from)
Move 2 bytes.
static void * byteToLocalUInt(void *to, const void *from, size_t nrbytes)
static void * byteFromLocalUShort(void *to, const void *from, size_t nrbytes)
static size_t fromLocalFloat(void *to, const void *from, size_t nr)
static size_t fromLocalUChar(void *to, const void *from, size_t nr)
static void * byteFromLocalChar(void *to, const void *from, size_t nrbytes)
Convert values from local format to canonical format.
static size_t fromLocalUInt(void *to, const void *from, size_t nr)
static size_t fromLocalShort(void *to, const void *from, size_t nr)
static void reverse2(void *to, const void *from)
Reverse 2 bytes.
unsigned long long uInt64
static size_t toLocalUInt(void *to, const void *from, size_t nr)
static unsigned int canonicalSize(const char *)
Return the canonical length for the various data types.
static void reverse8(void *to, const void *from)
Reverse 8 bytes.
static void * byteToLocalUChar(void *to, const void *from, size_t nrbytes)
LDOUBLE is 8 bytes on SUN, but 16 bytes canonical.
static size_t fromLocalDouble(void *to, const void *from, size_t nr)
static void * byteFromLocalUChar(void *to, const void *from, size_t nrbytes)
static void * byteToLocalInt64(void *to, const void *from, size_t nrbytes)
#define SIZE_CAN_CHAR
Define the canonical sizes of the built-in data types.
static void move4(void *to, const void *from)
Move 4 bytes.
static void * byteToLocalShort(void *to, const void *from, size_t nrbytes)
static Conversion::ByteFunction * getByteFromLocal(const char *)
static size_t fromLocalUShort(void *to, const void *from, size_t nr)
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...
static void * byteFromLocalInt64(void *to, const void *from, size_t nrbytes)
static size_t toLocalInt64(void *to, const void *from, size_t nr)
static void * byteToLocalUShort(void *to, const void *from, size_t nrbytes)
static void reverse4(void *to, const void *from)
Reverse 4 bytes.
static void * byteFromLocalUInt64(void *to, const void *from, size_t nrbytes)
static size_t toLocalUInt64(void *to, const void *from, size_t nr)
static void move8(void *to, const void *from)
Move 8 bytes.
static void * byteToLocalFloat(void *to, const void *from, size_t nrbytes)
static void * byteFromLocalUInt(void *to, const void *from, size_t nrbytes)
static Conversion::ValueFunction * getFromLocal(const char *)
static size_t toLocalFloat(void *to, const void *from, size_t nr)
CanonicalConversion()
This class should not be constructed (so declare the constructor private).
static size_t fromLocalInt64(void *to, const void *from, size_t nr)
static size_t fromLocalUInt64(void *to, const void *from, size_t nr)
static void * byteToLocalDouble(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 size_t toLocalShort(void *to, const void *from, size_t nr)
static Conversion::ValueFunction * getToLocal(const char *)
Get the value conversion function for the given type.
static void * byteToLocalChar(void *to, const void *from, size_t nrbytes)
Convert values from canonical format to local format.
static size_t toLocal(char &to, const void *from)
Convert one value from canonical format to local format.
static size_t fromLocal(void *to, const char &from)
Convert one value from local format to canonical format.
static void * byteFromLocalDouble(void *to, const void *from, size_t nrbytes)
static size_t toLocalUShort(void *to, const void *from, size_t nr)
static size_t fromLocalChar(void *to, const void *from, size_t nr)
Convert nr values from local format to canonical format.
static void * byteToLocalUInt64(void *to, const void *from, size_t nrbytes)
static size_t toLocalUChar(void *to, const void *from, size_t nr)
static size_t toLocalInt(void *to, const void *from, size_t nr)
static void * byteToLocalInt(void *to, const void *from, size_t nrbytes)
static void * byteFromLocalInt(void *to, const void *from, size_t nrbytes)
static size_t toLocalDouble(void *to, const void *from, size_t nr)
static size_t fromLocalInt(void *to, const void *from, size_t nr)
static void * byteFromLocalFloat(void *to, const void *from, size_t nrbytes)
static Conversion::ByteFunction * getByteToLocal(const char *)
Get the byte conversion function for the given type.
static void * byteFromLocalShort(void *to, const void *from, size_t nrbytes)
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...
#define casacore
<X11/Intrinsic.h> #defines true, false, casacore::Bool, and String.