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