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