LECanonicalConversion.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1