CanonicalConversion.h

Go to the documentation of this file.
00001 //# CanonicalConversion.h: A class with static functions to convert canonical format
00002 //# Copyright (C) 1996,1997,1999,2000,2001,2002
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef CASA_CANONICALCONVERSION_H
00029 #define CASA_CANONICALCONVERSION_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/OS/Conversion.h>
00034 #include <cstring>
00035 
00036 
00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00038 
00039 // Define the canonical sizes of the built-in data types.
00040 // These are the same for all machine architectures.
00041 // Also define the maximum size.
00042 
00043 #define SIZE_CAN_CHAR     1
00044 #define SIZE_CAN_UCHAR    1
00045 #define SIZE_CAN_SHORT    2
00046 #define SIZE_CAN_USHORT   2
00047 #define SIZE_CAN_INT      4
00048 #define SIZE_CAN_UINT     4
00049 #define SIZE_CAN_INT64    8
00050 #define SIZE_CAN_UINT64   8
00051 #define SIZE_CAN_FLOAT    4
00052 #define SIZE_CAN_DOUBLE   8
00053 //#//define SIZE_CAN_LDOUBLE 16
00054 
00055 
00056 // Define for each data format if a conversion is needed from the
00057 // local format to the canonical format (or vice-versa).
00058 // This allows for optimizations in, for example, AipsIO.
00059 // The canonical format is ASCII for strings, IEEE for floating point
00060 // and 2-complement for integers (all most significant bit first)
00061 // with the lengths as shown above.
00062 // The function checkConvert() can be used to check if the flags are
00063 // set correctly.
00064 
00065 // Conversion is needed for little endian architectures (like DEC and Intel),
00066 // because the bytes have to be swapped (thus not for data with length 1).
00067 #define CONVERT_CAN_CHAR     0
00068 #define CONVERT_CAN_UCHAR    0
00069 
00070 #if defined(AIPS_LITTLE_ENDIAN)
00071 #  define CONVERT_CAN_SHORT    1
00072 #  define CONVERT_CAN_USHORT   1
00073 #  define CONVERT_CAN_INT      1
00074 #  define CONVERT_CAN_UINT     1
00075 #  define CONVERT_CAN_INT64    1
00076 #  define CONVERT_CAN_UINT64   1
00077 #  define CONVERT_CAN_FLOAT    1
00078 #  define CONVERT_CAN_DOUBLE   1
00079 //#//#  define CONVERT_CAN_LDOUBLE  1
00080 #else
00081 
00082 // Conversion is not needed for IEEE data.
00083 // Change the definitions below if new architectures are being used.
00084 #  define CONVERT_CAN_SHORT    0
00085 #  define CONVERT_CAN_USHORT   0
00086 #  define CONVERT_CAN_INT      0
00087 #  define CONVERT_CAN_UINT     0
00088 #  define CONVERT_CAN_INT64    0
00089 #  define CONVERT_CAN_UINT64   0
00090 #  define CONVERT_CAN_FLOAT    0
00091 #  define CONVERT_CAN_DOUBLE   0
00092 // LDOUBLE is 8 bytes on SUN, but 16 bytes canonical.
00093 //#//#  define CONVERT_CAN_LDOUBLE  1
00094 #endif
00095 
00096 
00097 
00098 // <summary>
00099 // A class with static functions to convert canonical format
00100 // </summary>
00101 
00102 // <use visibility=export>
00103 
00104 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tCanonicalConversion" demos="">
00105 // </reviewed>
00106 
00107 // <synopsis>
00108 // This class consists of several static functions to convert
00109 // data from local (=native) format to a canonical format.
00110 // The canonical length of each data type is:
00111 // <br>- Bool: 1 bit
00112 // <br>- char: 1 byte
00113 // <br>- short: 2 bytes
00114 // <br>- int: 4 bytes
00115 // <br>- Int64: 8 bytes
00116 // <br>- float: 4 bytes
00117 // <br>- double: 8 bytes
00118 // <br> The canonical format is big-endian IEEE format, so on many machines
00119 // the conversion is only a copy operation. On Alpha- or Intel-based
00120 // machines, however, it involves a byte swap to convert from little
00121 // endian to big endian.
00122 // <p>
00123 // The class also contains conversion functions making it possible to
00124 // specify the number of bytes (in local format) instead of the number
00125 // of values. These functions are included to make it possible to have
00126 // the same signature as memcpy.
00127 // <p>
00128 // The current implementation of this class works on big- and little-endian
00129 // machines using IEEE format. When using on other machines (e.g. VAX)
00130 // the toLocal and fromLocal functions have to be changed.
00131 // <p>
00132 // Note that no functions are provided to handle Bools. Instead class
00133 // <linkto class=Conversion>Conversion</linkto> provides functions to
00134 // convert Bools to/from bits.
00135 // </synopsis>
00136 
00137 // <example>
00138 // <srcblock>
00139 // void someFunction (const uInt* data, uInt nrval)
00140 // {
00141 //     char* buffer = new char[nrval*CanonicalConversion::canonicalSize(data)];
00142 //     CanonicalConversion::fromLocal (buffer, data, nrval);
00143 //     ....
00144 //     delete [] buffer;
00145 // }
00146 // </srcblock>
00147 // </example>
00148 
00149 // <motivation>
00150 // Casacore data will often be stored in a canonical format.
00151 // To read these data conversion functions are needed.
00152 // However, these functions do not use any other Casacore classes,
00153 // so they can easily be used in any other software system.
00154 // </motivation>
00155 
00156 // <todo asof="$DATE$">
00157 //  <li> Support data type long double.
00158 // </todo>
00159 
00160 
00161 class CanonicalConversion
00162 {
00163 public:
00164     // Convert one value from canonical format to local format.
00165     // The from and to buffer should not overlap.
00166     // <group>
00167     static size_t toLocal (char&           to, const void* from);
00168     static size_t toLocal (unsigned char&  to, const void* from);
00169     static size_t toLocal (short&          to, const void* from);
00170     static size_t toLocal (unsigned short& to, const void* from);
00171     static size_t toLocal (int&            to, const void* from);
00172     static size_t toLocal (unsigned int&   to, const void* from);
00173     static size_t toLocal (Int64&          to, const void* from);
00174     static size_t toLocal (uInt64&         to, const void* from);
00175     static size_t toLocal (float&          to, const void* from);
00176     static size_t toLocal (double&         to, const void* from);
00177     // </group>
00178     
00179     // Convert one value from local format to canonical format.
00180     // The from and to buffer should not overlap.
00181     //# Note that the from value is passed by reference (and not by value),
00182     //# because the & operator applied to it is slowish if passed by value.
00183     // <group>
00184     static size_t fromLocal (void* to, const char&           from);
00185     static size_t fromLocal (void* to, const unsigned char&  from);
00186     static size_t fromLocal (void* to, const short&          from);
00187     static size_t fromLocal (void* to, const unsigned short& from);
00188     static size_t fromLocal (void* to, const int&            from);
00189     static size_t fromLocal (void* to, const unsigned int&   from);
00190     static size_t fromLocal (void* to, const Int64&          from);
00191     static size_t fromLocal (void* to, const uInt64&         from);
00192     static size_t fromLocal (void* to, const float&          from);
00193     static size_t fromLocal (void* to, const double&         from);
00194     // </group>
00195     
00196     // Convert nr values from canonical format to local format.
00197     // The from and to buffer should not overlap.
00198     // <group>
00199     static size_t toLocal (char*           to, const void* from,
00200                            size_t nr);
00201     static size_t toLocal (unsigned char*  to, const void* from,
00202                            size_t nr);
00203     static size_t toLocal (short*          to, const void* from,
00204                            size_t nr);
00205     static size_t toLocal (unsigned short* to, const void* from,
00206                            size_t nr);
00207     static size_t toLocal (int*            to, const void* from,
00208                            size_t nr);
00209     static size_t toLocal (unsigned int*   to, const void* from,
00210                            size_t nr);
00211     static size_t toLocal (Int64*          to, const void* from,
00212                            size_t nr);
00213     static size_t toLocal (uInt64*         to, const void* from,
00214                            size_t nr);
00215     static size_t toLocal (float*          to, const void* from,
00216                            size_t nr);
00217     static size_t toLocal (double*         to, const void* from,
00218                            size_t nr);
00219     // </group>
00220 
00221     // Convert nr values from local format to canonical format.
00222     // The from and to buffer should not overlap.
00223     // <group>
00224     static size_t fromLocal (void* to, const char*           from,
00225                              size_t nr);
00226     static size_t fromLocal (void* to, const unsigned char*  from,
00227                              size_t nr);
00228     static size_t fromLocal (void* to, const short*          from,
00229                              size_t nr);
00230     static size_t fromLocal (void* to, const unsigned short* from,
00231                              size_t nr);
00232     static size_t fromLocal (void* to, const int*            from,
00233                              size_t nr);
00234     static size_t fromLocal (void* to, const unsigned int*   from,
00235                              size_t nr);
00236     static size_t fromLocal (void* to, const Int64*          from,
00237                              size_t nr);
00238     static size_t fromLocal (void* to, const uInt64*         from,
00239                              size_t nr);
00240     static size_t fromLocal (void* to, const float*          from,
00241                              size_t nr);
00242     static size_t fromLocal (void* to, const double*         from,
00243                              size_t nr);
00244     // </group>
00245 
00246     // Convert nr values from canonical format to local format.
00247     // The from and to buffer should not overlap.
00248     // <group>
00249     static size_t toLocalChar     (void* to, const void* from,
00250                                    size_t nr);
00251     static size_t toLocalUChar    (void* to, const void* from,
00252                                    size_t nr);
00253     static size_t toLocalShort    (void* to, const void* from,
00254                                    size_t nr);
00255     static size_t toLocalUShort   (void* to, const void* from,
00256                                    size_t nr);
00257     static size_t toLocalInt      (void* to, const void* from,
00258                                    size_t nr);
00259     static size_t toLocalUInt     (void* to, const void* from,
00260                                    size_t nr);
00261     static size_t toLocalInt64    (void* to, const void* from,
00262                                    size_t nr);
00263     static size_t toLocalUInt64   (void* to, const void* from,
00264                                    size_t nr);
00265     static size_t toLocalFloat    (void* to, const void* from,
00266                                    size_t nr);
00267     static size_t toLocalDouble   (void* to, const void* from,
00268                                    size_t nr);
00269     // </group>
00270 
00271     // Convert nr values from local format to canonical format.
00272     // The from and to buffer should not overlap.
00273     // <group>
00274     static size_t fromLocalChar     (void* to, const void* from,
00275                                      size_t nr);
00276     static size_t fromLocalUChar    (void* to, const void* from,
00277                                      size_t nr);
00278     static size_t fromLocalShort    (void* to, const void* from,
00279                                      size_t nr);
00280     static size_t fromLocalUShort   (void* to, const void* from,
00281                                      size_t nr);
00282     static size_t fromLocalInt      (void* to, const void* from,
00283                                      size_t nr);
00284     static size_t fromLocalUInt     (void* to, const void* from,
00285                                      size_t nr);
00286     static size_t fromLocalInt64    (void* to, const void* from,
00287                                      size_t nr);
00288     static size_t fromLocalUInt64   (void* to, const void* from,
00289                                      size_t nr);
00290     static size_t fromLocalFloat    (void* to, const void* from,
00291                                      size_t nr);
00292     static size_t fromLocalDouble   (void* to, const void* from,
00293                                      size_t nr);
00294     // </group>
00295     
00296     // Convert values from canonical format to local format.
00297     // The from and to buffer should not overlap.
00298     // The number of values involved is determined from the argument
00299     // <src>nrbytes</src>, which gives the number of bytes in local format.
00300     // The signature of this function is the same as <src>memcpy</src>, so
00301     // that memcpy can directly be used if no conversion is needed.
00302     // <group>
00303     static void* byteToLocalChar     (void* to, const void* from,
00304                                       size_t nrbytes);
00305     static void* byteToLocalUChar    (void* to, const void* from,
00306                                       size_t nrbytes);
00307     static void* byteToLocalShort    (void* to, const void* from,
00308                                       size_t nrbytes);
00309     static void* byteToLocalUShort   (void* to, const void* from,
00310                                       size_t nrbytes);
00311     static void* byteToLocalInt      (void* to, const void* from,
00312                                       size_t nrbytes);
00313     static void* byteToLocalUInt     (void* to, const void* from,
00314                                       size_t nrbytes);
00315     static void* byteToLocalInt64    (void* to, const void* from,
00316                                       size_t nrbytes);
00317     static void* byteToLocalUInt64   (void* to, const void* from,
00318                                       size_t nrbytes);
00319     static void* byteToLocalFloat    (void* to, const void* from,
00320                                       size_t nrbytes);
00321     static void* byteToLocalDouble   (void* to, const void* from,
00322                                       size_t nrbytes);
00323     // </group>
00324     
00325     // Convert values from local format to canonical format.
00326     // The from and to buffer should not overlap.
00327     // The number of values involved is determined from the argument
00328     // <src>nrbytes</src>, which gives the number of bytes in local format.
00329     // The signature of this function is the same as <src>memcpy</src>, so
00330     // that memcpy can directly be used if no conversion is needed.
00331     // <group>
00332     static void* byteFromLocalChar     (void* to, const void* from,
00333                                         size_t nrbytes);
00334     static void* byteFromLocalUChar    (void* to, const void* from,
00335                                         size_t nrbytes);
00336     static void* byteFromLocalShort    (void* to, const void* from,
00337                                         size_t nrbytes);
00338     static void* byteFromLocalUShort   (void* to, const void* from,
00339                                         size_t nrbytes);
00340     static void* byteFromLocalInt      (void* to, const void* from,
00341                                         size_t nrbytes);
00342     static void* byteFromLocalUInt     (void* to, const void* from,
00343                                         size_t nrbytes);
00344     static void* byteFromLocalInt64    (void* to, const void* from,
00345                                         size_t nrbytes);
00346     static void* byteFromLocalUInt64   (void* to, const void* from,
00347                                         size_t nrbytes);
00348     static void* byteFromLocalFloat    (void* to, const void* from,
00349                                         size_t nrbytes);
00350     static void* byteFromLocalDouble   (void* to, const void* from,
00351                                         size_t nrbytes);
00352     // </group>
00353     
00354     // Get the value conversion function for the given type.
00355     // <group>
00356     static Conversion::ValueFunction* getToLocal (const char*);
00357     static Conversion::ValueFunction* getToLocal (const unsigned char*);
00358     static Conversion::ValueFunction* getToLocal (const short*);
00359     static Conversion::ValueFunction* getToLocal (const unsigned short*);
00360     static Conversion::ValueFunction* getToLocal (const int*);
00361     static Conversion::ValueFunction* getToLocal (const unsigned int*);
00362     static Conversion::ValueFunction* getToLocal (const Int64*);
00363     static Conversion::ValueFunction* getToLocal (const uInt64*);
00364     static Conversion::ValueFunction* getToLocal (const float*);
00365     static Conversion::ValueFunction* getToLocal (const double*);
00366     static Conversion::ValueFunction* getFromLocal (const char*);
00367     static Conversion::ValueFunction* getFromLocal (const unsigned char*);
00368     static Conversion::ValueFunction* getFromLocal (const short*);
00369     static Conversion::ValueFunction* getFromLocal (const unsigned short*);
00370     static Conversion::ValueFunction* getFromLocal (const int*);
00371     static Conversion::ValueFunction* getFromLocal (const unsigned int*);
00372     static Conversion::ValueFunction* getFromLocal (const Int64*);
00373     static Conversion::ValueFunction* getFromLocal (const uInt64*);
00374     static Conversion::ValueFunction* getFromLocal (const float*);
00375     static Conversion::ValueFunction* getFromLocal (const double*);
00376     // </group>
00377 
00378     // Get the byte conversion function for the given type.
00379     // The function <src>memcpy</src> is returned when a conversion
00380     // is not needed.
00381     // <group>
00382     static Conversion::ByteFunction* getByteToLocal (const char*);
00383     static Conversion::ByteFunction* getByteToLocal (const unsigned char*);
00384     static Conversion::ByteFunction* getByteToLocal (const short*);
00385     static Conversion::ByteFunction* getByteToLocal (const unsigned short*);
00386     static Conversion::ByteFunction* getByteToLocal (const int*);
00387     static Conversion::ByteFunction* getByteToLocal (const unsigned int*);
00388     static Conversion::ByteFunction* getByteToLocal (const Int64*);
00389     static Conversion::ByteFunction* getByteToLocal (const uInt64*);
00390     static Conversion::ByteFunction* getByteToLocal (const float*);
00391     static Conversion::ByteFunction* getByteToLocal (const double*);
00392     static Conversion::ByteFunction* getByteFromLocal (const char*);
00393     static Conversion::ByteFunction* getByteFromLocal (const unsigned char*);
00394     static Conversion::ByteFunction* getByteFromLocal (const short*);
00395     static Conversion::ByteFunction* getByteFromLocal (const unsigned short*);
00396     static Conversion::ByteFunction* getByteFromLocal (const int*);
00397     static Conversion::ByteFunction* getByteFromLocal (const unsigned int*);
00398     static Conversion::ByteFunction* getByteFromLocal (const Int64*);
00399     static Conversion::ByteFunction* getByteFromLocal (const uInt64*);
00400     static Conversion::ByteFunction* getByteFromLocal (const float*);
00401     static Conversion::ByteFunction* getByteFromLocal (const double*);
00402     // </group>
00403 
00404     // Return the canonical length for the various data types.
00405     // <group>
00406     static unsigned int canonicalSize (const char*);
00407     static unsigned int canonicalSize (const unsigned char*);
00408     static unsigned int canonicalSize (const short*);
00409     static unsigned int canonicalSize (const unsigned short*);
00410     static unsigned int canonicalSize (const int*);
00411     static unsigned int canonicalSize (const unsigned int*);
00412     static unsigned int canonicalSize (const Int64*);
00413     static unsigned int canonicalSize (const uInt64*);
00414     static unsigned int canonicalSize (const float*);
00415     static unsigned int canonicalSize (const double*);
00416     //#//static unsigned int canonicalSize (const long double*);
00417     // </group>
00418 
00419     // Reverse 2 bytes.
00420     static void reverse2 (void* to, const void* from);
00421 
00422     // Reverse 4 bytes.
00423     static void reverse4 (void* to, const void* from);
00424 
00425     // Reverse 8 bytes.
00426     static void reverse8 (void* to, const void* from);
00427 
00428     // Move 2 bytes.
00429     static void move2 (void* to, const void* from);
00430 
00431     // Move 4 bytes.
00432     static void move4 (void* to, const void* from);
00433 
00434     // Move 8 bytes.
00435     static void move8 (void* to, const void* from);
00436 
00437 private:
00438     // This class should not be constructed
00439     // (so declare the constructor private).
00440     CanonicalConversion();
00441 };
00442 
00443 
00444 inline void CanonicalConversion::reverse2 (void* to, const void* from)
00445 {
00446     unsigned short x, xsw;
00447     memcpy(&x, from, 2);
00448     xsw = ((x & 0xffu) << 8u) | (x >> 8u);
00449     memcpy(to, &xsw, 2);
00450 }
00451 
00452 inline void CanonicalConversion::reverse4 (void* to, const void* from)
00453 {
00454     unsigned int x, xsw;
00455     memcpy(&x, from, 4);
00456 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
00457     xsw = __builtin_bswap32(x);
00458 #else
00459     xsw = ((x & 0xffu) << 24u) | ((x & 0xff00u) << 8u) |
00460           ((x & 0xff0000u) >> 8u) | (x >> 24u);
00461 #endif
00462     memcpy(to, &xsw, 4);
00463 }
00464 
00465 inline void CanonicalConversion::reverse8 (void* to, const void* from)
00466 {
00467     uInt64 x, xsw;
00468     memcpy(&x, from, 8);
00469 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
00470     xsw = __builtin_bswap64(x);
00471 #else
00472     xsw = ((x & 0xffULL) << 56ULL) |
00473           ((x & 0xff00ULL) << 40ULL) |
00474           ((x & 0xff0000ULL) << 24ULL) |
00475           ((x & 0xff000000ULL) << 8ULL) |
00476           ((x & 0xff00000000ULL) >> 8ULL) |
00477           ((x & 0xff0000000000ULL) >> 24ULL) |
00478           ((x & 0xff000000000000ULL) >> 40ULL) |
00479           ( x >> 56ULL);
00480 #endif
00481     memcpy(to, &xsw, 8);
00482 }
00483 
00484 inline void CanonicalConversion::move2 (void* to, const void* from)
00485 {
00486     memcpy(to, from, 2);
00487 }
00488 
00489 inline void CanonicalConversion::move4 (void* to, const void* from)
00490 {
00491     memcpy(to, from, 4);
00492 }
00493 
00494 inline void CanonicalConversion::move8 (void* to, const void* from)
00495 {
00496     /* memcpy is overlap save if size fits into a register */
00497     if (sizeof(to) < 8) {
00498         memmove(to, from, 8);
00499     }
00500     else {
00501         memcpy(to, from, 8);
00502     }
00503 }
00504 
00505 
00506 
00507 inline size_t CanonicalConversion::toLocal (char& to, const void* from)
00508 {
00509     to = *(char*)from;
00510     return SIZE_CAN_CHAR;
00511 }
00512 
00513 inline size_t CanonicalConversion::toLocal (unsigned char& to,
00514                                             const void* from)
00515 {
00516     to = *(unsigned char*)from;
00517     return SIZE_CAN_UCHAR;
00518 }
00519 
00520 inline size_t CanonicalConversion::toLocal (short& to, const void* from)
00521 {
00522     if (sizeof(short) != 2) {
00523         if (((signed char*)from)[0] < 0) {
00524             to = -1;
00525         }else{
00526             to = 0;
00527         }
00528     }
00529 #if defined(AIPS_LITTLE_ENDIAN)
00530     reverse2 (&to, from);
00531 #else
00532     move2 (((char*)&to)+sizeof(short)-2, from);
00533 #endif
00534     return SIZE_CAN_SHORT;
00535 }
00536 
00537 inline size_t CanonicalConversion::toLocal (unsigned short& to,
00538                                             const void* from)
00539 {
00540     if (sizeof(unsigned short) != 2) {
00541         to = 0;
00542     }
00543 #if defined(AIPS_LITTLE_ENDIAN)
00544     reverse2 (&to, from);
00545 #else
00546     move2 (((char*)&to)+sizeof(unsigned short)-2, from);
00547 #endif
00548     return SIZE_CAN_USHORT;
00549 }
00550 
00551 inline size_t CanonicalConversion::toLocal (int& to, const void* from)
00552 {
00553     if (sizeof(int) != 4) {
00554         if (((signed char*)from)[0] < 0) {
00555             to = -1;
00556         }else{
00557             to = 0;
00558         }
00559     }
00560 #if defined(AIPS_LITTLE_ENDIAN)
00561     reverse4 (&to, from);
00562 #else
00563     move4 (((char*)&to)+sizeof(int)-4, from);
00564 #endif
00565     return SIZE_CAN_INT;
00566 }
00567 
00568 inline size_t CanonicalConversion::toLocal (unsigned int& to,
00569                                             const void* from)
00570 {
00571     if (sizeof(unsigned int) != 4) {
00572         to = 0;
00573     }
00574 #if defined(AIPS_LITTLE_ENDIAN)
00575     reverse4 (&to, from);
00576 #else
00577     move4 (((char*)&to)+sizeof(unsigned int)-4, from);
00578 #endif
00579     return SIZE_CAN_UINT;
00580 }
00581 
00582 inline size_t CanonicalConversion::toLocal (Int64& to, const void* from)
00583 {
00584     if (sizeof(Int64) != 8) {
00585         if (((signed char*)from)[0] < 0) {
00586             to = -1;
00587         }else{
00588             to = 0;
00589         }
00590     }
00591 #if defined(AIPS_LITTLE_ENDIAN)
00592     reverse8 (&to, from);
00593 #else
00594     move8 (((char*)&to)+sizeof(Int64)-8, from);
00595 #endif
00596     return SIZE_CAN_INT64;
00597 }
00598 
00599 inline size_t CanonicalConversion::toLocal (uInt64& to, const void* from)
00600 {
00601     if (sizeof(uInt64) != 8) {
00602         to = 0;
00603     }
00604 #if defined(AIPS_LITTLE_ENDIAN)
00605     reverse8 (&to, from);
00606 #else
00607     move8 (((char*)&to)+sizeof(uInt64)-8, from);
00608 #endif
00609     return SIZE_CAN_UINT64;
00610 }
00611 
00612 inline size_t CanonicalConversion::toLocal (float& to, const void* from)
00613 {
00614 #if defined(AIPS_LITTLE_ENDIAN)
00615     reverse4 (((char*)&to)+sizeof(float)-4, from);
00616 #else
00617     move4 (&to, from);
00618 #endif
00619     return SIZE_CAN_FLOAT;
00620 }
00621 
00622 inline size_t CanonicalConversion::toLocal (double& to, const void* from)
00623 {
00624 #if defined(AIPS_LITTLE_ENDIAN)
00625     reverse8 (((char*)&to)+sizeof(double)-8, from);
00626 #else
00627     move8 (&to, from);
00628 #endif
00629     return SIZE_CAN_DOUBLE;
00630 }
00631 
00632 
00633 inline size_t CanonicalConversion::fromLocal (void* to,
00634                                               const char& from)
00635 {
00636     *(char*)to = from;
00637     return SIZE_CAN_CHAR;
00638 }
00639 inline size_t CanonicalConversion::fromLocal (void* to,
00640                                               const unsigned char& from)
00641 {
00642     *(unsigned char*)to = from;
00643     return SIZE_CAN_UCHAR;
00644 }
00645 
00646 inline size_t CanonicalConversion::fromLocal (void* to,
00647                                               const short& from)
00648 {
00649 #if defined(AIPS_LITTLE_ENDIAN)
00650     reverse2 (to, &from);
00651 #else
00652     move2 (to, ((char*)&from)+sizeof(short)-2);
00653 #endif
00654     return SIZE_CAN_SHORT;
00655 }
00656 
00657 inline size_t CanonicalConversion::fromLocal (void* to,
00658                                               const unsigned short& from)
00659 {
00660 #if defined(AIPS_LITTLE_ENDIAN)
00661     reverse2 (to, &from);
00662 #else
00663     move2 (to, ((char*)&from)+sizeof(unsigned short)-2);
00664 #endif
00665     return SIZE_CAN_USHORT;
00666 }
00667 
00668 inline size_t CanonicalConversion::fromLocal (void* to,
00669                                               const int& from)
00670 {
00671 #if defined(AIPS_LITTLE_ENDIAN)
00672     reverse4 (to, &from);
00673 #else
00674     move4 (to, ((char*)&from)+sizeof(int)-4);
00675 #endif
00676     return SIZE_CAN_INT;
00677 }
00678 
00679 inline size_t CanonicalConversion::fromLocal (void* to,
00680                                               const unsigned int& from)
00681 {
00682 #if defined(AIPS_LITTLE_ENDIAN)
00683     reverse4 (to, &from);
00684 #else
00685     move4 (to, ((char*)&from)+sizeof(unsigned int)-4);
00686 #endif
00687     return SIZE_CAN_UINT;
00688 }
00689 
00690 inline size_t CanonicalConversion::fromLocal (void* to,
00691                                               const Int64& from)
00692 {
00693 #if defined(AIPS_LITTLE_ENDIAN)
00694     reverse8 (to, &from);
00695 #else
00696     move8 (to, ((char*)&from)+sizeof(Int64)-8);
00697 #endif
00698     return SIZE_CAN_INT64;
00699 }
00700 
00701 inline size_t CanonicalConversion::fromLocal (void* to,
00702                                               const uInt64& from)
00703 {
00704 #if defined(AIPS_LITTLE_ENDIAN)
00705     reverse8 (to, &from);
00706 #else
00707     move8 (to, ((char*)&from)+sizeof(uInt64)-8);
00708 #endif
00709     return SIZE_CAN_UINT64;
00710 }
00711 
00712 inline size_t CanonicalConversion::fromLocal (void* to,
00713                                               const float& from)
00714 {
00715 #if defined(AIPS_LITTLE_ENDIAN)
00716     reverse4 (to, &from);
00717 #else
00718     move4 (to, &from);
00719 #endif
00720     return SIZE_CAN_FLOAT;
00721 }
00722 
00723 inline size_t CanonicalConversion::fromLocal (void* to,
00724                                               const double& from)
00725 {
00726 #if defined(AIPS_LITTLE_ENDIAN)
00727     reverse8 (to, &from);
00728 #else
00729     move8 (to, &from);
00730 #endif
00731     return SIZE_CAN_FLOAT;
00732 }
00733 
00734 
00735 inline size_t CanonicalConversion::toLocal (char*           to,
00736                                             const void* from,
00737                                             size_t nr)
00738 {
00739     return toLocalChar (to, from, nr);
00740 }
00741 inline size_t CanonicalConversion::toLocal (unsigned char*  to,
00742                                             const void* from,
00743                                             size_t nr)
00744 {
00745     return toLocalUChar (to, from, nr);
00746 }
00747 inline size_t CanonicalConversion::toLocal (short*          to,
00748                                             const void* from,
00749                                             size_t nr)
00750 {
00751     return toLocalShort (to, from, nr);
00752 }
00753 inline size_t CanonicalConversion::toLocal (unsigned short* to,
00754                                             const void* from,
00755                                             size_t nr)
00756 {
00757     return toLocalUShort (to, from, nr);
00758 }
00759 inline size_t CanonicalConversion::toLocal (int*            to,
00760                                             const void* from,
00761                                             size_t nr)
00762 {
00763     return toLocalInt (to, from, nr);
00764 }
00765 inline size_t CanonicalConversion::toLocal (unsigned int*   to,
00766                                             const void* from,
00767                                             size_t nr)
00768 {
00769     return toLocalUInt (to, from, nr);
00770 }
00771 inline size_t CanonicalConversion::toLocal (Int64*          to,
00772                                             const void* from,
00773                                             size_t nr)
00774 {
00775     return toLocalInt64 (to, from, nr);
00776 }
00777 inline size_t CanonicalConversion::toLocal (uInt64*         to,
00778                                             const void* from,
00779                                             size_t nr)
00780 {
00781     return toLocalUInt64 (to, from, nr);
00782 }
00783 inline size_t CanonicalConversion::toLocal (float*          to,
00784                                             const void* from,
00785                                             size_t nr)
00786 {
00787     return toLocalFloat (to, from, nr);
00788 }
00789 inline size_t CanonicalConversion::toLocal (double*         to,
00790                                             const void* from,
00791                                             size_t nr)
00792 {
00793     return toLocalDouble (to, from, nr);
00794 }
00795 
00796 inline size_t CanonicalConversion::fromLocal (void* to,
00797                                               const char*           from,
00798                                               size_t nr)
00799 {
00800     return fromLocalChar (to, from, nr);
00801 }
00802 inline size_t CanonicalConversion::fromLocal (void* to,
00803                                               const unsigned char*  from,
00804                                               size_t nr)
00805 {
00806     return fromLocalUChar (to, from, nr);
00807 }
00808 inline size_t CanonicalConversion::fromLocal (void* to,
00809                                               const short*          from,
00810                                               size_t nr)
00811 {
00812     return fromLocalShort (to, from, nr);
00813 }
00814 inline size_t CanonicalConversion::fromLocal (void* to,
00815                                               const unsigned short* from,
00816                                               size_t nr)
00817 {
00818     return fromLocalUShort (to, from, nr);
00819 }
00820 inline size_t CanonicalConversion::fromLocal (void* to,
00821                                               const int*            from,
00822                                               size_t nr)
00823 {
00824     return fromLocalInt (to, from, nr);
00825 }
00826 inline size_t CanonicalConversion::fromLocal (void* to,
00827                                               const unsigned int*   from,
00828                                               size_t nr)
00829 {
00830     return fromLocalUInt (to, from, nr);
00831 }
00832 inline size_t CanonicalConversion::fromLocal (void* to,
00833                                               const Int64*          from,
00834                                               size_t nr)
00835 {
00836     return fromLocalInt64 (to, from, nr);
00837 }
00838 inline size_t CanonicalConversion::fromLocal (void* to,
00839                                               const uInt64*         from,
00840                                               size_t nr)
00841 {
00842     return fromLocalUInt64 (to, from, nr);
00843 }
00844 inline size_t CanonicalConversion::fromLocal (void* to,
00845                                               const float*          from,
00846                                               size_t nr)
00847 {
00848     return fromLocalFloat (to, from, nr);
00849 }
00850 inline size_t CanonicalConversion::fromLocal (void* to,
00851                                               const double*         from,
00852                                               size_t nr)
00853 {
00854     return fromLocalDouble (to, from, nr);
00855 }
00856 
00857 
00858 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00859                                                       (const char*)
00860 {
00861     return toLocalChar;
00862 }
00863 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00864                                                       (const unsigned char*)
00865 {
00866     return toLocalUChar;
00867 }
00868 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00869                                                       (const short*)
00870 {
00871     return toLocalShort;
00872 }
00873 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00874                                                       (const unsigned short*)
00875 {
00876     return toLocalUShort;
00877 }
00878 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00879                                                       (const int*)
00880 {
00881     return toLocalInt;
00882 }
00883 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00884                                                       (const unsigned int*)
00885 {
00886     return toLocalUInt;
00887 }
00888 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00889                                                       (const Int64*)
00890 {
00891     return toLocalInt64;
00892 }
00893 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00894                                                       (const uInt64*)
00895 {
00896     return toLocalUInt64;
00897 }
00898 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00899                                                       (const float*)
00900 {
00901     return toLocalFloat;
00902 }
00903 inline Conversion::ValueFunction* CanonicalConversion::getToLocal
00904                                                       (const double*)
00905 {
00906     return toLocalDouble;
00907 }
00908 
00909 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00910                                                       (const char*)
00911 {
00912     return fromLocalChar;
00913 }
00914 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00915                                                       (const unsigned char*)
00916 {
00917     return fromLocalUChar;
00918 }
00919 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00920                                                       (const short*)
00921 {
00922     return fromLocalShort;
00923 }
00924 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00925                                                       (const unsigned short*)
00926 {
00927     return fromLocalUShort;
00928 }
00929 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00930                                                       (const int*)
00931 {
00932     return fromLocalInt;
00933 }
00934 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00935                                                       (const unsigned int*)
00936 {
00937     return fromLocalUInt;
00938 }
00939 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00940                                                       (const Int64*)
00941 {
00942     return fromLocalInt64;
00943 }
00944 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00945                                                       (const uInt64*)
00946 {
00947     return fromLocalUInt64;
00948 }
00949 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00950                                                       (const float*)
00951 {
00952     return fromLocalFloat;
00953 }
00954 inline Conversion::ValueFunction* CanonicalConversion::getFromLocal
00955                                                       (const double*)
00956 {
00957     return fromLocalDouble;
00958 }
00959 
00960 
00961 inline unsigned int CanonicalConversion::canonicalSize (const char*)
00962     {return SIZE_CAN_CHAR;}
00963 inline unsigned int CanonicalConversion::canonicalSize (const unsigned char*)
00964     {return SIZE_CAN_UCHAR;} 
00965 inline unsigned int CanonicalConversion::canonicalSize (const short*)
00966     {return SIZE_CAN_SHORT;}
00967 inline unsigned int CanonicalConversion::canonicalSize (const unsigned short*)
00968     {return SIZE_CAN_USHORT;}
00969 inline unsigned int CanonicalConversion::canonicalSize (const int*)
00970     {return SIZE_CAN_INT;}
00971 inline unsigned int CanonicalConversion::canonicalSize (const unsigned int*)
00972     {return SIZE_CAN_UINT;}
00973 inline unsigned int CanonicalConversion::canonicalSize (const Int64*)
00974     {return SIZE_CAN_INT64;}
00975 inline unsigned int CanonicalConversion::canonicalSize (const uInt64*)
00976     {return SIZE_CAN_UINT64;}
00977 inline unsigned int CanonicalConversion::canonicalSize (const float*)
00978     {return SIZE_CAN_FLOAT;}
00979 inline unsigned int CanonicalConversion::canonicalSize (const double*)
00980     {return SIZE_CAN_DOUBLE;}
00981 //#//inline unsigned int CanonicalConversion::canonicalSize (const long double*)
00982 //#//    {return SIZE_CAN_LDOUBLE;}
00983 
00984 
00985 
00986 
00987 } //# NAMESPACE CASACORE - END
00988 
00989 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1