00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CASA_IBMCONVERSION_H
00029 #define CASA_IBMCONVERSION_H
00030
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/OS/CanonicalConversion.h>
00034
00035
00036 namespace casacore {
00037
00038
00039
00040 #define SIZE_IBM_CHAR 1
00041 #define SIZE_IBM_UCHAR 1
00042 #define SIZE_IBM_SHORT 2
00043 #define SIZE_IBM_USHORT 2
00044 #define SIZE_IBM_INT 4
00045 #define SIZE_IBM_UINT 4
00046 #define SIZE_IBM_INT64 4
00047 #define SIZE_IBM_UINT64 4
00048 #define SIZE_IBM_FLOAT 4
00049 #define SIZE_IBM_DOUBLE 8
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 class IBMConversion
00081 {
00082 public:
00083
00084
00085
00086
00087
00088
00089
00090 static void toLocal (char& to, const void* from);
00091 static void toLocal (unsigned char& to, const void* from);
00092 static void toLocal (short& to, const void* from);
00093 static void toLocal (unsigned short& to, const void* from);
00094 static void toLocal (int& to, const void* from);
00095 static void toLocal (unsigned int& to, const void* from);
00096 static void toLocal (Int64& to, const void* from);
00097 static void toLocal (uInt64& to, const void* from);
00098 static void toLocal (float& to, const void* from);
00099 static void toLocal (double& to, const void* from);
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 static void toLocal (char* to, const void* from,
00110 size_t nr);
00111 static void toLocal (unsigned char* to, const void* from,
00112 size_t nr);
00113 static void toLocal (short* to, const void* from,
00114 size_t nr);
00115 static void toLocal (unsigned short* to, const void* from,
00116 size_t nr);
00117 static void toLocal (int* to, const void* from,
00118 size_t nr);
00119 static void toLocal (unsigned int* to, const void* from,
00120 size_t nr);
00121 static void toLocal (Int64* to, const void* from,
00122 size_t nr);
00123 static void toLocal (uInt64* to, const void* from,
00124 size_t nr);
00125 static void toLocal (float* to, const void* from,
00126 size_t nr);
00127 static void toLocal (double* to, const void* from,
00128 size_t nr);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 static void fromLocal (void* to, char from);
00139 static void fromLocal (void* to, unsigned char from);
00140 static void fromLocal (void* to, short from);
00141 static void fromLocal (void* to, unsigned short from);
00142 static void fromLocal (void* to, int from);
00143 static void fromLocal (void* to, unsigned int from);
00144 static void fromLocal (void* to, Int64 from);
00145 static void fromLocal (void* to, uInt64 from);
00146 static void fromLocal (void* to, float from);
00147 static void fromLocal (void* to, double from);
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 static void fromLocal (void* to, const char* from,
00158 size_t nr);
00159 static void fromLocal (void* to, const unsigned char* from,
00160 size_t nr);
00161 static void fromLocal (void* to, const short* from,
00162 size_t nr);
00163 static void fromLocal (void* to, const unsigned short* from,
00164 size_t nr);
00165 static void fromLocal (void* to, const int* from,
00166 size_t nr);
00167 static void fromLocal (void* to, const unsigned int* from,
00168 size_t nr);
00169 static void fromLocal (void* to, const Int64* from,
00170 size_t nr);
00171 static void fromLocal (void* to, const uInt64* from,
00172 size_t nr);
00173 static void fromLocal (void* to, const float* from,
00174 size_t nr);
00175 static void fromLocal (void* to, const double* from,
00176 size_t nr);
00177
00178
00179 private:
00180
00181
00182 IBMConversion();
00183 };
00184
00185
00186
00187 inline void IBMConversion::toLocal (unsigned char& to, const void* from)
00188 {
00189 CanonicalConversion::toLocal (to, from);
00190 }
00191
00192 inline void IBMConversion::toLocal (short& to, const void* from)
00193 {
00194 CanonicalConversion::toLocal (to, from);
00195 }
00196
00197 inline void IBMConversion::toLocal (unsigned short& to, const void* from)
00198 {
00199 CanonicalConversion::toLocal (to, from);
00200 }
00201
00202 inline void IBMConversion::toLocal (int& to, const void* from)
00203 {
00204 CanonicalConversion::toLocal (to, from);
00205 }
00206
00207 inline void IBMConversion::toLocal (unsigned int& to, const void* from)
00208 {
00209 CanonicalConversion::toLocal (to, from);
00210 }
00211
00212 inline void IBMConversion::toLocal (Int64& to, const void* from)
00213 {
00214 if (sizeof(Int64) != 4) {
00215 if (((signed char*)from)[0] < 0) {
00216 to = -1;
00217 }else{
00218 to = 0;
00219 }
00220 }
00221 #if defined(AIPS_LITTLE_ENDIAN)
00222 CanonicalConversion::reverse4 (&to, from);
00223 #else
00224 CanonicalConversion::move4 (((char*)&to)+sizeof(Int64)-4, from);
00225 #endif
00226 }
00227
00228 inline void IBMConversion::toLocal (uInt64& to, const void* from)
00229 {
00230 if (sizeof(uInt64) != 4) {
00231 to = 0;
00232 }
00233 #if defined(AIPS_LITTLE_ENDIAN)
00234 CanonicalConversion::reverse4 (&to, from);
00235 #else
00236 CanonicalConversion::move4 (((char*)&to)+sizeof(uInt64)-4, from);
00237 #endif
00238 }
00239
00240 inline void IBMConversion::toLocal (float& to, const void* from)
00241 {
00242 toLocal (&to, from, 1);
00243 }
00244
00245 inline void IBMConversion::toLocal (double& to, const void* from)
00246 {
00247 toLocal (&to, from, 1);
00248 }
00249
00250 inline void IBMConversion::toLocal (unsigned char* to, const void* from,
00251 size_t nr)
00252 {
00253 CanonicalConversion::toLocal (to, from, nr);
00254 }
00255
00256 inline void IBMConversion::toLocal (short* to, const void* from,
00257 size_t nr)
00258 {
00259 CanonicalConversion::toLocal (to, from, nr);
00260 }
00261
00262 inline void IBMConversion::toLocal (unsigned short* to, const void* from,
00263 size_t nr)
00264 {
00265 CanonicalConversion::toLocal (to, from, nr);
00266 }
00267
00268 inline void IBMConversion::toLocal (int* to, const void* from,
00269 size_t nr)
00270 {
00271 CanonicalConversion::toLocal (to, from, nr);
00272 }
00273
00274 inline void IBMConversion::toLocal (unsigned int* to, const void* from,
00275 size_t nr)
00276 {
00277 CanonicalConversion::toLocal (to, from, nr);
00278 }
00279
00280
00281 inline void IBMConversion::fromLocal (void* to, unsigned char from)
00282 {
00283 CanonicalConversion::fromLocal (to, from);
00284 }
00285
00286 inline void IBMConversion::fromLocal (void* to, short from)
00287 {
00288 CanonicalConversion::fromLocal (to, from);
00289 }
00290
00291 inline void IBMConversion::fromLocal (void* to, unsigned short from)
00292 {
00293 CanonicalConversion::fromLocal (to, from);
00294 }
00295
00296 inline void IBMConversion::fromLocal (void* to, int from)
00297 {
00298 CanonicalConversion::fromLocal (to, from);
00299 }
00300
00301 inline void IBMConversion::fromLocal (void* to, unsigned int from)
00302 {
00303 CanonicalConversion::fromLocal (to, from);
00304 }
00305
00306 inline void IBMConversion::fromLocal (void* to, Int64 from)
00307 {
00308 #if defined(AIPS_LITTLE_ENDIAN)
00309 CanonicalConversion::reverse4 (to, &from);
00310 #else
00311 CanonicalConversion::move4 (to, ((char*)&from)+sizeof(Int64)-4);
00312 #endif
00313 }
00314
00315 inline void IBMConversion::fromLocal (void* to, uInt64 from)
00316 {
00317 #if defined(AIPS_LITTLE_ENDIAN)
00318 CanonicalConversion::reverse4 (to, &from);
00319 #else
00320 CanonicalConversion::move4 (to,((char*)&from)+sizeof(uInt64)-4);
00321 #endif
00322 }
00323
00324 inline void IBMConversion::fromLocal (void* to, float from)
00325 {
00326 fromLocal (to, &from, 1);
00327 }
00328
00329 inline void IBMConversion::fromLocal (void* to, double from)
00330 {
00331 fromLocal (to, &from, 1);
00332 }
00333
00334
00335 inline void IBMConversion::fromLocal (void* to, const unsigned char* from,
00336 size_t nr)
00337 {
00338 CanonicalConversion::fromLocal (to, from, nr);
00339 }
00340
00341 inline void IBMConversion::fromLocal (void* to, const short* from,
00342 size_t nr)
00343 {
00344 CanonicalConversion::fromLocal (to, from, nr);
00345 }
00346
00347 inline void IBMConversion::fromLocal (void* to, const unsigned short* from,
00348 size_t nr)
00349 {
00350 CanonicalConversion::fromLocal (to, from, nr);
00351 }
00352
00353 inline void IBMConversion::fromLocal (void* to, const int* from,
00354 size_t nr)
00355 {
00356 CanonicalConversion::fromLocal (to, from, nr);
00357 }
00358
00359 inline void IBMConversion::fromLocal (void* to, const unsigned int* from,
00360 size_t nr)
00361 {
00362 CanonicalConversion::fromLocal (to, from, nr);
00363 }
00364
00365
00366
00367
00368 }
00369
00370 #endif