casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VAXConversion.h
Go to the documentation of this file.
1 //# VAXConversion.h: A class with static functions to convert VAX format
2 //# Copyright (C) 1996,1997,1999,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_VAXCONVERSION_H
29 #define CASA_VAXCONVERSION_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <assert.h>
35 
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // Define the canonical sizes of the built-in data types.
40 // These are the same for all machine architectures.
41 
42 #define SIZE_VAX_CHAR 1
43 #define SIZE_VAX_UCHAR 1
44 #define SIZE_VAX_SHORT 2
45 #define SIZE_VAX_USHORT 2
46 #define SIZE_VAX_INT 4
47 #define SIZE_VAX_UINT 4
48 #define SIZE_VAX_INT64 4
49 #define SIZE_VAX_UINT64 4
50 #define SIZE_VAX_FLOAT 4
51 #define SIZE_VAX_DOUBLE 8
52 
53 
54 // <summary>
55 // A class with static functions to convert VAX format
56 // </summary>
57 
58 // <use visibility=export>
59 
60 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tVAXConversion" demos="">
61 // </reviewed>
62 
63 // <synopsis>
64 // This class contains static toLocal functions to convert data from VAX
65 // format to local format and vice-versa. It only handles VAX D-float format.
66 // Another class should be implemented to handle VAX G-float format.
67 // <p>
68 // The functions work well on big-endian as well as little-endian machines.
69 // </synopsis>
70 
71 // <motivation>
72 // Archived WSRT data can be stored in the old VAX format
73 // (little-endian and VAX D-float floating point format).
74 // Conversion functions are needed to read these data.
75 // </motivation>
76 
77 // <todo asof="$DATE$">
78 // <li> Support data type long double.
79 // </todo>
80 
81 
83 {
84 public:
85  // Convert one value from VAX format to local format.
86  // The from and to buffer should not overlap.
87  // <group>
88  static void toLocal (char& to, const void* from);
89  static void toLocal (unsigned char& to, const void* from);
90  static void toLocal (short& to, const void* from);
91  static void toLocal (unsigned short& to, const void* from);
92  static void toLocal (int& to, const void* from);
93  static void toLocal (unsigned int& to, const void* from);
94  static void toLocal (Int64& to, const void* from);
95  static void toLocal (uInt64& to, const void* from);
96  static void toLocal (float& to, const void* from);
97  static void toLocal (double& to, const void* from);
98  // </group>
99 
100  // Convert nr values from VAX format to local format.
101  // The from and to buffer should not overlap.
102  // <group>
103  static void toLocal (char* to, const void* from,
104  size_t nr);
105  static void toLocal (unsigned char* to, const void* from,
106  size_t nr);
107  static void toLocal (short* to, const void* from,
108  size_t nr);
109  static void toLocal (unsigned short* to, const void* from,
110  size_t nr);
111  static void toLocal (int* to, const void* from,
112  size_t nr);
113  static void toLocal (unsigned int* to, const void* from,
114  size_t nr);
115  static void toLocal (Int64* to, const void* from,
116  size_t nr);
117  static void toLocal (uInt64* to, const void* from,
118  size_t nr);
119  static void toLocal (float* to, const void* from,
120  size_t nr);
121  static void toLocal (double* to, const void* from,
122  size_t nr);
123  // </group>
124 
125  // Convert one value from local format to VAX format.
126  // The from and to buffer should not overlap.
127  // <group>
128  static void fromLocal (void* to, char from);
129  static void fromLocal (void* to, unsigned char from);
130  static void fromLocal (void* to, short from);
131  static void fromLocal (void* to, unsigned short from);
132  static void fromLocal (void* to, int from);
133  static void fromLocal (void* to, unsigned int from);
134  static void fromLocal (void* to, Int64 from);
135  static void fromLocal (void* to, uInt64 from);
136  static void fromLocal (void* to, float from);
137  static void fromLocal (void* to, double from);
138  // </group>
139 
140  // Convert nr values from local format to VAX format.
141  // The from and to buffer should not overlap.
142  // <group>
143  static void fromLocal (void* to, const char* from,
144  size_t nr);
145  static void fromLocal (void* to, const unsigned char* from,
146  size_t nr);
147  static void fromLocal (void* to, const short* from,
148  size_t nr);
149  static void fromLocal (void* to, const unsigned short* from,
150  size_t nr);
151  static void fromLocal (void* to, const int* from,
152  size_t nr);
153  static void fromLocal (void* to, const unsigned int* from,
154  size_t nr);
155  static void fromLocal (void* to, const Int64* from,
156  size_t nr);
157  static void fromLocal (void* to, const uInt64* from,
158  size_t nr);
159  static void fromLocal (void* to, const float* from,
160  size_t nr);
161  static void fromLocal (void* to, const double* from,
162  size_t nr);
163  // </group>
164 
165  // Move a float value (by swapping bytes correctly).
166  static void moveFloat (void* to, const void* from);
167 
168 private:
169  // This class should not be constructed
170  // (so declare the constructor private).
171  VAXConversion();
172 };
173 
174 
175 
176 inline void VAXConversion::toLocal (char& to, const void* from)
177 {
179 }
180 
181 inline void VAXConversion::toLocal (unsigned char& to, const void* from)
182 {
184 }
185 
186 inline void VAXConversion::toLocal (short& to, const void* from)
187 {
189 }
190 
191 inline void VAXConversion::toLocal (unsigned short& to, const void* from)
192 {
194 }
195 
196 inline void VAXConversion::toLocal (int& to, const void* from)
197 {
199 }
200 
201 inline void VAXConversion::toLocal (unsigned int& to, const void* from)
202 {
204 }
205 
206 inline void VAXConversion::toLocal (Int64& to, const void* from)
207 {
209 }
210 
211 inline void VAXConversion::toLocal (uInt64& to, const void* from)
212 {
214 }
215 
216 inline void VAXConversion::toLocal (float& to, const void* from)
217 {
218  toLocal (&to, from, 1);
219 }
220 
221 inline void VAXConversion::toLocal (double& to, const void* from)
222 {
223  toLocal (&to, from, 1);
224 }
225 
226 inline void VAXConversion::toLocal (char* to, const void* from,
227  size_t nr)
228 {
229  LittleEndianConversion::toLocal (to, from, nr);
230 }
231 
232 inline void VAXConversion::toLocal (unsigned char* to, const void* from,
233  size_t nr)
234 {
235  LittleEndianConversion::toLocal (to, from, nr);
236 }
237 
238 inline void VAXConversion::toLocal (short* to, const void* from,
239  size_t nr)
240 {
241  LittleEndianConversion::toLocal (to, from, nr);
242 }
243 
244 inline void VAXConversion::toLocal (unsigned short* to, const void* from,
245  size_t nr)
246 {
247  LittleEndianConversion::toLocal (to, from, nr);
248 }
249 
250 inline void VAXConversion::toLocal (int* to, const void* from,
251  size_t nr)
252 {
253  LittleEndianConversion::toLocal (to, from, nr);
254 }
255 
256 inline void VAXConversion::toLocal (unsigned int* to, const void* from,
257  size_t nr)
258 {
259  LittleEndianConversion::toLocal (to, from, nr);
260 }
261 
262 inline void VAXConversion::toLocal (Int64* to, const void* from,
263  size_t nr)
264 {
265  LittleEndianConversion::toLocal (to, from, nr);
266 }
267 
268 inline void VAXConversion::toLocal (uInt64* to, const void* from,
269  size_t nr)
270 {
271  LittleEndianConversion::toLocal (to, from, nr);
272 }
273 
274 
275 inline void VAXConversion::fromLocal (void* to, char from)
276 {
278 }
279 
280 inline void VAXConversion::fromLocal (void* to, unsigned char from)
281 {
283 }
284 
285 inline void VAXConversion::fromLocal (void* to, short from)
286 {
288 }
289 
290 inline void VAXConversion::fromLocal (void* to, unsigned short from)
291 {
293 }
294 
295 inline void VAXConversion::fromLocal (void* to, int from)
296 {
298 }
299 
300 inline void VAXConversion::fromLocal (void* to, unsigned int from)
301 {
303 }
304 
305 inline void VAXConversion::fromLocal (void* to, Int64 from)
306 {
308 }
309 
310 inline void VAXConversion::fromLocal (void* to, uInt64 from)
311 {
313 }
314 
315 inline void VAXConversion::fromLocal (void* to, float from)
316 {
317  fromLocal (to, &from, 1);
318 }
319 
320 inline void VAXConversion::fromLocal (void* to, double from)
321 {
322  fromLocal (to, &from, 1);
323 }
324 
325 inline void VAXConversion::fromLocal (void* to, const char* from,
326  size_t nr)
327 {
328  LittleEndianConversion::fromLocal (to, from, nr);
329 }
330 
331 inline void VAXConversion::fromLocal (void* to, const unsigned char* from,
332  size_t nr)
333 {
334  LittleEndianConversion::fromLocal (to, from, nr);
335 }
336 
337 inline void VAXConversion::fromLocal (void* to, const short* from,
338  size_t nr)
339 {
340  LittleEndianConversion::fromLocal (to, from, nr);
341 }
342 
343 inline void VAXConversion::fromLocal (void* to, const unsigned short* from,
344  size_t nr)
345 {
346  LittleEndianConversion::fromLocal (to, from, nr);
347 }
348 
349 inline void VAXConversion::fromLocal (void* to, const int* from,
350  size_t nr)
351 {
352  LittleEndianConversion::fromLocal (to, from, nr);
353 }
354 
355 inline void VAXConversion::fromLocal (void* to, const unsigned int* from,
356  size_t nr)
357 {
358  LittleEndianConversion::fromLocal (to, from, nr);
359 }
360 
361 inline void VAXConversion::fromLocal (void* to, const Int64* from,
362  size_t nr)
363 {
364  LittleEndianConversion::fromLocal (to, from, nr);
365 }
366 
367 inline void VAXConversion::fromLocal (void* to, const uInt64* from,
368  size_t nr)
369 {
370  LittleEndianConversion::fromLocal (to, from, nr);
371 }
372 
373 
374 
375 inline void VAXConversion::moveFloat (void* to, const void* from)
376 {
377 #if defined(AIPS_LITTLE_ENDIAN)
378  ((char*)to)[0] = ((const char*)from)[2];
379  ((char*)to)[1] = ((const char*)from)[3];
380  ((char*)to)[2] = ((const char*)from)[0];
381  ((char*)to)[3] = ((const char*)from)[1];
382 #else
383  ((char*)to)[0] = ((const char*)from)[1];
384  ((char*)to)[1] = ((const char*)from)[0];
385  ((char*)to)[2] = ((const char*)from)[3];
386  ((char*)to)[3] = ((const char*)from)[2];
387 #endif
388 }
389 
390 
391 
392 } //# NAMESPACE CASACORE - END
393 
394 #endif
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
VAXConversion()
This class should not be constructed (so declare the constructor private).
unsigned long long uInt64
Definition: aipsxtype.h:39
static void toLocal(char &to, const void *from)
Convert one value from VAX format to local format.
static void toLocal(char &to, const void *from)
Convert one value from littleEndian format to local format.
static void fromLocal(void *to, char from)
Convert one value from local format to littleEndian format.
A class with static functions to convert VAX format.
Definition: VAXConversion.h:82
static void fromLocal(void *to, char from)
Convert one value from local format to VAX format.
static void moveFloat(void *to, const void *from)
Move a float value (by swapping bytes correctly).