casacore
Loading...
Searching...
No Matches
CanonicalConversion.h
Go to the documentation of this file.
1//# CanonicalConversion.h: A class with static functions to convert canonical format
2//# Copyright (C) 1996,1997,1999,2000,2001,2002
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_CANONICALCONVERSION_H
27#define CASA_CANONICALCONVERSION_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/OS/Conversion.h>
32#include <cstring>
33
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37// Define the canonical sizes of the built-in data types.
38// These are the same for all machine architectures.
39// Also define the maximum size.
40
41#define SIZE_CAN_CHAR 1
42#define SIZE_CAN_UCHAR 1
43#define SIZE_CAN_SHORT 2
44#define SIZE_CAN_USHORT 2
45#define SIZE_CAN_INT 4
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
51//#//define SIZE_CAN_LDOUBLE 16
52
53
54// Define for each data format if a conversion is needed from the
55// local format to the canonical format (or vice-versa).
56// This allows for optimizations in, for example, AipsIO.
57// The canonical format is ASCII for strings, IEEE for floating point
58// and 2-complement for integers (all most significant bit first)
59// with the lengths as shown above.
60// The function checkConvert() can be used to check if the flags are
61// set correctly.
62
63// Conversion is needed for little endian architectures (like DEC and Intel),
64// because the bytes have to be swapped (thus not for data with length 1).
65#define CONVERT_CAN_CHAR 0
66#define CONVERT_CAN_UCHAR 0
67
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
77//#//# define CONVERT_CAN_LDOUBLE 1
78#else
79
80// Conversion is not needed for IEEE data.
81// Change the definitions below if new architectures are being used.
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
90// LDOUBLE is 8 bytes on SUN, but 16 bytes canonical.
91//#//# define CONVERT_CAN_LDOUBLE 1
92#endif
93
94
95
96// <summary>
97// A class with static functions to convert canonical format
98// </summary>
99
100// <use visibility=export>
101
102// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tCanonicalConversion" demos="">
103// </reviewed>
104
105// <synopsis>
106// This class consists of several static functions to convert
107// data from local (=native) format to a canonical format.
108// The canonical length of each data type is:
109// <br>- Bool: 1 bit
110// <br>- char: 1 byte
111// <br>- short: 2 bytes
112// <br>- int: 4 bytes
113// <br>- Int64: 8 bytes
114// <br>- float: 4 bytes
115// <br>- double: 8 bytes
116// <br> The canonical format is big-endian IEEE format, so on many machines
117// the conversion is only a copy operation. On Alpha- or Intel-based
118// machines, however, it involves a byte swap to convert from little
119// endian to big endian.
120// <p>
121// The class also contains conversion functions making it possible to
122// specify the number of bytes (in local format) instead of the number
123// of values. These functions are included to make it possible to have
124// the same signature as memcpy.
125// <p>
126// The current implementation of this class works on big- and little-endian
127// machines using IEEE format. When using on other machines (e.g. VAX)
128// the toLocal and fromLocal functions have to be changed.
129// <p>
130// Note that no functions are provided to handle Bools. Instead class
131// <linkto class=Conversion>Conversion</linkto> provides functions to
132// convert Bools to/from bits.
133// </synopsis>
134
135// <example>
136// <srcblock>
137// void someFunction (const uInt* data, uInt nrval)
138// {
139// char* buffer = new char[nrval*CanonicalConversion::canonicalSize(data)];
140// CanonicalConversion::fromLocal (buffer, data, nrval);
141// ....
142// delete [] buffer;
143// }
144// </srcblock>
145// </example>
146
147// <motivation>
148// Casacore data will often be stored in a canonical format.
149// To read these data conversion functions are needed.
150// However, these functions do not use any other Casacore classes,
151// so they can easily be used in any other software system.
152// </motivation>
153
154// <todo asof="$DATE$">
155// <li> Support data type long double.
156// </todo>
157
158
160{
161public:
162 // Convert one value from canonical format to local format.
163 // The from and to buffer should not overlap.
164 // <group>
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);
171 static size_t toLocal (Int64& to, const void* from);
172 static size_t toLocal (uInt64& to, const void* from);
173 static size_t toLocal (float& to, const void* from);
174 static size_t toLocal (double& to, const void* from);
175 // </group>
176
177 // Convert one value from local format to canonical format.
178 // The from and to buffer should not overlap.
179 //# Note that the from value is passed by reference (and not by value),
180 //# because the & operator applied to it is slowish if passed by value.
181 // <group>
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);
188 static size_t fromLocal (void* to, const Int64& from);
189 static size_t fromLocal (void* to, const uInt64& from);
190 static size_t fromLocal (void* to, const float& from);
191 static size_t fromLocal (void* to, const double& from);
192 // </group>
193
194 // Convert nr values from canonical format to local format.
195 // The from and to buffer should not overlap.
196 // <group>
197 static size_t toLocal (char* to, const void* from,
198 size_t nr);
199 static size_t toLocal (unsigned char* to, const void* from,
200 size_t nr);
201 static size_t toLocal (short* to, const void* from,
202 size_t nr);
203 static size_t toLocal (unsigned short* to, const void* from,
204 size_t nr);
205 static size_t toLocal (int* to, const void* from,
206 size_t nr);
207 static size_t toLocal (unsigned int* to, const void* from,
208 size_t nr);
209 static size_t toLocal (Int64* to, const void* from,
210 size_t nr);
211 static size_t toLocal (uInt64* to, const void* from,
212 size_t nr);
213 static size_t toLocal (float* to, const void* from,
214 size_t nr);
215 static size_t toLocal (double* to, const void* from,
216 size_t nr);
217 // </group>
218
219 // Convert nr values from local format to canonical format.
220 // The from and to buffer should not overlap.
221 // <group>
222 static size_t fromLocal (void* to, const char* from,
223 size_t nr);
224 static size_t fromLocal (void* to, const unsigned char* from,
225 size_t nr);
226 static size_t fromLocal (void* to, const short* from,
227 size_t nr);
228 static size_t fromLocal (void* to, const unsigned short* from,
229 size_t nr);
230 static size_t fromLocal (void* to, const int* from,
231 size_t nr);
232 static size_t fromLocal (void* to, const unsigned int* from,
233 size_t nr);
234 static size_t fromLocal (void* to, const Int64* from,
235 size_t nr);
236 static size_t fromLocal (void* to, const uInt64* from,
237 size_t nr);
238 static size_t fromLocal (void* to, const float* from,
239 size_t nr);
240 static size_t fromLocal (void* to, const double* from,
241 size_t nr);
242 // </group>
243
244 // Convert nr values from canonical format to local format.
245 // The from and to buffer should not overlap.
246 // <group>
247 static size_t toLocalChar (void* to, const void* from,
248 size_t nr);
249 static size_t toLocalUChar (void* to, const void* from,
250 size_t nr);
251 static size_t toLocalShort (void* to, const void* from,
252 size_t nr);
253 static size_t toLocalUShort (void* to, const void* from,
254 size_t nr);
255 static size_t toLocalInt (void* to, const void* from,
256 size_t nr);
257 static size_t toLocalUInt (void* to, const void* from,
258 size_t nr);
259 static size_t toLocalInt64 (void* to, const void* from,
260 size_t nr);
261 static size_t toLocalUInt64 (void* to, const void* from,
262 size_t nr);
263 static size_t toLocalFloat (void* to, const void* from,
264 size_t nr);
265 static size_t toLocalDouble (void* to, const void* from,
266 size_t nr);
267 // </group>
268
269 // Convert nr values from local format to canonical format.
270 // The from and to buffer should not overlap.
271 // <group>
272 static size_t fromLocalChar (void* to, const void* from,
273 size_t nr);
274 static size_t fromLocalUChar (void* to, const void* from,
275 size_t nr);
276 static size_t fromLocalShort (void* to, const void* from,
277 size_t nr);
278 static size_t fromLocalUShort (void* to, const void* from,
279 size_t nr);
280 static size_t fromLocalInt (void* to, const void* from,
281 size_t nr);
282 static size_t fromLocalUInt (void* to, const void* from,
283 size_t nr);
284 static size_t fromLocalInt64 (void* to, const void* from,
285 size_t nr);
286 static size_t fromLocalUInt64 (void* to, const void* from,
287 size_t nr);
288 static size_t fromLocalFloat (void* to, const void* from,
289 size_t nr);
290 static size_t fromLocalDouble (void* to, const void* from,
291 size_t nr);
292 // </group>
293
294 // Convert values from canonical format to local format.
295 // The from and to buffer should not overlap.
296 // The number of values involved is determined from the argument
297 // <src>nrbytes</src>, which gives the number of bytes in local format.
298 // The signature of this function is the same as <src>memcpy</src>, so
299 // that memcpy can directly be used if no conversion is needed.
300 // <group>
301 static void* byteToLocalChar (void* to, const void* from,
302 size_t nrbytes);
303 static void* byteToLocalUChar (void* to, const void* from,
304 size_t nrbytes);
305 static void* byteToLocalShort (void* to, const void* from,
306 size_t nrbytes);
307 static void* byteToLocalUShort (void* to, const void* from,
308 size_t nrbytes);
309 static void* byteToLocalInt (void* to, const void* from,
310 size_t nrbytes);
311 static void* byteToLocalUInt (void* to, const void* from,
312 size_t nrbytes);
313 static void* byteToLocalInt64 (void* to, const void* from,
314 size_t nrbytes);
315 static void* byteToLocalUInt64 (void* to, const void* from,
316 size_t nrbytes);
317 static void* byteToLocalFloat (void* to, const void* from,
318 size_t nrbytes);
319 static void* byteToLocalDouble (void* to, const void* from,
320 size_t nrbytes);
321 // </group>
322
323 // Convert values from local format to canonical format.
324 // The from and to buffer should not overlap.
325 // The number of values involved is determined from the argument
326 // <src>nrbytes</src>, which gives the number of bytes in local format.
327 // The signature of this function is the same as <src>memcpy</src>, so
328 // that memcpy can directly be used if no conversion is needed.
329 // <group>
330 static void* byteFromLocalChar (void* to, const void* from,
331 size_t nrbytes);
332 static void* byteFromLocalUChar (void* to, const void* from,
333 size_t nrbytes);
334 static void* byteFromLocalShort (void* to, const void* from,
335 size_t nrbytes);
336 static void* byteFromLocalUShort (void* to, const void* from,
337 size_t nrbytes);
338 static void* byteFromLocalInt (void* to, const void* from,
339 size_t nrbytes);
340 static void* byteFromLocalUInt (void* to, const void* from,
341 size_t nrbytes);
342 static void* byteFromLocalInt64 (void* to, const void* from,
343 size_t nrbytes);
344 static void* byteFromLocalUInt64 (void* to, const void* from,
345 size_t nrbytes);
346 static void* byteFromLocalFloat (void* to, const void* from,
347 size_t nrbytes);
348 static void* byteFromLocalDouble (void* to, const void* from,
349 size_t nrbytes);
350 // </group>
351
352 // Get the value conversion function for the given type.
353 // <group>
354 static Conversion::ValueFunction* getToLocal (const char*);
355 static Conversion::ValueFunction* getToLocal (const unsigned char*);
356 static Conversion::ValueFunction* getToLocal (const short*);
357 static Conversion::ValueFunction* getToLocal (const unsigned short*);
358 static Conversion::ValueFunction* getToLocal (const int*);
359 static Conversion::ValueFunction* getToLocal (const unsigned int*);
362 static Conversion::ValueFunction* getToLocal (const float*);
363 static Conversion::ValueFunction* getToLocal (const double*);
364 static Conversion::ValueFunction* getFromLocal (const char*);
365 static Conversion::ValueFunction* getFromLocal (const unsigned char*);
366 static Conversion::ValueFunction* getFromLocal (const short*);
367 static Conversion::ValueFunction* getFromLocal (const unsigned short*);
368 static Conversion::ValueFunction* getFromLocal (const int*);
369 static Conversion::ValueFunction* getFromLocal (const unsigned int*);
372 static Conversion::ValueFunction* getFromLocal (const float*);
373 static Conversion::ValueFunction* getFromLocal (const double*);
374 // </group>
375
376 // Get the byte conversion function for the given type.
377 // The function <src>memcpy</src> is returned when a conversion
378 // is not needed.
379 // <group>
381 static Conversion::ByteFunction* getByteToLocal (const unsigned char*);
383 static Conversion::ByteFunction* getByteToLocal (const unsigned short*);
385 static Conversion::ByteFunction* getByteToLocal (const unsigned int*);
391 static Conversion::ByteFunction* getByteFromLocal (const unsigned char*);
393 static Conversion::ByteFunction* getByteFromLocal (const unsigned short*);
395 static Conversion::ByteFunction* getByteFromLocal (const unsigned int*);
400 // </group>
401
402 // Return the canonical length for the various data types.
403 // <group>
404 static unsigned int canonicalSize (const char*);
405 static unsigned int canonicalSize (const unsigned char*);
406 static unsigned int canonicalSize (const short*);
407 static unsigned int canonicalSize (const unsigned short*);
408 static unsigned int canonicalSize (const int*);
409 static unsigned int canonicalSize (const unsigned int*);
410 static unsigned int canonicalSize (const Int64*);
411 static unsigned int canonicalSize (const uInt64*);
412 static unsigned int canonicalSize (const float*);
413 static unsigned int canonicalSize (const double*);
414 //#//static unsigned int canonicalSize (const long double*);
415 // </group>
416
417 // Reverse 2 bytes.
418 static void reverse2 (void* to, const void* from);
419
420 // Reverse 4 bytes.
421 static void reverse4 (void* to, const void* from);
422
423 // Reverse 8 bytes.
424 static void reverse8 (void* to, const void* from);
425
426 // Move 2 bytes.
427 static void move2 (void* to, const void* from);
428
429 // Move 4 bytes.
430 static void move4 (void* to, const void* from);
431
432 // Move 8 bytes.
433 static void move8 (void* to, const void* from);
434
435private:
436 // This class should not be constructed
437 // (so declare the constructor private).
439};
440
441
442inline void CanonicalConversion::reverse2 (void* to, const void* from)
443{
444 unsigned short x, xsw;
445 memcpy(&x, from, 2);
446 xsw = ((x & 0xffu) << 8u) | (x >> 8u);
447 memcpy(to, &xsw, 2);
448}
449
450inline void CanonicalConversion::reverse4 (void* to, const void* from)
451{
452 unsigned int x, xsw;
453 memcpy(&x, from, 4);
454#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
455 xsw = __builtin_bswap32(x);
456#else
457 xsw = ((x & 0xffu) << 24u) | ((x & 0xff00u) << 8u) |
458 ((x & 0xff0000u) >> 8u) | (x >> 24u);
459#endif
460 memcpy(to, &xsw, 4);
461}
462
463inline void CanonicalConversion::reverse8 (void* to, const void* from)
464{
465 uInt64 x, xsw;
466 memcpy(&x, from, 8);
467#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
468 xsw = __builtin_bswap64(x);
469#else
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) |
477 ( x >> 56ULL);
478#endif
479 memcpy(to, &xsw, 8);
480}
481
482inline void CanonicalConversion::move2 (void* to, const void* from)
483{
484 memcpy(to, from, 2);
485}
486
487inline void CanonicalConversion::move4 (void* to, const void* from)
488{
489 memcpy(to, from, 4);
490}
491
492inline void CanonicalConversion::move8 (void* to, const void* from)
493{
494 /* memcpy is overlap save if size fits into a register */
495 if (sizeof(to) < 8) {
496 memmove(to, from, 8);
497 }
498 else {
499 memcpy(to, from, 8);
500 }
501}
502
503
504
505inline size_t CanonicalConversion::toLocal (char& to, const void* from)
506{
507 to = *(char*)from;
508 return SIZE_CAN_CHAR;
509}
510
511inline size_t CanonicalConversion::toLocal (unsigned char& to,
512 const void* from)
513{
514 to = *(unsigned char*)from;
515 return SIZE_CAN_UCHAR;
516}
517
518inline size_t CanonicalConversion::toLocal (short& to, const void* from)
519{
520 if (sizeof(short) != 2) {
521 if (((signed char*)from)[0] < 0) {
522 to = -1;
523 }else{
524 to = 0;
525 }
526 }
527#if defined(AIPS_LITTLE_ENDIAN)
528 reverse2 (&to, from);
529#else
530 move2 (((char*)&to)+sizeof(short)-2, from);
531#endif
532 return SIZE_CAN_SHORT;
533}
534
535inline size_t CanonicalConversion::toLocal (unsigned short& to,
536 const void* from)
537{
538 if (sizeof(unsigned short) != 2) {
539 to = 0;
540 }
541#if defined(AIPS_LITTLE_ENDIAN)
542 reverse2 (&to, from);
543#else
544 move2 (((char*)&to)+sizeof(unsigned short)-2, from);
545#endif
546 return SIZE_CAN_USHORT;
547}
548
549inline size_t CanonicalConversion::toLocal (int& to, const void* from)
550{
551 if (sizeof(int) != 4) {
552 if (((signed char*)from)[0] < 0) {
553 to = -1;
554 }else{
555 to = 0;
556 }
557 }
558#if defined(AIPS_LITTLE_ENDIAN)
559 reverse4 (&to, from);
560#else
561 move4 (((char*)&to)+sizeof(int)-4, from);
562#endif
563 return SIZE_CAN_INT;
564}
565
566inline size_t CanonicalConversion::toLocal (unsigned int& to,
567 const void* from)
568{
569 if (sizeof(unsigned int) != 4) {
570 to = 0;
571 }
572#if defined(AIPS_LITTLE_ENDIAN)
573 reverse4 (&to, from);
574#else
575 move4 (((char*)&to)+sizeof(unsigned int)-4, from);
576#endif
577 return SIZE_CAN_UINT;
578}
579
580inline size_t CanonicalConversion::toLocal (Int64& to, const void* from)
581{
582 if (sizeof(Int64) != 8) {
583 if (((signed char*)from)[0] < 0) {
584 to = -1;
585 }else{
586 to = 0;
587 }
588 }
589#if defined(AIPS_LITTLE_ENDIAN)
590 reverse8 (&to, from);
591#else
592 move8 (((char*)&to)+sizeof(Int64)-8, from);
593#endif
594 return SIZE_CAN_INT64;
595}
596
597inline size_t CanonicalConversion::toLocal (uInt64& to, const void* from)
598{
599 if (sizeof(uInt64) != 8) {
600 to = 0;
601 }
602#if defined(AIPS_LITTLE_ENDIAN)
603 reverse8 (&to, from);
604#else
605 move8 (((char*)&to)+sizeof(uInt64)-8, from);
606#endif
607 return SIZE_CAN_UINT64;
608}
609
610inline size_t CanonicalConversion::toLocal (float& to, const void* from)
611{
612#if defined(AIPS_LITTLE_ENDIAN)
613 reverse4 (((char*)&to)+sizeof(float)-4, from);
614#else
615 move4 (&to, from);
616#endif
617 return SIZE_CAN_FLOAT;
618}
619
620inline size_t CanonicalConversion::toLocal (double& to, const void* from)
621{
622#if defined(AIPS_LITTLE_ENDIAN)
623 reverse8 (((char*)&to)+sizeof(double)-8, from);
624#else
625 move8 (&to, from);
626#endif
627 return SIZE_CAN_DOUBLE;
628}
629
630
631inline size_t CanonicalConversion::fromLocal (void* to,
632 const char& from)
633{
634 *(char*)to = from;
635 return SIZE_CAN_CHAR;
636}
637inline size_t CanonicalConversion::fromLocal (void* to,
638 const unsigned char& from)
639{
640 *(unsigned char*)to = from;
641 return SIZE_CAN_UCHAR;
642}
643
644inline size_t CanonicalConversion::fromLocal (void* to,
645 const short& from)
646{
647#if defined(AIPS_LITTLE_ENDIAN)
648 reverse2 (to, &from);
649#else
650 move2 (to, ((char*)&from)+sizeof(short)-2);
651#endif
652 return SIZE_CAN_SHORT;
653}
654
655inline size_t CanonicalConversion::fromLocal (void* to,
656 const unsigned short& from)
657{
658#if defined(AIPS_LITTLE_ENDIAN)
659 reverse2 (to, &from);
660#else
661 move2 (to, ((char*)&from)+sizeof(unsigned short)-2);
662#endif
663 return SIZE_CAN_USHORT;
664}
665
666inline size_t CanonicalConversion::fromLocal (void* to,
667 const int& from)
668{
669#if defined(AIPS_LITTLE_ENDIAN)
670 reverse4 (to, &from);
671#else
672 move4 (to, ((char*)&from)+sizeof(int)-4);
673#endif
674 return SIZE_CAN_INT;
675}
676
677inline size_t CanonicalConversion::fromLocal (void* to,
678 const unsigned int& from)
679{
680#if defined(AIPS_LITTLE_ENDIAN)
681 reverse4 (to, &from);
682#else
683 move4 (to, ((char*)&from)+sizeof(unsigned int)-4);
684#endif
685 return SIZE_CAN_UINT;
686}
687
688inline size_t CanonicalConversion::fromLocal (void* to,
689 const Int64& from)
690{
691#if defined(AIPS_LITTLE_ENDIAN)
692 reverse8 (to, &from);
693#else
694 move8 (to, ((char*)&from)+sizeof(Int64)-8);
695#endif
696 return SIZE_CAN_INT64;
697}
698
699inline size_t CanonicalConversion::fromLocal (void* to,
700 const uInt64& from)
701{
702#if defined(AIPS_LITTLE_ENDIAN)
703 reverse8 (to, &from);
704#else
705 move8 (to, ((char*)&from)+sizeof(uInt64)-8);
706#endif
707 return SIZE_CAN_UINT64;
708}
709
710inline size_t CanonicalConversion::fromLocal (void* to,
711 const float& from)
712{
713#if defined(AIPS_LITTLE_ENDIAN)
714 reverse4 (to, &from);
715#else
716 move4 (to, &from);
717#endif
718 return SIZE_CAN_FLOAT;
719}
720
721inline size_t CanonicalConversion::fromLocal (void* to,
722 const double& from)
723{
724#if defined(AIPS_LITTLE_ENDIAN)
725 reverse8 (to, &from);
726#else
727 move8 (to, &from);
728#endif
729 return SIZE_CAN_FLOAT;
730}
731
732
733inline size_t CanonicalConversion::toLocal (char* to,
734 const void* from,
735 size_t nr)
736{
737 return toLocalChar (to, from, nr);
738}
739inline size_t CanonicalConversion::toLocal (unsigned char* to,
740 const void* from,
741 size_t nr)
742{
743 return toLocalUChar (to, from, nr);
744}
745inline size_t CanonicalConversion::toLocal (short* to,
746 const void* from,
747 size_t nr)
748{
749 return toLocalShort (to, from, nr);
750}
751inline size_t CanonicalConversion::toLocal (unsigned short* to,
752 const void* from,
753 size_t nr)
754{
755 return toLocalUShort (to, from, nr);
756}
757inline size_t CanonicalConversion::toLocal (int* to,
758 const void* from,
759 size_t nr)
760{
761 return toLocalInt (to, from, nr);
762}
763inline size_t CanonicalConversion::toLocal (unsigned int* to,
764 const void* from,
765 size_t nr)
766{
767 return toLocalUInt (to, from, nr);
768}
770 const void* from,
771 size_t nr)
772{
773 return toLocalInt64 (to, from, nr);
774}
776 const void* from,
777 size_t nr)
778{
779 return toLocalUInt64 (to, from, nr);
780}
781inline size_t CanonicalConversion::toLocal (float* to,
782 const void* from,
783 size_t nr)
784{
785 return toLocalFloat (to, from, nr);
786}
787inline size_t CanonicalConversion::toLocal (double* to,
788 const void* from,
789 size_t nr)
790{
791 return toLocalDouble (to, from, nr);
792}
793
794inline size_t CanonicalConversion::fromLocal (void* to,
795 const char* from,
796 size_t nr)
797{
798 return fromLocalChar (to, from, nr);
799}
800inline size_t CanonicalConversion::fromLocal (void* to,
801 const unsigned char* from,
802 size_t nr)
803{
804 return fromLocalUChar (to, from, nr);
805}
806inline size_t CanonicalConversion::fromLocal (void* to,
807 const short* from,
808 size_t nr)
809{
810 return fromLocalShort (to, from, nr);
811}
812inline size_t CanonicalConversion::fromLocal (void* to,
813 const unsigned short* from,
814 size_t nr)
815{
816 return fromLocalUShort (to, from, nr);
817}
818inline size_t CanonicalConversion::fromLocal (void* to,
819 const int* from,
820 size_t nr)
821{
822 return fromLocalInt (to, from, nr);
823}
824inline size_t CanonicalConversion::fromLocal (void* to,
825 const unsigned int* from,
826 size_t nr)
827{
828 return fromLocalUInt (to, from, nr);
829}
830inline size_t CanonicalConversion::fromLocal (void* to,
831 const Int64* from,
832 size_t nr)
833{
834 return fromLocalInt64 (to, from, nr);
835}
836inline size_t CanonicalConversion::fromLocal (void* to,
837 const uInt64* from,
838 size_t nr)
839{
840 return fromLocalUInt64 (to, from, nr);
841}
842inline size_t CanonicalConversion::fromLocal (void* to,
843 const float* from,
844 size_t nr)
845{
846 return fromLocalFloat (to, from, nr);
847}
848inline size_t CanonicalConversion::fromLocal (void* to,
849 const double* from,
850 size_t nr)
851{
852 return fromLocalDouble (to, from, nr);
853}
854
855
857 (const char*)
858{
859 return toLocalChar;
860}
862 (const unsigned char*)
863{
864 return toLocalUChar;
865}
867 (const short*)
868{
869 return toLocalShort;
870}
872 (const unsigned short*)
873{
874 return toLocalUShort;
875}
877 (const int*)
878{
879 return toLocalInt;
880}
882 (const unsigned int*)
883{
884 return toLocalUInt;
885}
897 (const float*)
898{
899 return toLocalFloat;
900}
902 (const double*)
903{
904 return toLocalDouble;
905}
906
908 (const char*)
909{
910 return fromLocalChar;
911}
913 (const unsigned char*)
914{
915 return fromLocalUChar;
916}
918 (const short*)
919{
920 return fromLocalShort;
921}
923 (const unsigned short*)
924{
925 return fromLocalUShort;
926}
928 (const int*)
929{
930 return fromLocalInt;
931}
933 (const unsigned int*)
934{
935 return fromLocalUInt;
936}
948 (const float*)
949{
950 return fromLocalFloat;
951}
953 (const double*)
954{
955 return fromLocalDouble;
956}
957
958
959inline unsigned int CanonicalConversion::canonicalSize (const char*)
960 {return SIZE_CAN_CHAR;}
961inline unsigned int CanonicalConversion::canonicalSize (const unsigned char*)
962 {return SIZE_CAN_UCHAR;}
963inline unsigned int CanonicalConversion::canonicalSize (const short*)
964 {return SIZE_CAN_SHORT;}
965inline unsigned int CanonicalConversion::canonicalSize (const unsigned short*)
966 {return SIZE_CAN_USHORT;}
967inline unsigned int CanonicalConversion::canonicalSize (const int*)
968 {return SIZE_CAN_INT;}
969inline unsigned int CanonicalConversion::canonicalSize (const unsigned int*)
970 {return SIZE_CAN_UINT;}
971inline unsigned int CanonicalConversion::canonicalSize (const Int64*)
972 {return SIZE_CAN_INT64;}
973inline unsigned int CanonicalConversion::canonicalSize (const uInt64*)
974 {return SIZE_CAN_UINT64;}
975inline unsigned int CanonicalConversion::canonicalSize (const float*)
976 {return SIZE_CAN_FLOAT;}
977inline unsigned int CanonicalConversion::canonicalSize (const double*)
978 {return SIZE_CAN_DOUBLE;}
979//#//inline unsigned int CanonicalConversion::canonicalSize (const long double*)
980//#// {return SIZE_CAN_LDOUBLE;}
981
982
983
984
985} //# NAMESPACE CASACORE - END
986
987#endif
#define SIZE_CAN_UINT
#define SIZE_CAN_INT64
#define SIZE_CAN_USHORT
#define SIZE_CAN_CHAR
Define the canonical sizes of the built-in data types.
#define SIZE_CAN_DOUBLE
#define SIZE_CAN_INT
#define SIZE_CAN_UCHAR
#define SIZE_CAN_SHORT
#define SIZE_CAN_FLOAT
#define SIZE_CAN_UINT64
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...
Definition Conversion.h:98
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...
Definition Conversion.h:106
this file contains all the compiler specific defines
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
unsigned long long uInt64
Definition aipsxtype.h:37