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