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_VAXCONVERSION_H
00029 #define CASA_VAXCONVERSION_H
00030
00031
00032 #include <casacore/casa/aips.h>
00033 #include <assert.h>
00034 #include <casacore/casa/OS/LittleEndianConversion.h>
00035
00036
00037 namespace casacore {
00038
00039
00040
00041
00042 #define SIZE_VAX_CHAR 1
00043 #define SIZE_VAX_UCHAR 1
00044 #define SIZE_VAX_SHORT 2
00045 #define SIZE_VAX_USHORT 2
00046 #define SIZE_VAX_INT 4
00047 #define SIZE_VAX_UINT 4
00048 #define SIZE_VAX_INT64 4
00049 #define SIZE_VAX_UINT64 4
00050 #define SIZE_VAX_FLOAT 4
00051 #define SIZE_VAX_DOUBLE 8
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
00081
00082 class VAXConversion
00083 {
00084 public:
00085
00086
00087
00088 static void toLocal (char& to, const void* from);
00089 static void toLocal (unsigned char& to, const void* from);
00090 static void toLocal (short& to, const void* from);
00091 static void toLocal (unsigned short& to, const void* from);
00092 static void toLocal (int& to, const void* from);
00093 static void toLocal (unsigned int& to, const void* from);
00094 static void toLocal (Int64& to, const void* from);
00095 static void toLocal (uInt64& to, const void* from);
00096 static void toLocal (float& to, const void* from);
00097 static void toLocal (double& to, const void* from);
00098
00099
00100
00101
00102
00103 static void toLocal (char* to, const void* from,
00104 size_t nr);
00105 static void toLocal (unsigned char* to, const void* from,
00106 size_t nr);
00107 static void toLocal (short* to, const void* from,
00108 size_t nr);
00109 static void toLocal (unsigned short* to, const void* from,
00110 size_t nr);
00111 static void toLocal (int* to, const void* from,
00112 size_t nr);
00113 static void toLocal (unsigned int* to, const void* from,
00114 size_t nr);
00115 static void toLocal (Int64* to, const void* from,
00116 size_t nr);
00117 static void toLocal (uInt64* to, const void* from,
00118 size_t nr);
00119 static void toLocal (float* to, const void* from,
00120 size_t nr);
00121 static void toLocal (double* to, const void* from,
00122 size_t nr);
00123
00124
00125
00126
00127
00128 static void fromLocal (void* to, char from);
00129 static void fromLocal (void* to, unsigned char from);
00130 static void fromLocal (void* to, short from);
00131 static void fromLocal (void* to, unsigned short from);
00132 static void fromLocal (void* to, int from);
00133 static void fromLocal (void* to, unsigned int from);
00134 static void fromLocal (void* to, Int64 from);
00135 static void fromLocal (void* to, uInt64 from);
00136 static void fromLocal (void* to, float from);
00137 static void fromLocal (void* to, double from);
00138
00139
00140
00141
00142
00143 static void fromLocal (void* to, const char* from,
00144 size_t nr);
00145 static void fromLocal (void* to, const unsigned char* from,
00146 size_t nr);
00147 static void fromLocal (void* to, const short* from,
00148 size_t nr);
00149 static void fromLocal (void* to, const unsigned short* from,
00150 size_t nr);
00151 static void fromLocal (void* to, const int* from,
00152 size_t nr);
00153 static void fromLocal (void* to, const unsigned int* from,
00154 size_t nr);
00155 static void fromLocal (void* to, const Int64* from,
00156 size_t nr);
00157 static void fromLocal (void* to, const uInt64* from,
00158 size_t nr);
00159 static void fromLocal (void* to, const float* from,
00160 size_t nr);
00161 static void fromLocal (void* to, const double* from,
00162 size_t nr);
00163
00164
00165
00166 static void moveFloat (void* to, const void* from);
00167
00168 private:
00169
00170
00171 VAXConversion();
00172 };
00173
00174
00175
00176 inline void VAXConversion::toLocal (char& to, const void* from)
00177 {
00178 LittleEndianConversion::toLocal (to, from);
00179 }
00180
00181 inline void VAXConversion::toLocal (unsigned char& to, const void* from)
00182 {
00183 LittleEndianConversion::toLocal (to, from);
00184 }
00185
00186 inline void VAXConversion::toLocal (short& to, const void* from)
00187 {
00188 LittleEndianConversion::toLocal (to, from);
00189 }
00190
00191 inline void VAXConversion::toLocal (unsigned short& to, const void* from)
00192 {
00193 LittleEndianConversion::toLocal (to, from);
00194 }
00195
00196 inline void VAXConversion::toLocal (int& to, const void* from)
00197 {
00198 LittleEndianConversion::toLocal (to, from);
00199 }
00200
00201 inline void VAXConversion::toLocal (unsigned int& to, const void* from)
00202 {
00203 LittleEndianConversion::toLocal (to, from);
00204 }
00205
00206 inline void VAXConversion::toLocal (Int64& to, const void* from)
00207 {
00208 LittleEndianConversion::toLocal (to, from);
00209 }
00210
00211 inline void VAXConversion::toLocal (uInt64& to, const void* from)
00212 {
00213 LittleEndianConversion::toLocal (to, from);
00214 }
00215
00216 inline void VAXConversion::toLocal (float& to, const void* from)
00217 {
00218 toLocal (&to, from, 1);
00219 }
00220
00221 inline void VAXConversion::toLocal (double& to, const void* from)
00222 {
00223 toLocal (&to, from, 1);
00224 }
00225
00226 inline void VAXConversion::toLocal (char* to, const void* from,
00227 size_t nr)
00228 {
00229 LittleEndianConversion::toLocal (to, from, nr);
00230 }
00231
00232 inline void VAXConversion::toLocal (unsigned char* to, const void* from,
00233 size_t nr)
00234 {
00235 LittleEndianConversion::toLocal (to, from, nr);
00236 }
00237
00238 inline void VAXConversion::toLocal (short* to, const void* from,
00239 size_t nr)
00240 {
00241 LittleEndianConversion::toLocal (to, from, nr);
00242 }
00243
00244 inline void VAXConversion::toLocal (unsigned short* to, const void* from,
00245 size_t nr)
00246 {
00247 LittleEndianConversion::toLocal (to, from, nr);
00248 }
00249
00250 inline void VAXConversion::toLocal (int* to, const void* from,
00251 size_t nr)
00252 {
00253 LittleEndianConversion::toLocal (to, from, nr);
00254 }
00255
00256 inline void VAXConversion::toLocal (unsigned int* to, const void* from,
00257 size_t nr)
00258 {
00259 LittleEndianConversion::toLocal (to, from, nr);
00260 }
00261
00262 inline void VAXConversion::toLocal (Int64* to, const void* from,
00263 size_t nr)
00264 {
00265 LittleEndianConversion::toLocal (to, from, nr);
00266 }
00267
00268 inline void VAXConversion::toLocal (uInt64* to, const void* from,
00269 size_t nr)
00270 {
00271 LittleEndianConversion::toLocal (to, from, nr);
00272 }
00273
00274
00275 inline void VAXConversion::fromLocal (void* to, char from)
00276 {
00277 LittleEndianConversion::fromLocal (to, from);
00278 }
00279
00280 inline void VAXConversion::fromLocal (void* to, unsigned char from)
00281 {
00282 LittleEndianConversion::fromLocal (to, from);
00283 }
00284
00285 inline void VAXConversion::fromLocal (void* to, short from)
00286 {
00287 LittleEndianConversion::fromLocal (to, from);
00288 }
00289
00290 inline void VAXConversion::fromLocal (void* to, unsigned short from)
00291 {
00292 LittleEndianConversion::fromLocal (to, from);
00293 }
00294
00295 inline void VAXConversion::fromLocal (void* to, int from)
00296 {
00297 LittleEndianConversion::fromLocal (to, from);
00298 }
00299
00300 inline void VAXConversion::fromLocal (void* to, unsigned int from)
00301 {
00302 LittleEndianConversion::fromLocal (to, from);
00303 }
00304
00305 inline void VAXConversion::fromLocal (void* to, Int64 from)
00306 {
00307 LittleEndianConversion::fromLocal (to, from);
00308 }
00309
00310 inline void VAXConversion::fromLocal (void* to, uInt64 from)
00311 {
00312 LittleEndianConversion::fromLocal (to, from);
00313 }
00314
00315 inline void VAXConversion::fromLocal (void* to, float from)
00316 {
00317 fromLocal (to, &from, 1);
00318 }
00319
00320 inline void VAXConversion::fromLocal (void* to, double from)
00321 {
00322 fromLocal (to, &from, 1);
00323 }
00324
00325 inline void VAXConversion::fromLocal (void* to, const char* from,
00326 size_t nr)
00327 {
00328 LittleEndianConversion::fromLocal (to, from, nr);
00329 }
00330
00331 inline void VAXConversion::fromLocal (void* to, const unsigned char* from,
00332 size_t nr)
00333 {
00334 LittleEndianConversion::fromLocal (to, from, nr);
00335 }
00336
00337 inline void VAXConversion::fromLocal (void* to, const short* from,
00338 size_t nr)
00339 {
00340 LittleEndianConversion::fromLocal (to, from, nr);
00341 }
00342
00343 inline void VAXConversion::fromLocal (void* to, const unsigned short* from,
00344 size_t nr)
00345 {
00346 LittleEndianConversion::fromLocal (to, from, nr);
00347 }
00348
00349 inline void VAXConversion::fromLocal (void* to, const int* from,
00350 size_t nr)
00351 {
00352 LittleEndianConversion::fromLocal (to, from, nr);
00353 }
00354
00355 inline void VAXConversion::fromLocal (void* to, const unsigned int* from,
00356 size_t nr)
00357 {
00358 LittleEndianConversion::fromLocal (to, from, nr);
00359 }
00360
00361 inline void VAXConversion::fromLocal (void* to, const Int64* from,
00362 size_t nr)
00363 {
00364 LittleEndianConversion::fromLocal (to, from, nr);
00365 }
00366
00367 inline void VAXConversion::fromLocal (void* to, const uInt64* from,
00368 size_t nr)
00369 {
00370 LittleEndianConversion::fromLocal (to, from, nr);
00371 }
00372
00373
00374
00375 inline void VAXConversion::moveFloat (void* to, const void* from)
00376 {
00377 #if defined(AIPS_LITTLE_ENDIAN)
00378 ((char*)to)[0] = ((const char*)from)[2];
00379 ((char*)to)[1] = ((const char*)from)[3];
00380 ((char*)to)[2] = ((const char*)from)[0];
00381 ((char*)to)[3] = ((const char*)from)[1];
00382 #else
00383 ((char*)to)[0] = ((const char*)from)[1];
00384 ((char*)to)[1] = ((const char*)from)[0];
00385 ((char*)to)[2] = ((const char*)from)[3];
00386 ((char*)to)[3] = ((const char*)from)[2];
00387 #endif
00388 }
00389
00390
00391
00392 }
00393
00394 #endif