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