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