casacore
DataConversion.h
Go to the documentation of this file.
1 //# DataConversion.h: Abstract base class with functions to convert any format
2 //# Copyright (C) 1996,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_DATACONVERSION_H
29 #define CASA_DATACONVERSION_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/OS/Conversion.h>
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 // <summary>
38 // Abstract base class with functions to convert any format
39 // </summary>
40 
41 // <use visibility=export>
42 
43 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tDataConversion" demos="">
44 // </reviewed>
45 
46 // <synopsis>
47 // This abstract base class contains pure virtual functions to convert
48 // from any foreign data format to local format and vice-versa.
49 // Classes derived from it implement the functions for a specific
50 // foreign format (e.g.
51 // <linkto class=CanonicalDataConversion:description>CanonicalDataConversion
52 // </linkto>,
53 // <linkto class=VAXDataConversion:description>VAXDataConversion</linkto>,
54 // <linkto class=IBMDataConversion:description>IBMDataConversion</linkto>).
55 // <linkto class=RawDataConversion:description>RawDataConversion</linkto>).
56 // </synopsis>
57 
58 // <example>
59 // <srcblock>
60 // // Construct the correct conversion object.
61 // DataConversion* conv = new IBMDataConversion();
62 // // Say that you read a block of 256 floats (in IBM-format).
63 // char buffer[1024];
64 // read (fd, buffer, 1024);
65 // // Convert the float to local format.
66 // float values[256];
67 // conv->toLocal (values, buffer, 256);
68 // </srcblock>
69 // </example>
70 
71 // <motivation>
72 // The abstract base class allows one to construct the correct conversion
73 // object at the beginning. Thereafter this base class can be used and
74 // polymorphism takes care of picking the correct functions.
75 // </motivation>
76 
77 // <todo asof="$DATE$">
78 // <li> Support data type long double.
79 // </todo>
80 
81 
83 {
84 public:
85  // Construct the object.
87 
88  virtual ~DataConversion();
89 
90  // Convert one value from foreign format to local format.
91  // The from and to buffer should not overlap.
92  // <note>
93  // The char version handles characters (thus may involve conversion
94  // EBCDIC to ASCII), while the unsigned chars are simply bytes.
95  // </note>
96  // <group>
97  virtual size_t toLocal (char& to,
98  const void* from) const = 0;
99  virtual size_t toLocal (unsigned char& to,
100  const void* from) const = 0;
101  virtual size_t toLocal (short& to,
102  const void* from) const = 0;
103  virtual size_t toLocal (unsigned short& to,
104  const void* from) const = 0;
105  virtual size_t toLocal (int& to,
106  const void* from) const = 0;
107  virtual size_t toLocal (unsigned int& to,
108  const void* from) const = 0;
109  virtual size_t toLocal (Int64& to,
110  const void* from) const = 0;
111  virtual size_t toLocal (uInt64& to,
112  const void* from) const = 0;
113  virtual size_t toLocal (float& to,
114  const void* from) const = 0;
115  virtual size_t toLocal (double& to,
116  const void* from) const = 0;
117  // </group>
118 
119  // Convert nr values from foreign format to local format.
120  // The from and to buffer should not overlap.
121  // <note>
122  // The char version handles characters (thus may involve conversion
123  // EBCDIC to ASCII), while the unsigned chars are simply bytes.
124  // </note>
125  // <group>
126  virtual size_t toLocal (char* to, const void* from,
127  size_t nr) const = 0;
128  virtual size_t toLocal (unsigned char* to, const void* from,
129  size_t nr) const = 0;
130  virtual size_t toLocal (short* to, const void* from,
131  size_t nr) const = 0;
132  virtual size_t toLocal (unsigned short* to, const void* from,
133  size_t nr) const = 0;
134  virtual size_t toLocal (int* to, const void* from,
135  size_t nr) const = 0;
136  virtual size_t toLocal (unsigned int* to, const void* from,
137  size_t nr) const = 0;
138  virtual size_t toLocal (Int64* to, const void* from,
139  size_t nr) const = 0;
140  virtual size_t toLocal (uInt64* to, const void* from,
141  size_t nr) const = 0;
142  virtual size_t toLocal (float* to, const void* from,
143  size_t nr) const = 0;
144  virtual size_t toLocal (double* to, const void* from,
145  size_t nr) const = 0;
146  // </group>
147 
148  // Convert one value from local format to foreign format.
149  // The from and to buffer should not overlap.
150  // <note>
151  // The char version handles characters (thus may involve conversion
152  // ASCII to EBCDIC), while the unsigned chars are simply bytes.
153  // </note>
154  // <group>
155  virtual size_t fromLocal (void* to, char from) const = 0;
156  virtual size_t fromLocal (void* to, unsigned char from) const = 0;
157  virtual size_t fromLocal (void* to, short from) const = 0;
158  virtual size_t fromLocal (void* to, unsigned short from) const = 0;
159  virtual size_t fromLocal (void* to, int from) const = 0;
160  virtual size_t fromLocal (void* to, unsigned int from) const = 0;
161  virtual size_t fromLocal (void* to, Int64 from) const = 0;
162  virtual size_t fromLocal (void* to, uInt64 from) const = 0;
163  virtual size_t fromLocal (void* to, float from) const = 0;
164  virtual size_t fromLocal (void* to, double from) const = 0;
165  // </group>
166 
167  // Convert nr values from local format to foreign format.
168  // The from and to buffer should not overlap.
169  // <note>
170  // The char version handles characters (thus may involve conversion
171  // ASCII to EBCDIC), while the unsigned chars are simply bytes.
172  // </note>
173  // <group>
174  virtual size_t fromLocal (void* to, const char* from,
175  size_t nr) const = 0;
176  virtual size_t fromLocal (void* to, const unsigned char* from,
177  size_t nr) const = 0;
178  virtual size_t fromLocal (void* to, const short* from,
179  size_t nr) const = 0;
180  virtual size_t fromLocal (void* to, const unsigned short* from,
181  size_t nr) const = 0;
182  virtual size_t fromLocal (void* to, const int* from,
183  size_t nr) const = 0;
184  virtual size_t fromLocal (void* to, const unsigned int* from,
185  size_t nr) const = 0;
186  virtual size_t fromLocal (void* to, const Int64* from,
187  size_t nr) const = 0;
188  virtual size_t fromLocal (void* to, const uInt64* from,
189  size_t nr) const = 0;
190  virtual size_t fromLocal (void* to, const float* from,
191  size_t nr) const = 0;
192  virtual size_t fromLocal (void* to, const double* from,
193  size_t nr) const = 0;
194  // </group>
195 
196  // Determine if the data for a data type can be simply copied, thus
197  // if no conversion is needed.
198  // <group>
199  virtual Bool canCopy (const char*) const = 0;
200  virtual Bool canCopy (const unsigned char*) const = 0;
201  virtual Bool canCopy (const short*) const = 0;
202  virtual Bool canCopy (const unsigned short*) const = 0;
203  virtual Bool canCopy (const int*) const = 0;
204  virtual Bool canCopy (const unsigned int*) const = 0;
205  virtual Bool canCopy (const Int64*) const = 0;
206  virtual Bool canCopy (const uInt64*) const = 0;
207  virtual Bool canCopy (const float*) const = 0;
208  virtual Bool canCopy (const double*) const = 0;
209  // </group>
210 
211  // Get the external size of the data type.
212  // <group>
213  virtual unsigned int externalSize (const char*) const = 0;
214  virtual unsigned int externalSize (const unsigned char*) const = 0;
215  virtual unsigned int externalSize (const short*) const = 0;
216  virtual unsigned int externalSize (const unsigned short*) const = 0;
217  virtual unsigned int externalSize (const int*) const = 0;
218  virtual unsigned int externalSize (const unsigned int*) const = 0;
219  virtual unsigned int externalSize (const Int64*) const = 0;
220  virtual unsigned int externalSize (const uInt64*) const = 0;
221  virtual unsigned int externalSize (const float*) const = 0;
222  virtual unsigned int externalSize (const double*) const = 0;
223  // </group>
224 };
225 
226 
228 {}
229 
230 
231 
232 } //# NAMESPACE CASACORE - END
233 
234 #endif
virtual size_t toLocal(int *to, const void *from, size_t nr) const =0
virtual size_t toLocal(short &to, const void *from) const =0
virtual size_t toLocal(short *to, const void *from, size_t nr) const =0
virtual size_t fromLocal(void *to, const char *from, size_t nr) const =0
Convert nr values from local format to foreign format.
virtual unsigned int externalSize(const float *) const =0
virtual size_t fromLocal(void *to, unsigned short from) const =0
virtual size_t fromLocal(void *to, const unsigned short *from, size_t nr) const =0
virtual size_t toLocal(Int64 *to, const void *from, size_t nr) const =0
virtual Bool canCopy(const uInt64 *) const =0
virtual size_t fromLocal(void *to, const short *from, size_t nr) const =0
virtual unsigned int externalSize(const short *) const =0
virtual Bool canCopy(const unsigned short *) const =0
virtual size_t fromLocal(void *to, short from) const =0
virtual size_t fromLocal(void *to, const unsigned int *from, size_t nr) const =0
virtual unsigned int externalSize(const Int64 *) const =0
virtual Bool canCopy(const unsigned char *) const =0
virtual size_t fromLocal(void *to, const double *from, size_t nr) const =0
virtual size_t fromLocal(void *to, int from) const =0
virtual size_t fromLocal(void *to, const unsigned char *from, size_t nr) const =0
virtual Bool canCopy(const float *) const =0
virtual size_t fromLocal(void *to, const uInt64 *from, size_t nr) const =0
virtual size_t toLocal(double &to, const void *from) const =0
virtual size_t toLocal(char *to, const void *from, size_t nr) const =0
Convert nr values from foreign format to local format.
virtual size_t toLocal(int &to, const void *from) const =0
virtual size_t toLocal(uInt64 *to, const void *from, size_t nr) const =0
virtual size_t toLocal(unsigned short &to, const void *from) const =0
virtual size_t toLocal(float &to, const void *from) const =0
virtual size_t toLocal(double *to, const void *from, size_t nr) const =0
virtual unsigned int externalSize(const char *) const =0
Get the external size of the data type.
virtual unsigned int externalSize(const double *) const =0
virtual Bool canCopy(const short *) const =0
virtual size_t fromLocal(void *to, const Int64 *from, size_t nr) const =0
virtual size_t fromLocal(void *to, const float *from, size_t nr) const =0
virtual size_t toLocal(Int64 &to, const void *from) const =0
virtual size_t fromLocal(void *to, char from) const =0
Convert one value from local format to foreign format.
virtual unsigned int externalSize(const int *) const =0
virtual unsigned int externalSize(const unsigned int *) const =0
virtual size_t toLocal(unsigned int *to, const void *from, size_t nr) const =0
virtual size_t fromLocal(void *to, uInt64 from) const =0
virtual size_t fromLocal(void *to, float from) const =0
virtual Bool canCopy(const int *) const =0
virtual size_t toLocal(float *to, const void *from, size_t nr) const =0
virtual size_t toLocal(unsigned char &to, const void *from) const =0
virtual size_t fromLocal(void *to, double from) const =0
virtual size_t toLocal(unsigned int &to, const void *from) const =0
virtual size_t fromLocal(void *to, unsigned char from) const =0
virtual Bool canCopy(const Int64 *) const =0
virtual size_t toLocal(uInt64 &to, const void *from) const =0
virtual size_t fromLocal(void *to, const int *from, size_t nr) const =0
virtual Bool canCopy(const unsigned int *) const =0
virtual Bool canCopy(const double *) const =0
DataConversion()
Construct the object.
virtual unsigned int externalSize(const unsigned char *) const =0
virtual size_t toLocal(unsigned char *to, const void *from, size_t nr) const =0
virtual size_t fromLocal(void *to, Int64 from) const =0
virtual unsigned int externalSize(const unsigned short *) const =0
virtual size_t toLocal(unsigned short *to, const void *from, size_t nr) const =0
virtual unsigned int externalSize(const uInt64 *) const =0
virtual size_t toLocal(char &to, const void *from) const =0
Convert one value from foreign format to local format.
virtual Bool canCopy(const char *) const =0
Determine if the data for a data type can be simply copied, thus if no conversion is needed.
virtual size_t fromLocal(void *to, unsigned int from) const =0
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:38
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
unsigned long long uInt64
Definition: aipsxtype.h:39