casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef CASA_VAXCONVERSION_H
27#define CASA_VAXCONVERSION_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <assert.h>
32#include <casacore/casa/OS/LittleEndianConversion.h>
33
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37// Define the canonical sizes of the built-in data types.
38// These are the same for all machine architectures.
39
40#define SIZE_VAX_CHAR 1
41#define SIZE_VAX_UCHAR 1
42#define SIZE_VAX_SHORT 2
43#define SIZE_VAX_USHORT 2
44#define SIZE_VAX_INT 4
45#define SIZE_VAX_UINT 4
46#define SIZE_VAX_INT64 4
47#define SIZE_VAX_UINT64 4
48#define SIZE_VAX_FLOAT 4
49#define SIZE_VAX_DOUBLE 8
50
51
52// <summary>
53// A class with static functions to convert VAX format
54// </summary>
55
56// <use visibility=export>
57
58// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tVAXConversion" demos="">
59// </reviewed>
60
61// <synopsis>
62// This class contains static toLocal functions to convert data from VAX
63// format to local format and vice-versa. It only handles VAX D-float format.
64// Another class should be implemented to handle VAX G-float format.
65// <p>
66// The functions work well on big-endian as well as little-endian machines.
67// </synopsis>
68
69// <motivation>
70// Archived WSRT data can be stored in the old VAX format
71// (little-endian and VAX D-float floating point format).
72// Conversion functions are needed to read these data.
73// </motivation>
74
75// <todo asof="$DATE$">
76// <li> Support data type long double.
77// </todo>
78
79
81{
82public:
83 // Convert one value from VAX format to local format.
84 // The from and to buffer should not overlap.
85 // <group>
86 static void toLocal (char& to, const void* from);
87 static void toLocal (unsigned char& to, const void* from);
88 static void toLocal (short& to, const void* from);
89 static void toLocal (unsigned short& to, const void* from);
90 static void toLocal (int& to, const void* from);
91 static void toLocal (unsigned int& to, const void* from);
92 static void toLocal (Int64& to, const void* from);
93 static void toLocal (uInt64& to, const void* from);
94 static void toLocal (float& to, const void* from);
95 static void toLocal (double& to, const void* from);
96 // </group>
97
98 // Convert nr values from VAX format to local format.
99 // The from and to buffer should not overlap.
100 // <group>
101 static void toLocal (char* to, const void* from,
102 size_t nr);
103 static void toLocal (unsigned char* to, const void* from,
104 size_t nr);
105 static void toLocal (short* to, const void* from,
106 size_t nr);
107 static void toLocal (unsigned short* to, const void* from,
108 size_t nr);
109 static void toLocal (int* to, const void* from,
110 size_t nr);
111 static void toLocal (unsigned int* to, const void* from,
112 size_t nr);
113 static void toLocal (Int64* to, const void* from,
114 size_t nr);
115 static void toLocal (uInt64* to, const void* from,
116 size_t nr);
117 static void toLocal (float* to, const void* from,
118 size_t nr);
119 static void toLocal (double* to, const void* from,
120 size_t nr);
121 // </group>
122
123 // Convert one value from local format to VAX format.
124 // The from and to buffer should not overlap.
125 // <group>
126 static void fromLocal (void* to, char from);
127 static void fromLocal (void* to, unsigned char from);
128 static void fromLocal (void* to, short from);
129 static void fromLocal (void* to, unsigned short from);
130 static void fromLocal (void* to, int from);
131 static void fromLocal (void* to, unsigned int from);
132 static void fromLocal (void* to, Int64 from);
133 static void fromLocal (void* to, uInt64 from);
134 static void fromLocal (void* to, float from);
135 static void fromLocal (void* to, double from);
136 // </group>
137
138 // Convert nr values from local format to VAX format.
139 // The from and to buffer should not overlap.
140 // <group>
141 static void fromLocal (void* to, const char* from,
142 size_t nr);
143 static void fromLocal (void* to, const unsigned char* from,
144 size_t nr);
145 static void fromLocal (void* to, const short* from,
146 size_t nr);
147 static void fromLocal (void* to, const unsigned short* from,
148 size_t nr);
149 static void fromLocal (void* to, const int* from,
150 size_t nr);
151 static void fromLocal (void* to, const unsigned int* from,
152 size_t nr);
153 static void fromLocal (void* to, const Int64* from,
154 size_t nr);
155 static void fromLocal (void* to, const uInt64* from,
156 size_t nr);
157 static void fromLocal (void* to, const float* from,
158 size_t nr);
159 static void fromLocal (void* to, const double* from,
160 size_t nr);
161 // </group>
162
163 // Move a float value (by swapping bytes correctly).
164 static void moveFloat (void* to, const void* from);
165
166private:
167 // This class should not be constructed
168 // (so declare the constructor private).
170};
171
172
173
174inline void VAXConversion::toLocal (char& to, const void* from)
175{
177}
178
179inline void VAXConversion::toLocal (unsigned char& to, const void* from)
180{
182}
183
184inline void VAXConversion::toLocal (short& to, const void* from)
185{
187}
188
189inline void VAXConversion::toLocal (unsigned short& to, const void* from)
190{
192}
193
194inline void VAXConversion::toLocal (int& to, const void* from)
195{
197}
198
199inline void VAXConversion::toLocal (unsigned int& to, const void* from)
200{
202}
203
204inline void VAXConversion::toLocal (Int64& to, const void* from)
205{
207}
208
209inline void VAXConversion::toLocal (uInt64& to, const void* from)
210{
212}
213
214inline void VAXConversion::toLocal (float& to, const void* from)
215{
216 toLocal (&to, from, 1);
217}
218
219inline void VAXConversion::toLocal (double& to, const void* from)
220{
221 toLocal (&to, from, 1);
222}
223
224inline void VAXConversion::toLocal (char* to, const void* from,
225 size_t nr)
226{
227 LittleEndianConversion::toLocal (to, from, nr);
228}
229
230inline void VAXConversion::toLocal (unsigned char* to, const void* from,
231 size_t nr)
232{
233 LittleEndianConversion::toLocal (to, from, nr);
234}
235
236inline void VAXConversion::toLocal (short* to, const void* from,
237 size_t nr)
238{
239 LittleEndianConversion::toLocal (to, from, nr);
240}
241
242inline void VAXConversion::toLocal (unsigned short* to, const void* from,
243 size_t nr)
244{
245 LittleEndianConversion::toLocal (to, from, nr);
246}
247
248inline void VAXConversion::toLocal (int* to, const void* from,
249 size_t nr)
250{
251 LittleEndianConversion::toLocal (to, from, nr);
252}
253
254inline void VAXConversion::toLocal (unsigned int* to, const void* from,
255 size_t nr)
256{
257 LittleEndianConversion::toLocal (to, from, nr);
258}
259
260inline void VAXConversion::toLocal (Int64* to, const void* from,
261 size_t nr)
262{
263 LittleEndianConversion::toLocal (to, from, nr);
264}
265
266inline void VAXConversion::toLocal (uInt64* to, const void* from,
267 size_t nr)
268{
269 LittleEndianConversion::toLocal (to, from, nr);
270}
271
272
273inline void VAXConversion::fromLocal (void* to, char from)
274{
276}
277
278inline void VAXConversion::fromLocal (void* to, unsigned char from)
279{
281}
282
283inline void VAXConversion::fromLocal (void* to, short from)
284{
286}
287
288inline void VAXConversion::fromLocal (void* to, unsigned short from)
289{
291}
292
293inline void VAXConversion::fromLocal (void* to, int from)
294{
296}
297
298inline void VAXConversion::fromLocal (void* to, unsigned int from)
299{
301}
302
303inline void VAXConversion::fromLocal (void* to, Int64 from)
304{
306}
307
308inline void VAXConversion::fromLocal (void* to, uInt64 from)
309{
311}
312
313inline void VAXConversion::fromLocal (void* to, float from)
314{
315 fromLocal (to, &from, 1);
316}
317
318inline void VAXConversion::fromLocal (void* to, double from)
319{
320 fromLocal (to, &from, 1);
321}
322
323inline void VAXConversion::fromLocal (void* to, const char* from,
324 size_t nr)
325{
327}
328
329inline void VAXConversion::fromLocal (void* to, const unsigned char* from,
330 size_t nr)
331{
333}
334
335inline void VAXConversion::fromLocal (void* to, const short* from,
336 size_t nr)
337{
339}
340
341inline void VAXConversion::fromLocal (void* to, const unsigned short* from,
342 size_t nr)
343{
345}
346
347inline void VAXConversion::fromLocal (void* to, const int* from,
348 size_t nr)
349{
351}
352
353inline void VAXConversion::fromLocal (void* to, const unsigned int* from,
354 size_t nr)
355{
357}
358
359inline void VAXConversion::fromLocal (void* to, const Int64* from,
360 size_t nr)
361{
363}
364
365inline void VAXConversion::fromLocal (void* to, const uInt64* from,
366 size_t nr)
367{
369}
370
371
372
373inline void VAXConversion::moveFloat (void* to, const void* from)
374{
375#if defined(AIPS_LITTLE_ENDIAN)
376 ((char*)to)[0] = ((const char*)from)[2];
377 ((char*)to)[1] = ((const char*)from)[3];
378 ((char*)to)[2] = ((const char*)from)[0];
379 ((char*)to)[3] = ((const char*)from)[1];
380#else
381 ((char*)to)[0] = ((const char*)from)[1];
382 ((char*)to)[1] = ((const char*)from)[0];
383 ((char*)to)[2] = ((const char*)from)[3];
384 ((char*)to)[3] = ((const char*)from)[2];
385#endif
386}
387
388
389
390} //# NAMESPACE CASACORE - END
391
392#endif
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.
static void toLocal(double *to, const void *from, size_t nr)
static void fromLocal(void *to, char from)
Convert one value from local format to VAX format.
static void fromLocal(void *to, const float *from, size_t nr)
static void moveFloat(void *to, const void *from)
Move a float value (by swapping bytes correctly).
static void toLocal(char &to, const void *from)
Convert one value from VAX format to local format.
static void fromLocal(void *to, const double *from, size_t nr)
static void toLocal(float *to, const void *from, size_t nr)
VAXConversion()
This class should not be constructed (so declare the constructor private).
this file contains all the compiler specific defines
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
unsigned long long uInt64
Definition aipsxtype.h:37