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
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// Define the canonical sizes of the built-in data types.
37// These are the same for all machine architectures.
38
39#define SIZE_VAX_CHAR 1
40#define SIZE_VAX_UCHAR 1
41#define SIZE_VAX_SHORT 2
42#define SIZE_VAX_USHORT 2
43#define SIZE_VAX_INT 4
44#define SIZE_VAX_UINT 4
45#define SIZE_VAX_INT64 4
46#define SIZE_VAX_UINT64 4
47#define SIZE_VAX_FLOAT 4
48#define SIZE_VAX_DOUBLE 8
49
50// <summary>
51// A class with static functions to convert VAX format
52// </summary>
53
54// <use visibility=export>
55
56// <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tVAXConversion" demos="">
57// </reviewed>
58
59// <synopsis>
60// This class contains static toLocal functions to convert data from VAX
61// format to local format and vice-versa. It only handles VAX D-float format.
62// Another class should be implemented to handle VAX G-float format.
63// <p>
64// The functions work well on big-endian as well as little-endian machines.
65// </synopsis>
66
67// <motivation>
68// Archived WSRT data can be stored in the old VAX format
69// (little-endian and VAX D-float floating point format).
70// Conversion functions are needed to read these data.
71// </motivation>
72
73// <todo asof="$DATE$">
74// <li> Support data type long double.
75// </todo>
76
78 public:
79 // Convert one value from VAX format to local format.
80 // The from and to buffer should not overlap.
81 // <group>
82 static void toLocal(char& to, const void* from);
83 static void toLocal(unsigned char& to, const void* from);
84 static void toLocal(short& to, const void* from);
85 static void toLocal(unsigned short& to, const void* from);
86 static void toLocal(int& to, const void* from);
87 static void toLocal(unsigned int& to, const void* from);
88 static void toLocal(Int64& to, const void* from);
89 static void toLocal(uInt64& to, const void* from);
90 static void toLocal(float& to, const void* from);
91 static void toLocal(double& to, const void* from);
92 // </group>
93
94 // Convert nr values from VAX format to local format.
95 // The from and to buffer should not overlap.
96 // <group>
97 static void toLocal(char* to, const void* from, size_t nr);
98 static void toLocal(unsigned char* to, const void* from, size_t nr);
99 static void toLocal(short* to, const void* from, size_t nr);
100 static void toLocal(unsigned short* to, const void* from, size_t nr);
101 static void toLocal(int* to, const void* from, size_t nr);
102 static void toLocal(unsigned int* to, const void* from, size_t nr);
103 static void toLocal(Int64* to, const void* from, size_t nr);
104 static void toLocal(uInt64* to, const void* from, size_t nr);
105 static void toLocal(float* to, const void* from, size_t nr);
106 static void toLocal(double* to, const void* from, size_t nr);
107 // </group>
108
109 // Convert one value from local format to VAX format.
110 // The from and to buffer should not overlap.
111 // <group>
112 static void fromLocal(void* to, char from);
113 static void fromLocal(void* to, unsigned char from);
114 static void fromLocal(void* to, short from);
115 static void fromLocal(void* to, unsigned short from);
116 static void fromLocal(void* to, int from);
117 static void fromLocal(void* to, unsigned int from);
118 static void fromLocal(void* to, Int64 from);
119 static void fromLocal(void* to, uInt64 from);
120 static void fromLocal(void* to, float from);
121 static void fromLocal(void* to, double from);
122 // </group>
123
124 // Convert nr values from local format to VAX format.
125 // The from and to buffer should not overlap.
126 // <group>
127 static void fromLocal(void* to, const char* from, size_t nr);
128 static void fromLocal(void* to, const unsigned char* from, size_t nr);
129 static void fromLocal(void* to, const short* from, size_t nr);
130 static void fromLocal(void* to, const unsigned short* from, size_t nr);
131 static void fromLocal(void* to, const int* from, size_t nr);
132 static void fromLocal(void* to, const unsigned int* from, size_t nr);
133 static void fromLocal(void* to, const Int64* from, size_t nr);
134 static void fromLocal(void* to, const uInt64* from, size_t nr);
135 static void fromLocal(void* to, const float* from, size_t nr);
136 static void fromLocal(void* to, const double* from, size_t nr);
137 // </group>
138
139 // Move a float value (by swapping bytes correctly).
140 static void moveFloat(void* to, const void* from);
141
142 private:
143 // This class should not be constructed
144 // (so declare the constructor private).
146};
147
148inline void VAXConversion::toLocal(char& to, const void* from) {
150}
151
152inline void VAXConversion::toLocal(unsigned char& to, const void* from) {
154}
155
156inline void VAXConversion::toLocal(short& to, const void* from) {
158}
159
160inline void VAXConversion::toLocal(unsigned short& to, const void* from) {
162}
163
164inline void VAXConversion::toLocal(int& to, const void* from) {
166}
167
168inline void VAXConversion::toLocal(unsigned int& to, const void* from) {
170}
171
172inline void VAXConversion::toLocal(Int64& to, const void* from) {
174}
175
176inline void VAXConversion::toLocal(uInt64& to, const void* from) {
178}
179
180inline void VAXConversion::toLocal(float& to, const void* from) { toLocal(&to, from, 1); }
181
182inline void VAXConversion::toLocal(double& to, const void* from) { toLocal(&to, from, 1); }
183
184inline void VAXConversion::toLocal(char* to, const void* from, size_t nr) {
186}
187
188inline void VAXConversion::toLocal(unsigned char* to, const void* from, size_t nr) {
190}
191
192inline void VAXConversion::toLocal(short* to, const void* from, size_t nr) {
194}
195
196inline void VAXConversion::toLocal(unsigned short* to, const void* from, size_t nr) {
198}
199
200inline void VAXConversion::toLocal(int* to, const void* from, size_t nr) {
202}
203
204inline void VAXConversion::toLocal(unsigned int* to, const void* from, size_t nr) {
206}
207
208inline void VAXConversion::toLocal(Int64* to, const void* from, size_t nr) {
210}
211
212inline void VAXConversion::toLocal(uInt64* to, const void* from, size_t nr) {
214}
215
216inline void VAXConversion::fromLocal(void* to, char from) {
218}
219
220inline void VAXConversion::fromLocal(void* to, unsigned char from) {
222}
223
224inline void VAXConversion::fromLocal(void* to, short from) {
226}
227
228inline void VAXConversion::fromLocal(void* to, unsigned short from) {
230}
231
232inline void VAXConversion::fromLocal(void* to, int from) {
234}
235
236inline void VAXConversion::fromLocal(void* to, unsigned int from) {
238}
239
240inline void VAXConversion::fromLocal(void* to, Int64 from) {
242}
243
244inline void VAXConversion::fromLocal(void* to, uInt64 from) {
246}
247
248inline void VAXConversion::fromLocal(void* to, float from) { fromLocal(to, &from, 1); }
249
250inline void VAXConversion::fromLocal(void* to, double from) { fromLocal(to, &from, 1); }
251
252inline void VAXConversion::fromLocal(void* to, const char* from, size_t nr) {
254}
255
256inline void VAXConversion::fromLocal(void* to, const unsigned char* from, size_t nr) {
258}
259
260inline void VAXConversion::fromLocal(void* to, const short* from, size_t nr) {
262}
263
264inline void VAXConversion::fromLocal(void* to, const unsigned short* from, size_t nr) {
266}
267
268inline void VAXConversion::fromLocal(void* to, const int* from, size_t nr) {
270}
271
272inline void VAXConversion::fromLocal(void* to, const unsigned int* from, size_t nr) {
274}
275
276inline void VAXConversion::fromLocal(void* to, const Int64* from, size_t nr) {
278}
279
280inline void VAXConversion::fromLocal(void* to, const uInt64* from, size_t nr) {
282}
283
284inline void VAXConversion::moveFloat(void* to, const void* from) {
285#if defined(AIPS_LITTLE_ENDIAN)
286 ((char*)to)[0] = ((const char*)from)[2];
287 ((char*)to)[1] = ((const char*)from)[3];
288 ((char*)to)[2] = ((const char*)from)[0];
289 ((char*)to)[3] = ((const char*)from)[1];
290#else
291 ((char*)to)[0] = ((const char*)from)[1];
292 ((char*)to)[1] = ((const char*)from)[0];
293 ((char*)to)[2] = ((const char*)from)[3];
294 ((char*)to)[3] = ((const char*)from)[2];
295#endif
296}
297
298} // namespace casacore
299
300#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).
For temporary backward namespace compatibility, use casa as alias for casacore.
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