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