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
80 public:
81 // Construct the object.
83
84 virtual ~DataConversion();
85
86 template <typename T>
87 size_t toLocalGeneric(T& to, const void* from) const {
88 return toLocal(to, from);
89 }
90
91 template <typename T>
92 size_t toLocalGeneric(T* to, const void* from, size_t nr) const {
93 return toLocal(to, from, nr);
94 }
95
96 template <typename T>
97 size_t fromLocalGeneric(void* to, T from) const {
98 return fromLocal(to, from);
99 }
100
101 template <typename T>
102 size_t fromLocalGeneric(void* to, const T* from, size_t nr) const {
103 return fromLocal(to, from, nr);
104 }
105
106 template <typename T>
107 bool canCopyGeneric() const {
108 return canCopy(static_cast<const T*>(nullptr));
109 }
110
111 template <typename T>
112 unsigned int externalSizeGeneric() const {
113 return externalSize(static_cast<const T*>(nullptr));
114 }
115
116 // Convert one value from foreign format to local format.
117 // The from and to buffer should not overlap.
118 // <note>
119 // The char version handles characters (thus may involve conversion
120 // EBCDIC to ASCII), while the unsigned chars are simply bytes.
121 // </note>
122 // <group>
123 virtual size_t toLocal(char& to, const void* from) const = 0;
124 virtual size_t toLocal(unsigned char& to, const void* from) const = 0;
125 virtual size_t toLocal(short& to, const void* from) const = 0;
126 virtual size_t toLocal(unsigned short& to, const void* from) const = 0;
127 virtual size_t toLocal(int& to, const void* from) const = 0;
128 virtual size_t toLocal(unsigned int& to, const void* from) const = 0;
129 virtual size_t toLocal(Int64& to, const void* from) const = 0;
130 virtual size_t toLocal(uInt64& to, const void* from) const = 0;
131 virtual size_t toLocal(float& to, const void* from) const = 0;
132 virtual size_t toLocal(double& to, const void* from) const = 0;
133 // </group>
134
135 // Convert nr values from foreign format to local format.
136 // The from and to buffer should not overlap.
137 // <note>
138 // The char version handles characters (thus may involve conversion
139 // EBCDIC to ASCII), while the unsigned chars are simply bytes.
140 // </note>
141 // <group>
142 virtual size_t toLocal(char* to, const void* from, size_t nr) const = 0;
143 virtual size_t toLocal(unsigned char* to, const void* from, size_t nr) const = 0;
144 virtual size_t toLocal(short* to, const void* from, size_t nr) const = 0;
145 virtual size_t toLocal(unsigned short* to, const void* from, size_t nr) const = 0;
146 virtual size_t toLocal(int* to, const void* from, size_t nr) const = 0;
147 virtual size_t toLocal(unsigned int* to, const void* from, size_t nr) const = 0;
148 virtual size_t toLocal(Int64* to, const void* from, size_t nr) const = 0;
149 virtual size_t toLocal(uInt64* to, const void* from, size_t nr) const = 0;
150 virtual size_t toLocal(float* to, const void* from, size_t nr) const = 0;
151 virtual size_t toLocal(double* to, const void* from, size_t nr) const = 0;
152 // </group>
153
154 // Convert one value from local format to foreign format.
155 // The from and to buffer should not overlap.
156 // <note>
157 // The char version handles characters (thus may involve conversion
158 // ASCII to EBCDIC), while the unsigned chars are simply bytes.
159 // </note>
160 // <group>
161 virtual size_t fromLocal(void* to, char from) const = 0;
162 virtual size_t fromLocal(void* to, unsigned char from) const = 0;
163 virtual size_t fromLocal(void* to, short from) const = 0;
164 virtual size_t fromLocal(void* to, unsigned short from) const = 0;
165 virtual size_t fromLocal(void* to, int from) const = 0;
166 virtual size_t fromLocal(void* to, unsigned int from) const = 0;
167 virtual size_t fromLocal(void* to, Int64 from) const = 0;
168 virtual size_t fromLocal(void* to, uInt64 from) const = 0;
169 virtual size_t fromLocal(void* to, float from) const = 0;
170 virtual size_t fromLocal(void* to, double from) const = 0;
171 // </group>
172
173 // Convert nr values from local format to foreign format.
174 // The from and to buffer should not overlap.
175 // <note>
176 // The char version handles characters (thus may involve conversion
177 // ASCII to EBCDIC), while the unsigned chars are simply bytes.
178 // </note>
179 // <group>
180 virtual size_t fromLocal(void* to, const char* from, size_t nr) const = 0;
181 virtual size_t fromLocal(void* to, const unsigned char* from, size_t nr) const = 0;
182 virtual size_t fromLocal(void* to, const short* from, size_t nr) const = 0;
183 virtual size_t fromLocal(void* to, const unsigned short* from, size_t nr) const = 0;
184 virtual size_t fromLocal(void* to, const int* from, size_t nr) const = 0;
185 virtual size_t fromLocal(void* to, const unsigned int* from, size_t nr) const = 0;
186 virtual size_t fromLocal(void* to, const Int64* from, size_t nr) const = 0;
187 virtual size_t fromLocal(void* to, const uInt64* from, size_t nr) const = 0;
188 virtual size_t fromLocal(void* to, const float* from, size_t nr) const = 0;
189 virtual size_t fromLocal(void* to, const double* from, size_t nr) const = 0;
190 // </group>
191
192 // Determine if the data for a data type can be simply copied, thus
193 // if no conversion is needed.
194 // <group>
195 virtual Bool canCopy(const char*) const = 0;
196 virtual Bool canCopy(const unsigned char*) const = 0;
197 virtual Bool canCopy(const short*) const = 0;
198 virtual Bool canCopy(const unsigned short*) const = 0;
199 virtual Bool canCopy(const int*) const = 0;
200 virtual Bool canCopy(const unsigned int*) const = 0;
201 virtual Bool canCopy(const Int64*) const = 0;
202 virtual Bool canCopy(const uInt64*) const = 0;
203 virtual Bool canCopy(const float*) const = 0;
204 virtual Bool canCopy(const double*) const = 0;
205 // </group>
206
207 // Get the external size of the data type.
208 // <group>
209 virtual unsigned int externalSize(const char*) const = 0;
210 virtual unsigned int externalSize(const unsigned char*) const = 0;
211 virtual unsigned int externalSize(const short*) const = 0;
212 virtual unsigned int externalSize(const unsigned short*) const = 0;
213 virtual unsigned int externalSize(const int*) const = 0;
214 virtual unsigned int externalSize(const unsigned int*) const = 0;
215 virtual unsigned int externalSize(const Int64*) const = 0;
216 virtual unsigned int externalSize(const uInt64*) const = 0;
217 virtual unsigned int externalSize(const float*) const = 0;
218 virtual unsigned int externalSize(const double*) const = 0;
219 // </group>
220};
221
223
224} // namespace casacore
225
226#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
size_t fromLocalGeneric(void *to, const T *from, size_t nr) const
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
size_t toLocalGeneric(T &to, const void *from) const
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
size_t toLocalGeneric(T *to, const void *from, size_t nr) const
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
unsigned int externalSizeGeneric() const
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
size_t fromLocalGeneric(void *to, T from) const
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
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
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
unsigned long long uInt64
Definition aipsxtype.h:37