casacore
Loading...
Searching...
No Matches
ModcompConversion.h
Go to the documentation of this file.
1//# ModCompConversion.h: A class with static functions to convert ModComp format
2//# Copyright (C) 1998,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_MODCOMPCONVERSION_H
27#define CASA_MODCOMPCONVERSION_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Utilities/Assert.h>
31#include <casacore/casa/OS/CanonicalConversion.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35// Define the canonical sizes of the built-in data types.
36// These are the same for all machine architectures.
37
38#define SIZE_MODCOMP_CHAR 1
39#define SIZE_MODCOMP_UCHAR 1
40#define SIZE_MODCOMP_SHORT 2
41#define SIZE_MODCOMP_USHORT 2
42#define SIZE_MODCOMP_INT 4
43#define SIZE_MODCOMP_UINT 4
44#define SIZE_MODCOMP_INT64 4
45#define SIZE_MODCOMP_UINT64 4
46#define SIZE_MODCOMP_FLOAT 4
47#define SIZE_MODCOMP_DOUBLE 8
48
49// Define for each data format if a conversion is needed from the ModComp
50// format to the local format (or vice-versa). This allows for optimizations
51// in, for example, AipsIO.
52
53// The ModComp format is ASCII for strings, a proprietary floating point format
54// and 2-complement for integers (all most significant bit first) with the
55// lengths as shown above.
56
57// Change the definitions below if new architectures (whith different lengths
58// for these integer types) are being used.
59#define CONVERT_MODCOMP_CHAR 0
60#define CONVERT_MODCOMP_UCHAR 0
61// Conversion is needed for little endian architectures (like DEC and Intel),
62// because the bytes have to be swapped (thus not for data with length 1).
63#if defined(AIPS_LITTLE_ENDIAN)
64#define CONVERT_MODCOMP_SHORT 1
65#define CONVERT_MODCOMP_USHORT 1
66#define CONVERT_MODCOMP_INT 1
67#define CONVERT_MODCOMP_UINT 1
68#define CONVERT_MODCOMP_INT64 1
69#define CONVERT_MODCOMP_UINT64 1
70#else
71// Conversion is not needed for integers if the local lengths for Shorts and
72// Ints is 2,4 respectively.
73#define CONVERT_MODCOMP_SHORT 0
74#define CONVERT_MODCOMP_USHORT 0
75#define CONVERT_MODCOMP_INT 0
76#define CONVERT_MODCOMP_UINT 0
77#define CONVERT_MODCOMP_INT64 1
78#define CONVERT_MODCOMP_UINT64 1
79#endif
80// Conversion is always needed for floating point data.
81#define CONVERT_MODCOMP_FLOAT 1
82#define CONVERT_MODCOMP_DOUBLE 1
83
84// <summary>Static functions to convert Modcomp numeric formats</summary>
85
86// <use visibility=export>
87
88// <reviewed reviewer="" date="yyyy/mm/dd" tests="tModcompConversion" demos="">
89// </reviewed>
90
91// <synopsis>
92// This class contains static toLocal functions to convert data from Modcomp
93// format to local format and vice-versa.
94//
95// The functions work on both big-endian and little-endian machines. They
96// convert between Modcomp 2-byte integers and Shorts (or uShorts) and Modcomp
97// 4-byte integers and Ints (or uInts, Int64s or uInt64s).
98//
99// It is currently not possible to convert floating point numbers from local
100// format to Modcomp. Attempting to do so will throw an exception (AipsError).
101// </synopsis>
102
103// <motivation>
104// The VLA data is stored using Modcomp numeric data formats and needs to be
105// converted to the local format to be manipulated.
106// </motivation>
107
108// <todo asof="$DATE$">
109// <li> Support conversion of floating point data to Modcomp format
110// <li> Support data type long double.
111// </todo>
112
113
115{
116public:
117 // Convert one value from Modcomp format to local format.
118 // The from and to buffer should not overlap.
119 // <group>
120 static size_t toLocal(Char& to, const void* from);
121 static size_t toLocal(uChar& to, const void* from);
122 static size_t toLocal(Short& to, const void* from);
123 static size_t toLocal(uShort& to, const void* from);
124 static size_t toLocal(Int& to, const void* from);
125 static size_t toLocal(uInt& to, const void* from);
126 static size_t toLocal(Int64& to, const void* from);
127 static size_t toLocal(uInt64& to, const void* from);
128 static size_t toLocal(Float& to, const void* from);
129 static size_t toLocal(Double& to, const void* from);
130 // </group>
131
132 // Convert nr values from Modcomp format to local format.
133 // The from and to buffer should not overlap.
134 // <group>
135 static size_t toLocal(Char* to, const void* from, size_t nr);
136 static size_t toLocal(uChar* to, const void* from, size_t nr);
137 static size_t toLocal(Short* to, const void* from, size_t nr);
138 static size_t toLocal(uShort* to, const void* from, size_t nr);
139 static size_t toLocal(Int* to, const void* from, size_t nr);
140 static size_t toLocal(uInt* to, const void* from, size_t nr);
141 static size_t toLocal(Int64* to, const void* from, size_t nr);
142 static size_t toLocal(uInt64* to, const void* from, size_t nr);
143 static size_t toLocal(Float* to, const void* from, size_t nr);
144 static size_t toLocal(Double* to, const void* from, size_t nr);
145 // </group>
146
147 // Convert one value from local format to Modcomp format. The from and to
148 // buffer should not overlap. The floating point functions will throw
149 // exceptions as they are not implemented yet.
150 // <group>
151 static size_t fromLocal(void* to, Char from);
152 static size_t fromLocal(void* to, uChar from);
153 static size_t fromLocal(void* to, Short from);
154 static size_t fromLocal(void* to, uShort from);
155 static size_t fromLocal(void* to, Int from);
156 static size_t fromLocal(void* to, uInt from);
157 static size_t fromLocal(void* to, Int64 from);
158 static size_t fromLocal(void* to, uInt64 from);
159 static size_t fromLocal(void* to, Float from);
160 static size_t fromLocal(void* to, Double from);
161 // </group>
162
163 // Convert nr values from local format to Modcomp format. The from and to
164 // buffer should not overlap. The floating point functions will throw
165 // exceptions as they are not implemented yet.
166 // <group>
167 static size_t fromLocal(void* to, const Char* from, size_t nr);
168 static size_t fromLocal(void* to, const uChar* from, size_t nr);
169 static size_t fromLocal(void* to, const Short* from, size_t nr);
170 static size_t fromLocal(void* to, const uShort* from, size_t nr);
171 static size_t fromLocal(void* to, const Int* from, size_t nr);
172 static size_t fromLocal(void* to, const uInt* from, size_t nr);
173 static size_t fromLocal(void* to, const Int64* from, size_t nr);
174 static size_t fromLocal(void* to, const uInt64* from, size_t nr);
175 static size_t fromLocal(void* to, const Float* from, size_t nr);
176 static size_t fromLocal(void* to, const Double* from, size_t nr);
177 // </group>
178
179private:
180 // This class should not be constructed
181 // (so declare the constructor private).
183};
184
185inline size_t ModcompConversion::toLocal(Char& to, const void* from) {
186 return CanonicalConversion::toLocal(to, from);
187}
188
189inline size_t ModcompConversion::toLocal(uChar& to, const void* from) {
190 return CanonicalConversion::toLocal(to, from);
191}
192
193inline size_t ModcompConversion::toLocal(Short& to, const void* from) {
194 return CanonicalConversion::toLocal(to, from);
195}
196
197inline size_t ModcompConversion::toLocal(uShort& to, const void* from) {
198 return CanonicalConversion::toLocal(to, from);
199}
200
201inline size_t ModcompConversion::toLocal(Int& to, const void* from) {
202 return CanonicalConversion::toLocal(to, from);
203}
204
205inline size_t ModcompConversion::toLocal(uInt& to, const void* from) {
206 return CanonicalConversion::toLocal(to, from);
207}
208
209inline size_t ModcompConversion::toLocal(Int64& to, const void* from) {
210 Int tmp;
211 size_t res = toLocal (tmp, from);
212 to = tmp;
213 return res;
214}
215
216inline size_t ModcompConversion::toLocal(uInt64& to, const void* from) {
217 uInt tmp;
218 size_t res = toLocal (tmp, from);
219 to = tmp;
220 return res;
221}
222
223inline size_t ModcompConversion::toLocal(Float& to, const void* from) {
224 return ModcompConversion::toLocal(&to, from, 1u);
225}
226
227inline size_t ModcompConversion::toLocal(Double& to, const void* from) {
228 return ModcompConversion::toLocal(&to, from, 1u);
229}
230
231inline size_t ModcompConversion::toLocal(Char* to, const void* from, size_t nr) {
232 return CanonicalConversion::toLocalChar(to, from, nr);
233}
234
235inline size_t ModcompConversion::toLocal(uChar* to, const void* from, size_t nr) {
236 return CanonicalConversion::toLocalUChar(to, from, nr);
237}
238
239inline size_t ModcompConversion::toLocal(Short* to, const void* from, size_t nr) {
240 return CanonicalConversion::toLocalShort(to, from, nr);
241}
242
243inline size_t ModcompConversion::toLocal(uShort* to, const void* from, size_t nr) {
244 return CanonicalConversion::toLocalUShort(to, from, nr);
245}
246
247inline size_t ModcompConversion::toLocal(Int* to, const void* from, size_t nr) {
248 return CanonicalConversion::toLocalInt(to, from, nr);
249}
250
251inline size_t ModcompConversion::toLocal(uInt* to, const void* from, size_t nr) {
252 return CanonicalConversion::toLocalUInt(to, from, nr);
253}
254
255inline size_t ModcompConversion::fromLocal(void* to, Char from) {
256 return CanonicalConversion::fromLocal(to, from);
257}
258
259inline size_t ModcompConversion::fromLocal(void* to, uChar from) {
260 return CanonicalConversion::fromLocal(to, from);
261}
262
263inline size_t ModcompConversion::fromLocal(void* to, Short from) {
264 return CanonicalConversion::fromLocal (to, from);
265}
266
267inline size_t ModcompConversion::fromLocal(void* to, uShort from) {
268 return CanonicalConversion::fromLocal(to, from);
269}
270
271inline size_t ModcompConversion::fromLocal(void* to, Int from) {
272 return CanonicalConversion::fromLocal (to, from);
273}
274
275inline size_t ModcompConversion::fromLocal(void* to, uInt from) {
276 return CanonicalConversion::fromLocal (to, from);
277}
278
279inline size_t ModcompConversion::fromLocal(void* to, Int64 from) {
280 return CanonicalConversion::fromLocal (to, (Int) from);
281}
282
283inline size_t ModcompConversion::fromLocal(void* to, uInt64 from) {
284 return CanonicalConversion::fromLocal (to, (uInt) from);
285}
286
287inline size_t ModcompConversion::fromLocal(void* to, Float from) {
288 return ModcompConversion::fromLocal(to, &from, 1u);
289}
290
291inline size_t ModcompConversion::fromLocal(void* to, Double from) {
292 return ModcompConversion::fromLocal(to, &from, 1u);
293}
294
295inline size_t ModcompConversion::fromLocal(void* to, const Char* from, size_t nr) {
296 return CanonicalConversion::fromLocalChar(to, from, nr);
297}
298
299inline size_t ModcompConversion::fromLocal(void* to, const uChar* from, size_t nr){
300 return CanonicalConversion::fromLocalUChar(to, from, nr);
301}
302
303inline size_t ModcompConversion::fromLocal(void* to, const Short* from, size_t nr){
304 return CanonicalConversion::fromLocalShort(to, from, nr);
305}
306
307inline size_t ModcompConversion::fromLocal(void* to, const uShort* from,size_t nr){
308 return CanonicalConversion::fromLocalUShort(to, from, nr);
309}
310
311inline size_t ModcompConversion::fromLocal(void* to, const Int* from, size_t nr) {
312 return CanonicalConversion::fromLocalInt(to, from, nr);
313}
314
315inline size_t ModcompConversion::fromLocal(void* to, const uInt* from, size_t nr) {
316 return CanonicalConversion::fromLocalUInt(to, from, nr);
317}
318
319
320
321} //# NAMESPACE CASACORE - END
322
323#endif
static size_t toLocalChar(void *to, const void *from, size_t nr)
Convert nr values from canonical format to local format.
static size_t fromLocalChar(void *to, const void *from, size_t nr)
Convert nr values from local format to canonical format.
static size_t fromLocalUShort(void *to, const void *from, size_t nr)
static size_t fromLocalUChar(void *to, const void *from, size_t nr)
static size_t toLocalInt(void *to, const void *from, size_t nr)
static size_t fromLocal(void *to, const char &from)
Convert one value from local format to canonical format.
static size_t toLocal(char &to, const void *from)
Convert one value from canonical format to local format.
static size_t toLocalUChar(void *to, const void *from, size_t nr)
static size_t fromLocalShort(void *to, const void *from, size_t nr)
static size_t toLocalUInt(void *to, const void *from, size_t nr)
static size_t toLocalUShort(void *to, const void *from, size_t nr)
static size_t fromLocalInt(void *to, const void *from, size_t nr)
static size_t toLocalShort(void *to, const void *from, size_t nr)
static size_t fromLocalUInt(void *to, const void *from, size_t nr)
static size_t fromLocal(void *to, Char from)
Convert one value from local format to Modcomp format.
static size_t toLocal(Char &to, const void *from)
Convert one value from Modcomp format to local format.
static size_t fromLocal(void *to, const Int64 *from, size_t nr)
static size_t toLocal(Float *to, const void *from, size_t nr)
static size_t fromLocal(void *to, const Double *from, size_t nr)
ModcompConversion()
This class should not be constructed (so declare the constructor private).
static size_t toLocal(uInt64 *to, const void *from, size_t nr)
static size_t toLocal(Int64 *to, const void *from, size_t nr)
static size_t toLocal(Double *to, const void *from, size_t nr)
static size_t fromLocal(void *to, const Float *from, size_t nr)
static size_t fromLocal(void *to, const uInt64 *from, size_t nr)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44
unsigned long long uInt64
Definition aipsxtype.h:37