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