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