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
2// format # Copyright (C) 2002 # Associated Universities, Inc. Washington DC, USA.
3// #
4// # This library is free software; you can redistribute it and/or modify it
5// # under the terms of the GNU Library General Public License as published by
6// # the Free Software Foundation; either version 2 of the License, or (at your
7// # option) any later version.
8// #
9// # This library is distributed in the hope that it will be useful, but WITHOUT
10// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12// # License for more details.
13// #
14// # You should have received a copy of the GNU Library General Public License
15// # along with this library; if not, write to the Free Software Foundation,
16// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17// #
18// # Correspondence concerning AIPS++ should be addressed as follows:
19// # Internet email: casa-feedback@nrao.edu.
20// # Postal address: AIPS++ Project Office
21// # National Radio Astronomy Observatory
22// # 520 Edgemont Road
23// # Charlottesville, VA 22903-2475 USA
24
25#ifndef CASA_LECANONICALCONVERSION_H
26#define CASA_LECANONICALCONVERSION_H
27
28// # Includes
29#include <casacore/casa/aips.h>
30#include <casacore/casa/OS/Conversion.h>
31#include <cstring>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// Define the little endian canonical sizes of the built-in data types.
36// These are the same for all machine architectures.
37
38#define SIZE_LECAN_CHAR 1
39#define SIZE_LECAN_UCHAR 1
40#define SIZE_LECAN_SHORT 2
41#define SIZE_LECAN_USHORT 2
42#define SIZE_LECAN_INT 4
43#define SIZE_LECAN_UINT 4
44#define SIZE_LECAN_INT64 8
45#define SIZE_LECAN_UINT64 8
46#define SIZE_LECAN_FLOAT 4
47#define SIZE_LECAN_DOUBLE 8
48// #//define SIZE_LECAN_LDOUBLE 16
49
50// Define for each data format if a conversion is needed from the
51// local format to the little endian canonical format (or vice-versa).
52// This allows for optimizations in, for example, AipsIO.
53// The canonical format is ASCII for strings, IEEE for floating point
54// and 2-complement for integers (all most significant bit last)
55// with the lengths as shown above.
56// The function checkConvert() can be used to check if the flags are
57// set correctly.
58
59// Conversion is needed for big endian architectures (like SUN),
60// because the bytes have to be swapped (thus not for data with length 1).
61#define CONVERT_LECAN_CHAR 0
62#define CONVERT_LECAN_UCHAR 0
63
64#if !defined(AIPS_LITTLE_ENDIAN)
65#define CONVERT_LECAN_SHORT 1
66#define CONVERT_LECAN_USHORT 1
67#define CONVERT_LECAN_INT 1
68#define CONVERT_LECAN_UINT 1
69#define CONVERT_LECAN_INT64 1
70#define CONVERT_LECAN_UINT64 1
71#define CONVERT_LECAN_FLOAT 1
72#define CONVERT_LECAN_DOUBLE 1
73// #//# define CONVERT_LECAN_LDOUBLE 1
74#else
75
76// Conversion is not needed for IEEE data.
77// Change the definitions below if new architectures are being used.
78#define CONVERT_LECAN_SHORT 0
79#define CONVERT_LECAN_USHORT 0
80#define CONVERT_LECAN_INT 0
81#define CONVERT_LECAN_UINT 0
82#define CONVERT_LECAN_INT64 0
83#define CONVERT_LECAN_UINT64 0
84#define CONVERT_LECAN_FLOAT 0
85#define CONVERT_LECAN_DOUBLE 0
86// LDOUBLE is 8 bytes on SUN, but 16 bytes canonical.
87// #//# define CONVERT_LECAN_LDOUBLE 1
88#endif
89
90// <summary>
91// A class with static functions to convert little endian canonical format
92// </summary>
93
94// <use visibility=export>
95
96// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tLECanonicalConversion" demos="">
97// </reviewed>
98
99// <synopsis>
100// This class consists of several static functions to convert
101// data from local (=native) format to a little endian canonical format.
102// The canonical length of each data type is:
103// <br>- Bool: 1 bit
104// <br>- char: 1 byte
105// <br>- short: 2 bytes
106// <br>- int: 4 bytes
107// <br>- Int64: 8 bytes
108// <br>- float: 4 bytes
109// <br>- double: 8 bytes
110// <br> This canonical format is little-endian IEEE format, so on PCs
111// the conversion is only a copy operation. On e.g. SUNs
112// however, it involves a byte swap to convert from little
113// endian to big endian.
114// <p>
115// The class also contains conversion functions making it possible to
116// specify the number of bytes (in local format) instead of the number
117// of values. These functions are included to make it possible to have
118// the same signature as memcpy.
119// <p>
120// The current implementation of this class works on big- and little-endian
121// machines using IEEE format. When using on other machines (e.g. VAX)
122// the toLocal and fromLocal functions have to be changed.
123// <p>
124// Note that no functions are provided to handle Bools. Instead class
125// <linkto class=Conversion>Conversion</linkto> provides functions to
126// convert Bools to/from bits.
127// </synopsis>
128
129// <example>
130// <srcblock>
131// void someFunction (const uInt* data, uInt nrval)
132// {
133// char* buffer = new char[nrval*LECanonicalConversion::canonicalSize(data)];
134// LECanonicalConversion::fromLocal (buffer, data, nrval);
135// ....
136// delete [] buffer;
137// }
138// </srcblock>
139// </example>
140
141// <motivation>
142// Casacore data will often be stored in a canonical format.
143// To read these data conversion functions are needed.
144// However, these functions do not use any other Casacore classes,
145// so they can easily be used in any other software system.
146// </motivation>
147
148// <todo asof="$DATE$">
149// <li> Support data type long double.
150// </todo>
151
153 public:
154 // Convert one value from canonical format to local format.
155 // The from and to buffer should not overlap.
156 // <group>
157 static size_t toLocal(char& to, const void* from);
158 static size_t toLocal(unsigned char& to, const void* from);
159 static size_t toLocal(short& to, const void* from);
160 static size_t toLocal(unsigned short& to, const void* from);
161 static size_t toLocal(int& to, const void* from);
162 static size_t toLocal(unsigned int& to, const void* from);
163 static size_t toLocal(Int64& to, const void* from);
164 static size_t toLocal(uInt64& to, const void* from);
165 static size_t toLocal(float& to, const void* from);
166 static size_t toLocal(double& to, const void* from);
167 // </group>
168
169 // Convert one value from local format to canonical format.
170 // The from and to buffer should not overlap.
171 // <group>
172 static size_t fromLocal(void* to, const char& from);
173 static size_t fromLocal(void* to, const unsigned char& from);
174 static size_t fromLocal(void* to, const short& from);
175 static size_t fromLocal(void* to, const unsigned short& from);
176 static size_t fromLocal(void* to, const int& from);
177 static size_t fromLocal(void* to, const unsigned int& from);
178 static size_t fromLocal(void* to, const Int64& from);
179 static size_t fromLocal(void* to, const uInt64& from);
180 static size_t fromLocal(void* to, const float& from);
181 static size_t fromLocal(void* to, const double& from);
182 // </group>
183
184 // Convert nr values from canonical format to local format.
185 // The from and to buffer should not overlap.
186 // <group>
187 static size_t toLocal(char* to, const void* from, size_t nr);
188 static size_t toLocal(unsigned char* to, const void* from, size_t nr);
189 static size_t toLocal(short* to, const void* from, size_t nr);
190 static size_t toLocal(unsigned short* to, const void* from, size_t nr);
191 static size_t toLocal(int* to, const void* from, size_t nr);
192 static size_t toLocal(unsigned int* to, const void* from, size_t nr);
193 static size_t toLocal(Int64* to, const void* from, size_t nr);
194 static size_t toLocal(uInt64* to, const void* from, size_t nr);
195 static size_t toLocal(float* to, const void* from, size_t nr);
196 static size_t toLocal(double* to, const void* from, size_t nr);
197 // </group>
198
199 // Convert nr values from local format to canonical format.
200 // The from and to buffer should not overlap.
201 // <group>
202 static size_t fromLocal(void* to, const char* from, size_t nr);
203 static size_t fromLocal(void* to, const unsigned char* from, size_t nr);
204 static size_t fromLocal(void* to, const short* from, size_t nr);
205 static size_t fromLocal(void* to, const unsigned short* from, size_t nr);
206 static size_t fromLocal(void* to, const int* from, size_t nr);
207 static size_t fromLocal(void* to, const unsigned int* from, size_t nr);
208 static size_t fromLocal(void* to, const Int64* from, size_t nr);
209 static size_t fromLocal(void* to, const uInt64* from, size_t nr);
210 static size_t fromLocal(void* to, const float* from, size_t nr);
211 static size_t fromLocal(void* to, const double* from, size_t nr);
212 // </group>
213
214 // Convert nr values from canonical format to local format.
215 // The from and to buffer should not overlap.
216 // <group>
217 static size_t toLocalChar(void* to, const void* from, size_t nr);
218 static size_t toLocalUChar(void* to, const void* from, size_t nr);
219 static size_t toLocalShort(void* to, const void* from, size_t nr);
220 static size_t toLocalUShort(void* to, const void* from, size_t nr);
221 static size_t toLocalInt(void* to, const void* from, size_t nr);
222 static size_t toLocalUInt(void* to, const void* from, size_t nr);
223 static size_t toLocalInt64(void* to, const void* from, size_t nr);
224 static size_t toLocalUInt64(void* to, const void* from, size_t nr);
225 static size_t toLocalFloat(void* to, const void* from, size_t nr);
226 static size_t toLocalDouble(void* to, const void* from, size_t nr);
227 // </group>
228
229 // Convert nr values from local format to canonical format.
230 // The from and to buffer should not overlap.
231 // <group>
232 static size_t fromLocalChar(void* to, const void* from, size_t nr);
233 static size_t fromLocalUChar(void* to, const void* from, size_t nr);
234 static size_t fromLocalShort(void* to, const void* from, size_t nr);
235 static size_t fromLocalUShort(void* to, const void* from, size_t nr);
236 static size_t fromLocalInt(void* to, const void* from, size_t nr);
237 static size_t fromLocalUInt(void* to, const void* from, size_t nr);
238 static size_t fromLocalInt64(void* to, const void* from, size_t nr);
239 static size_t fromLocalUInt64(void* to, const void* from, size_t nr);
240 static size_t fromLocalFloat(void* to, const void* from, size_t nr);
241 static size_t fromLocalDouble(void* to, const void* from, size_t nr);
242 // </group>
243
244 // Convert values from canonical format to local format.
245 // The from and to buffer should not overlap.
246 // The number of values involved is determined from the argument
247 // <src>nrbytes</src>, which gives the number of bytes in local format.
248 // The signature of this function is the same as <src>memcpy</src>, so
249 // that memcpy can directly be used if no conversion is needed.
250 // <group>
251 static void* byteToLocalChar(void* to, const void* from, size_t nrbytes);
252 static void* byteToLocalUChar(void* to, const void* from, size_t nrbytes);
253 static void* byteToLocalShort(void* to, const void* from, size_t nrbytes);
254 static void* byteToLocalUShort(void* to, const void* from, size_t nrbytes);
255 static void* byteToLocalInt(void* to, const void* from, size_t nrbytes);
256 static void* byteToLocalUInt(void* to, const void* from, size_t nrbytes);
257 static void* byteToLocalInt64(void* to, const void* from, size_t nrbytes);
258 static void* byteToLocalUInt64(void* to, const void* from, size_t nrbytes);
259 static void* byteToLocalFloat(void* to, const void* from, size_t nrbytes);
260 static void* byteToLocalDouble(void* to, const void* from, size_t nrbytes);
261 // </group>
262
263 // Convert values from local format to canonical format.
264 // The from and to buffer should not overlap.
265 // The number of values involved is determined from the argument
266 // <src>nrbytes</src>, which gives the number of bytes in local format.
267 // The signature of this function is the same as <src>memcpy</src>, so
268 // that memcpy can directly be used if no conversion is needed.
269 // <group>
270 static void* byteFromLocalChar(void* to, const void* from, size_t nrbytes);
271 static void* byteFromLocalUChar(void* to, const void* from, size_t nrbytes);
272 static void* byteFromLocalShort(void* to, const void* from, size_t nrbytes);
273 static void* byteFromLocalUShort(void* to, const void* from, size_t nrbytes);
274 static void* byteFromLocalInt(void* to, const void* from, size_t nrbytes);
275 static void* byteFromLocalUInt(void* to, const void* from, size_t nrbytes);
276 static void* byteFromLocalInt64(void* to, const void* from, size_t nrbytes);
277 static void* byteFromLocalUInt64(void* to, const void* from, size_t nrbytes);
278 static void* byteFromLocalFloat(void* to, const void* from, size_t nrbytes);
279 static void* byteFromLocalDouble(void* to, const void* from, size_t nrbytes);
280 // </group>
281
282 // Get the value conversion function for the given type.
283 // <group>
284 static Conversion::ValueFunction* getToLocal(const char*);
285 static Conversion::ValueFunction* getToLocal(const unsigned char*);
286 static Conversion::ValueFunction* getToLocal(const short*);
287 static Conversion::ValueFunction* getToLocal(const unsigned short*);
288 static Conversion::ValueFunction* getToLocal(const int*);
289 static Conversion::ValueFunction* getToLocal(const unsigned int*);
292 static Conversion::ValueFunction* getToLocal(const float*);
293 static Conversion::ValueFunction* getToLocal(const double*);
294 static Conversion::ValueFunction* getFromLocal(const char*);
295 static Conversion::ValueFunction* getFromLocal(const unsigned char*);
296 static Conversion::ValueFunction* getFromLocal(const short*);
297 static Conversion::ValueFunction* getFromLocal(const unsigned short*);
298 static Conversion::ValueFunction* getFromLocal(const int*);
299 static Conversion::ValueFunction* getFromLocal(const unsigned int*);
302 static Conversion::ValueFunction* getFromLocal(const float*);
303 static Conversion::ValueFunction* getFromLocal(const double*);
304 // </group>
305
306 // Get the byte conversion function for the given type.
307 // The function <src>memcpy</src> is returned when a conversion
308 // is not needed.
309 // <group>
311 static Conversion::ByteFunction* getByteToLocal(const unsigned char*);
313 static Conversion::ByteFunction* getByteToLocal(const unsigned short*);
315 static Conversion::ByteFunction* getByteToLocal(const unsigned int*);
321 static Conversion::ByteFunction* getByteFromLocal(const unsigned char*);
323 static Conversion::ByteFunction* getByteFromLocal(const unsigned short*);
325 static Conversion::ByteFunction* getByteFromLocal(const unsigned int*);
330 // </group>
331
332 // Return the canonical length for the various data types.
333 // <group>
334 static unsigned int canonicalSize(const char*);
335 static unsigned int canonicalSize(const unsigned char*);
336 static unsigned int canonicalSize(const short*);
337 static unsigned int canonicalSize(const unsigned short*);
338 static unsigned int canonicalSize(const int*);
339 static unsigned int canonicalSize(const unsigned int*);
340 static unsigned int canonicalSize(const Int64*);
341 static unsigned int canonicalSize(const uInt64*);
342 static unsigned int canonicalSize(const float*);
343 static unsigned int canonicalSize(const double*);
344 // #//static unsigned int canonicalSize (const long double*);
345 // </group>
346
347 // Reverse 2 bytes.
348 static void reverse2(void* to, const void* from);
349
350 // Reverse 4 bytes.
351 static void reverse4(void* to, const void* from);
352
353 // Reverse 8 bytes.
354 static void reverse8(void* to, const void* from);
355
356 // Move 2 bytes.
357 static void move2(void* to, const void* from);
358
359 // Move 4 bytes.
360 static void move4(void* to, const void* from);
361
362 // Move 8 bytes.
363 static void move8(void* to, const void* from);
364
365 private:
366 // This class should not be constructed
367 // (so declare the constructor private).
369};
370
371inline void LECanonicalConversion::reverse2(void* to, const void* from) {
372 unsigned short x, xsw;
373 memcpy(&x, from, 2);
374 xsw = ((x & 0xffu) << 8u) | (x >> 8u);
375 memcpy(to, &xsw, 2);
376}
377
378inline void LECanonicalConversion::reverse4(void* to, const void* from) {
379 unsigned int x, xsw;
380 memcpy(&x, from, 4);
381#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
382 xsw = __builtin_bswap32(x);
383#else
384 xsw = ((x & 0xffu) << 24u) | ((x & 0xff00u) << 8u) | ((x & 0xff0000u) >> 8u) | (x >> 24u);
385#endif
386 memcpy(to, &xsw, 4);
387}
388
389inline void LECanonicalConversion::reverse8(void* to, const void* from) {
390 uInt64 x, xsw;
391 memcpy(&x, from, 8);
392#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
393 xsw = __builtin_bswap64(x);
394#else
395 xsw = ((x & 0xffULL) << 56ULL) | ((x & 0xff00ULL) << 40ULL) | ((x & 0xff0000ULL) << 24ULL) |
396 ((x & 0xff000000ULL) << 8ULL) | ((x & 0xff00000000ULL) >> 8ULL) |
397 ((x & 0xff0000000000ULL) >> 24ULL) | ((x & 0xff000000000000ULL) >> 40ULL) | (x >> 56ULL);
398#endif
399 memcpy(to, &xsw, 8);
400}
401
402inline void LECanonicalConversion::move2(void* to, const void* from) { memcpy(to, from, 2); }
403
404inline void LECanonicalConversion::move4(void* to, const void* from) { memcpy(to, from, 4); }
405
406inline void LECanonicalConversion::move8(void* to, const void* from) {
407 /* memcpy is overlap save if size fits into a register */
408 if (sizeof(to) < 8) {
409 memmove(to, from, 8);
410 } else {
411 memcpy(to, from, 8);
412 }
413}
414
415inline size_t LECanonicalConversion::toLocal(char& to, const void* from) {
416 to = *(char*)from;
417 return SIZE_LECAN_CHAR;
418}
419
420inline size_t LECanonicalConversion::toLocal(unsigned char& to, const void* from) {
421 to = *(unsigned char*)from;
422 return SIZE_LECAN_UCHAR;
423}
424
425inline size_t LECanonicalConversion::toLocal(short& to, const void* from) {
426 if (sizeof(short) != 2) {
427 if (((signed char*)from)[0] < 0) {
428 to = -1;
429 } else {
430 to = 0;
431 }
432 }
433#if !defined(AIPS_LITTLE_ENDIAN)
434 reverse2(&to, from);
435#else
436 move2(((char*)&to) + sizeof(short) - 2, from);
437#endif
438 return SIZE_LECAN_SHORT;
439}
440
441inline size_t LECanonicalConversion::toLocal(unsigned short& to, const void* from) {
442 if (sizeof(unsigned short) != 2) {
443 to = 0;
444 }
445#if !defined(AIPS_LITTLE_ENDIAN)
446 reverse2(&to, from);
447#else
448 move2(((char*)&to) + sizeof(unsigned short) - 2, from);
449#endif
450 return SIZE_LECAN_USHORT;
451}
452
453inline size_t LECanonicalConversion::toLocal(int& to, const void* from) {
454 if (sizeof(int) != 4) {
455 if (((signed char*)from)[0] < 0) {
456 to = -1;
457 } else {
458 to = 0;
459 }
460 }
461#if !defined(AIPS_LITTLE_ENDIAN)
462 reverse4(&to, from);
463#else
464 move4(((char*)&to) + sizeof(int) - 4, from);
465#endif
466 return SIZE_LECAN_INT;
467}
468
469inline size_t LECanonicalConversion::toLocal(unsigned int& to, const void* from) {
470 if (sizeof(unsigned int) != 4) {
471 to = 0;
472 }
473#if !defined(AIPS_LITTLE_ENDIAN)
474 reverse4(&to, from);
475#else
476 move4(((char*)&to) + sizeof(unsigned int) - 4, from);
477#endif
478 return SIZE_LECAN_UINT;
479}
480
481inline size_t LECanonicalConversion::toLocal(Int64& to, const void* from) {
482 if (sizeof(Int64) != 8) {
483 if (((signed char*)from)[0] < 0) {
484 to = -1;
485 } else {
486 to = 0;
487 }
488 }
489#if !defined(AIPS_LITTLE_ENDIAN)
490 reverse8(&to, from);
491#else
492 move8(((char*)&to) + sizeof(Int64) - 8, from);
493#endif
494 return SIZE_LECAN_INT64;
495}
496
497inline size_t LECanonicalConversion::toLocal(uInt64& to, const void* from) {
498 if (sizeof(uInt64) != 8) {
499 to = 0;
500 }
501#if !defined(AIPS_LITTLE_ENDIAN)
502 reverse8(&to, from);
503#else
504 move8(((char*)&to) + sizeof(uInt64) - 8, from);
505#endif
506 return SIZE_LECAN_UINT64;
507}
508
509inline size_t LECanonicalConversion::toLocal(float& to, const void* from) {
510#if !defined(AIPS_LITTLE_ENDIAN)
511 reverse4(((char*)&to) + sizeof(float) - 4, from);
512#else
513 move4(&to, from);
514#endif
515 return SIZE_LECAN_FLOAT;
516}
517
518inline size_t LECanonicalConversion::toLocal(double& to, const void* from) {
519#if !defined(AIPS_LITTLE_ENDIAN)
520 reverse8(((char*)&to) + sizeof(double) - 8, from);
521#else
522 move8(&to, from);
523#endif
524 return SIZE_LECAN_DOUBLE;
525}
526
527inline size_t LECanonicalConversion::fromLocal(void* to, const char& from) {
528 *(char*)to = from;
529 return SIZE_LECAN_CHAR;
530}
531inline size_t LECanonicalConversion::fromLocal(void* to, const unsigned char& from) {
532 *(unsigned char*)to = from;
533 return SIZE_LECAN_UCHAR;
534}
535
536inline size_t LECanonicalConversion::fromLocal(void* to, const short& from) {
537#if !defined(AIPS_LITTLE_ENDIAN)
538 reverse2(to, &from);
539#else
540 move2(to, ((char*)&from) + sizeof(short) - 2);
541#endif
542 return SIZE_LECAN_SHORT;
543}
544
545inline size_t LECanonicalConversion::fromLocal(void* to, const unsigned short& from) {
546#if !defined(AIPS_LITTLE_ENDIAN)
547 reverse2(to, &from);
548#else
549 move2(to, ((char*)&from) + sizeof(unsigned short) - 2);
550#endif
551 return SIZE_LECAN_USHORT;
552}
553
554inline size_t LECanonicalConversion::fromLocal(void* to, const int& from) {
555#if !defined(AIPS_LITTLE_ENDIAN)
556 reverse4(to, &from);
557#else
558 move4(to, ((char*)&from) + sizeof(int) - 4);
559#endif
560 return SIZE_LECAN_INT;
561}
562
563inline size_t LECanonicalConversion::fromLocal(void* to, const unsigned int& from) {
564#if !defined(AIPS_LITTLE_ENDIAN)
565 reverse4(to, &from);
566#else
567 move4(to, ((char*)&from) + sizeof(unsigned int) - 4);
568#endif
569 return SIZE_LECAN_UINT;
570}
571
572inline size_t LECanonicalConversion::fromLocal(void* to, const Int64& from) {
573#if !defined(AIPS_LITTLE_ENDIAN)
574 reverse8(to, &from);
575#else
576 move8(to, ((char*)&from) + sizeof(Int64) - 8);
577#endif
578 return SIZE_LECAN_INT64;
579}
580
581inline size_t LECanonicalConversion::fromLocal(void* to, const uInt64& from) {
582#if !defined(AIPS_LITTLE_ENDIAN)
583 reverse8(to, &from);
584#else
585 move8(to, ((char*)&from) + sizeof(uInt64) - 8);
586#endif
587 return SIZE_LECAN_UINT64;
588}
589
590inline size_t LECanonicalConversion::fromLocal(void* to, const float& from) {
591#if !defined(AIPS_LITTLE_ENDIAN)
592 reverse4(to, &from);
593#else
594 move4(to, &from);
595#endif
596 return SIZE_LECAN_FLOAT;
597}
598
599inline size_t LECanonicalConversion::fromLocal(void* to, const double& from) {
600#if !defined(AIPS_LITTLE_ENDIAN)
601 reverse8(to, &from);
602#else
603 move8(to, &from);
604#endif
605 return SIZE_LECAN_FLOAT;
606}
607
608inline size_t LECanonicalConversion::toLocal(char* to, const void* from, size_t nr) {
609 return toLocalChar(to, from, nr);
610}
611inline size_t LECanonicalConversion::toLocal(unsigned char* to, const void* from, size_t nr) {
612 return toLocalUChar(to, from, nr);
613}
614inline size_t LECanonicalConversion::toLocal(short* to, const void* from, size_t nr) {
615 return toLocalShort(to, from, nr);
616}
617inline size_t LECanonicalConversion::toLocal(unsigned short* to, const void* from, size_t nr) {
618 return toLocalUShort(to, from, nr);
619}
620inline size_t LECanonicalConversion::toLocal(int* to, const void* from, size_t nr) {
621 return toLocalInt(to, from, nr);
622}
623inline size_t LECanonicalConversion::toLocal(unsigned int* to, const void* from, size_t nr) {
624 return toLocalUInt(to, from, nr);
625}
626inline size_t LECanonicalConversion::toLocal(Int64* to, const void* from, size_t nr) {
627 return toLocalInt64(to, from, nr);
628}
629inline size_t LECanonicalConversion::toLocal(uInt64* to, const void* from, size_t nr) {
630 return toLocalUInt64(to, from, nr);
631}
632inline size_t LECanonicalConversion::toLocal(float* to, const void* from, size_t nr) {
633 return toLocalFloat(to, from, nr);
634}
635inline size_t LECanonicalConversion::toLocal(double* to, const void* from, size_t nr) {
636 return toLocalDouble(to, from, nr);
637}
638
639inline size_t LECanonicalConversion::fromLocal(void* to, const char* from, size_t nr) {
640 return fromLocalChar(to, from, nr);
641}
642inline size_t LECanonicalConversion::fromLocal(void* to, const unsigned char* from, size_t nr) {
643 return fromLocalUChar(to, from, nr);
644}
645inline size_t LECanonicalConversion::fromLocal(void* to, const short* from, size_t nr) {
646 return fromLocalShort(to, from, nr);
647}
648inline size_t LECanonicalConversion::fromLocal(void* to, const unsigned short* from, size_t nr) {
649 return fromLocalUShort(to, from, nr);
650}
651inline size_t LECanonicalConversion::fromLocal(void* to, const int* from, size_t nr) {
652 return fromLocalInt(to, from, nr);
653}
654inline size_t LECanonicalConversion::fromLocal(void* to, const unsigned int* from, size_t nr) {
655 return fromLocalUInt(to, from, nr);
656}
657inline size_t LECanonicalConversion::fromLocal(void* to, const Int64* from, size_t nr) {
658 return fromLocalInt64(to, from, nr);
659}
660inline size_t LECanonicalConversion::fromLocal(void* to, const uInt64* from, size_t nr) {
661 return fromLocalUInt64(to, from, nr);
662}
663inline size_t LECanonicalConversion::fromLocal(void* to, const float* from, size_t nr) {
664 return fromLocalFloat(to, from, nr);
665}
666inline size_t LECanonicalConversion::fromLocal(void* to, const double* from, size_t nr) {
667 return fromLocalDouble(to, from, nr);
668}
669
674 return toLocalUChar;
675}
680 return toLocalUShort;
681}
686 return toLocalUInt;
687}
700
705 return fromLocalUChar;
706}
711 return fromLocalUShort;
712}
731
732inline unsigned int LECanonicalConversion::canonicalSize(const char*) { return SIZE_LECAN_CHAR; }
733inline unsigned int LECanonicalConversion::canonicalSize(const unsigned char*) {
734 return SIZE_LECAN_UCHAR;
735}
736inline unsigned int LECanonicalConversion::canonicalSize(const short*) { return SIZE_LECAN_SHORT; }
737inline unsigned int LECanonicalConversion::canonicalSize(const unsigned short*) {
738 return SIZE_LECAN_USHORT;
739}
740inline unsigned int LECanonicalConversion::canonicalSize(const int*) { return SIZE_LECAN_INT; }
741inline unsigned int LECanonicalConversion::canonicalSize(const unsigned int*) {
742 return SIZE_LECAN_UINT;
743}
744inline unsigned int LECanonicalConversion::canonicalSize(const Int64*) { return SIZE_LECAN_INT64; }
745inline unsigned int LECanonicalConversion::canonicalSize(const uInt64*) {
746 return SIZE_LECAN_UINT64;
747}
748inline unsigned int LECanonicalConversion::canonicalSize(const float*) { return SIZE_LECAN_FLOAT; }
749inline unsigned int LECanonicalConversion::canonicalSize(const double*) {
750 return SIZE_LECAN_DOUBLE;
751}
752// #//inline unsigned int LECanonicalConversion::canonicalSize (const long double*)
753// #// {return SIZE_LECAN_LDOUBLE;}
754
755} // namespace casacore
756
757#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:95
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:102
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 *)
For temporary backward namespace compatibility, use casa as alias for casacore.
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