casacore
Loading...
Searching...
No Matches
ValType.h
Go to the documentation of this file.
1// # ValType.h: Data types and their undefined values
2// # Copyright (C) 1993,1994,1995,1996,1998,2001,2002
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_VALTYPE_H
27#define CASA_VALTYPE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Utilities/DataType.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/BasicSL/Complex.h>
34#include <casacore/casa/Utilities/Compare.h>
35#include <casacore/casa/OS/Conversion.h>
36#include <casacore/casa/IO/AipsIO.h>
37#include <casacore/casa/iosfwd.h>
38#include <memory>
39
40namespace casacore { // # NAMESPACE CASACORE - BEGIN
41
42// # Forward Declarations
43class TableRecord;
44
45// <summary>
46// Data types and their undefined values.
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="Friso olnon" date="1995/03/20" tests="" demos="">
52// </reviewed>
53
54// <prerequisite>
55// <li> enum <linkto group="DataType.h#DataType">DataType</linkto>
56// </prerequisite>
57
58// <synopsis>
59// Class <src>ValType</src> describes the data types and their
60// "undefined values".
61//
62// Supported are built-in data types, <src>Bool</src>,
63// <src>String</src>, <src>Complex</src> and <src>DComplex</src>.
64// As a rule, the smallest possible value of a data type is used as its
65// "undefined value"; for <src>String</src> we use the null string, and
66// for <src>Bool</src> the value <em>False</em>.
67//
68// The class does not contain data. It merely defines constants and
69// has overloaded functions that return in some form the "undefined
70// value", the data type, or certain other information about the data
71// type.
72// </synopsis>
73
74class ValType {
75 public:
76 // Get the "undefined value" for this data type as the function's
77 // return value.
78 //<group>
79 static Bool undefBool();
80 static Char undefChar();
81 static uChar undefUChar();
82 static Short undefShort();
83 static uShort undefUShort();
84 static Int undefInt();
85 static uInt undefUInt();
86 static Int64 undefInt64();
87 static float undefFloat();
88 static double undefDouble();
89 static Complex undefComplex();
90 static DComplex undefDComplex();
91 static String undefString();
92 //</group>
93
94 // Get the "undefined value" for this data type in the argument.
95 // The <src>void*</src> function is not doing anything and is for
96 // TpOther types.
97 //<group>
98 static void getUndef(Bool*);
99 static void getUndef(Char*);
100 static void getUndef(uChar*);
101 static void getUndef(Short*);
102 static void getUndef(uShort*);
103 static void getUndef(Int*);
104 static void getUndef(uInt*);
105 static void getUndef(Int64*);
106 static void getUndef(float*);
107 static void getUndef(double*);
108 static void getUndef(Complex*);
109 static void getUndef(DComplex*);
110 static void getUndef(String*);
111 static void getUndef(void*);
112 //</group>
113
114 // Get the data type code for this type as the function's
115 // return value.
116 //<group>
117 static DataType getType(const Bool*);
118 static DataType getType(const Char*);
119 static DataType getType(const uChar*);
120 static DataType getType(const Short*);
121 static DataType getType(const uShort*);
122 static DataType getType(const Int*);
123 static DataType getType(const uInt*);
124 static DataType getType(const Int64*);
125 static DataType getType(const float*);
126 static DataType getType(const double*);
127 static DataType getType(const Complex*);
128 static DataType getType(const DComplex*);
129 static DataType getType(const String*);
130 static DataType getType(const TableRecord*);
131 static DataType getType(const void*);
132 //</group>
133
134 // Get the name of the data type. The <src>void*</src> returns
135 // the string "Other ".
136 //<group>
137 static const String& getTypeStr(DataType);
138 static const String& getTypeStr(const Bool*);
139 static const String& getTypeStr(const Char*);
140 static const String& getTypeStr(const uChar*);
141 static const String& getTypeStr(const Short*);
142 static const String& getTypeStr(const uShort*);
143 static const String& getTypeStr(const Int*);
144 static const String& getTypeStr(const uInt*);
145 static const String& getTypeStr(const Int64*);
146 static const String& getTypeStr(const float*);
147 static const String& getTypeStr(const double*);
148 static const String& getTypeStr(const Complex*);
149 static const String& getTypeStr(const DComplex*);
150 static const String& getTypeStr(const String*);
151 static const String& getTypeStr(const TableRecord*);
152 static const String& getTypeStr(const void*);
153 //</group>
154
155 // Get the size of data type (in local format).
156 static int getTypeSize(DataType);
157
158 // Get the size of data type in canonical format.
159 // <br>The argument <src>BECanonical</src> determines if the big-endian
160 // or little-endian canonical format is used.
161 static int getCanonicalSize(DataType, Bool BECanonical = True);
162
163 // Get the functions to convert to/from canonical format.
164 // These functions take the number of pixels as the length argument.
165 // It returns the number of elements per value; normally this is 1,
166 // but for complex values it is 2 (since they convert float/double).
167 // <br>The argument <src>BECanonical</src> determines if the big-endian
168 // or little-endian canonical format is used.
169 static void getCanonicalFunc(DataType dt, Conversion::ValueFunction*& readFunc,
170 Conversion::ValueFunction*& writeFunc, uInt& nrElementsPerValue,
171 Bool BECanonical = True);
172
173 // Test if a data type can be promoted to another.
174 static Bool isPromotable(DataType from, DataType to);
175
176 // Get the pointer to the routine which compares two values.
177 static ObjCompareFunc* getCmpFunc(DataType);
178
179 // Get the object which compares two values.
180 static std::shared_ptr<BaseCompare> getCmpObj(DataType);
181
182 // Put the value into <src>AipsIO</src>.
183 // The <src>void*</src> function is not doing anything and is for
184 // TpOther types.
185 //<group>
186 static void put(AipsIO&, const Bool*);
187 static void put(AipsIO&, const Char*);
188 static void put(AipsIO&, const uChar*);
189 static void put(AipsIO&, const Short*);
190 static void put(AipsIO&, const uShort*);
191 static void put(AipsIO&, const Int*);
192 static void put(AipsIO&, const uInt*);
193 static void put(AipsIO&, const Int64*);
194 static void put(AipsIO&, const float*);
195 static void put(AipsIO&, const double*);
196 static void put(AipsIO&, const Complex*);
197 static void put(AipsIO&, const DComplex*);
198 static void put(AipsIO&, const String*);
199 static void put(AipsIO&, const void*);
200 //</group>
201
202 // Get the value from <src>AipsIO</src>.
203 // The <src>void*</src> function is not doing anything and is for
204 // TpOther types.
205 //<group>
206 static void get(AipsIO&, Bool*);
207 static void get(AipsIO&, Char*);
208 static void get(AipsIO&, uChar*);
209 static void get(AipsIO&, Short*);
210 static void get(AipsIO&, uShort*);
211 static void get(AipsIO&, Int*);
212 static void get(AipsIO&, uInt*);
213 static void get(AipsIO&, Int64*);
214 static void get(AipsIO&, float*);
215 static void get(AipsIO&, double*);
216 static void get(AipsIO&, Complex*);
217 static void get(AipsIO&, DComplex*);
218 static void get(AipsIO&, String*);
219 static void get(AipsIO&, void*);
220 //</group>
221
222 // Put the value into the <src>ostream</src>.
223 // The <src>void*</src> function is not doing anything and is for
224 // TpOther types.
225 //<group>
226 static void put(ostream&, const Bool*);
227 static void put(ostream&, const Char*);
228 static void put(ostream&, const uChar*);
229 static void put(ostream&, const Short*);
230 static void put(ostream&, const uShort*);
231 static void put(ostream&, const Int*);
232 static void put(ostream&, const uInt*);
233 static void put(ostream&, const Int64*);
234 static void put(ostream&, const float*);
235 static void put(ostream&, const double*);
236 static void put(ostream&, const Complex*);
237 static void put(ostream&, const DComplex*);
238 static void put(ostream&, const String*);
239 static void put(ostream&, const void*);
240 //</group>
241
242 // Check if a value is defined, i.e. if it mismatches the given
243 // undefined value. The <src>void*</src> function (for non-standard
244 // data types) always returns the value <src>1</src>, since such
245 // values cannot be undefined.
246 //<group>
247 static int isDefined(const Bool* value, const Bool* undef);
248 static int isDefined(const Char* value, const Char* undef);
249 static int isDefined(const uChar* value, const uChar* undef);
250 static int isDefined(const Short* value, const Short* undef);
251 static int isDefined(const uShort* value, const uShort* undef);
252 static int isDefined(const Int* value, const Int* undef);
253 static int isDefined(const uInt* value, const uInt* undef);
254 static int isDefined(const Int64* value, const Int64* undef);
255 static int isDefined(const float* value, const float* undef);
256 static int isDefined(const double* value, const double* undef);
257 static int isDefined(const Complex* value, const Complex* undef);
258 static int isDefined(const DComplex* value, const DComplex* undef);
259 static int isDefined(const String* value, const String* undef);
260 static int isDefined(const void* value, const void* undef);
261 //</group>
262
263 private:
264 static const Bool undefbool;
265 static const Char undefchar;
266 static const uChar undefuchar;
267 static const Short undefshort;
268 static const uShort undefushort;
269 static const Int undefint;
270 static const uInt undefuint;
271 static const Int64 undefint64;
272 static const float undeffloat;
273 static const double undefdouble;
274 static const Complex undefcomplex;
275 static const DComplex undefdcomplex;
276 static const String undefstring;
277
278 static const String& strbool() {
279 static String result("Bool ");
280 return result;
281 }
282 static const String& strchar() {
283 static String result("Char ");
284 return result;
285 }
286 static const String& struchar() {
287 static String result("uChar ");
288 return result;
289 }
290 static const String& strshort() {
291 static String result("Short ");
292 return result;
293 }
294 static const String& strushort() {
295 static String result("uShort ");
296 return result;
297 }
298 static const String& strint() {
299 static String result("Int ");
300 return result;
301 }
302 static const String& struint() {
303 static String result("uInt ");
304 return result;
305 }
306 static const String& strint64() {
307 static String result("Int64 ");
308 return result;
309 }
310 static const String& strfloat() {
311 static String result("float ");
312 return result;
313 }
314 static const String& strdouble() {
315 static String result("double ");
316 return result;
317 }
318 static const String& strcomplex() {
319 static String result("Complex ");
320 return result;
321 }
322 static const String& strdcomplex() {
323 static String result("DComplex");
324 return result;
325 }
326 static const String& strstring() {
327 static String result("String ");
328 return result;
329 }
330 static const String& strrecord() {
331 static String result("Record ");
332 return result;
333 }
334 static const String& strtable() {
335 static String result("Table ");
336 return result;
337 }
338 static const String& strother() {
339 static String result("Other ");
340 return result;
341 }
342 static const String& strunknown() {
343 static String result("unknown ");
344 return result;
345 }
346 //
347 // This class is not meant to be constructed.
348 //
350};
351
357inline Int ValType::undefInt() { return undefint; }
360inline float ValType::undefFloat() { return undeffloat; }
361inline double ValType::undefDouble() { return undefdouble; }
362inline Complex ValType::undefComplex() { return undefcomplex; }
363inline DComplex ValType::undefDComplex() { return undefdcomplex; }
365
366inline void ValType::getUndef(Bool* val) { *val = undefbool; }
367inline void ValType::getUndef(Char* val) { *val = undefchar; }
368inline void ValType::getUndef(uChar* val) { *val = undefuchar; }
369inline void ValType::getUndef(Short* val) { *val = undefshort; }
370inline void ValType::getUndef(uShort* val) { *val = undefushort; }
371inline void ValType::getUndef(Int* val) { *val = undefint; }
372inline void ValType::getUndef(uInt* val) { *val = undefuint; }
373inline void ValType::getUndef(Int64* val) { *val = undefint64; }
374inline void ValType::getUndef(float* val) { *val = undeffloat; }
375inline void ValType::getUndef(double* val) { *val = undefdouble; }
376inline void ValType::getUndef(Complex* val) { *val = undefcomplex; }
377inline void ValType::getUndef(DComplex* val) { *val = undefdcomplex; }
378inline void ValType::getUndef(String* val) { *val = undefstring; }
379inline void ValType::getUndef(void*) {}
380
381inline DataType ValType::getType(const Bool*) { return TpBool; }
382inline DataType ValType::getType(const Char*) { return TpChar; }
383inline DataType ValType::getType(const uChar*) { return TpUChar; }
384inline DataType ValType::getType(const Short*) { return TpShort; }
385inline DataType ValType::getType(const uShort*) { return TpUShort; }
386inline DataType ValType::getType(const Int*) { return TpInt; }
387inline DataType ValType::getType(const uInt*) { return TpUInt; }
388inline DataType ValType::getType(const Int64*) { return TpInt64; }
389inline DataType ValType::getType(const float*) { return TpFloat; }
390inline DataType ValType::getType(const double*) { return TpDouble; }
391inline DataType ValType::getType(const Complex*) { return TpComplex; }
392inline DataType ValType::getType(const DComplex*) { return TpDComplex; }
393inline DataType ValType::getType(const String*) { return TpString; }
394inline DataType ValType::getType(const TableRecord*) { return TpRecord; }
395inline DataType ValType::getType(const void*) { return TpOther; }
396
397inline const String& ValType::getTypeStr(const Bool*) { return strbool(); }
398inline const String& ValType::getTypeStr(const Char*) { return strchar(); }
399inline const String& ValType::getTypeStr(const uChar*) { return struchar(); }
400inline const String& ValType::getTypeStr(const Short*) { return strshort(); }
401inline const String& ValType::getTypeStr(const uShort*) { return strushort(); }
402inline const String& ValType::getTypeStr(const Int*) { return strint(); }
403inline const String& ValType::getTypeStr(const uInt*) { return struint(); }
404inline const String& ValType::getTypeStr(const Int64*) { return strint64(); }
405inline const String& ValType::getTypeStr(const float*) { return strfloat(); }
406inline const String& ValType::getTypeStr(const double*) { return strdouble(); }
407inline const String& ValType::getTypeStr(const Complex*) { return strcomplex(); }
408inline const String& ValType::getTypeStr(const DComplex*) { return strdcomplex(); }
409inline const String& ValType::getTypeStr(const String*) { return strstring(); }
410inline const String& ValType::getTypeStr(const TableRecord*) { return strrecord(); }
411inline const String& ValType::getTypeStr(const void*) { return strother(); }
412
413inline void ValType::put(AipsIO& ios, const Bool* value) { ios << *value; }
414inline void ValType::put(AipsIO& ios, const Char* value) { ios << *value; }
415inline void ValType::put(AipsIO& ios, const uChar* value) { ios << *value; }
416inline void ValType::put(AipsIO& ios, const Short* value) { ios << *value; }
417inline void ValType::put(AipsIO& ios, const uShort* value) { ios << *value; }
418inline void ValType::put(AipsIO& ios, const Int* value) { ios << *value; }
419inline void ValType::put(AipsIO& ios, const uInt* value) { ios << *value; }
420inline void ValType::put(AipsIO& ios, const Int64* value) { ios << *value; }
421inline void ValType::put(AipsIO& ios, const float* value) { ios << *value; }
422inline void ValType::put(AipsIO& ios, const double* value) { ios << *value; }
423inline void ValType::put(AipsIO& ios, const Complex* value) { ios << *value; }
424inline void ValType::put(AipsIO& ios, const DComplex* value) { ios << *value; }
425inline void ValType::put(AipsIO& ios, const String* value) { ios << *value; }
426inline void ValType::put(AipsIO&, const void*) {}
427
428inline void ValType::get(AipsIO& ios, Bool* value) { ios >> *value; }
429inline void ValType::get(AipsIO& ios, Char* value) { ios >> *value; }
430inline void ValType::get(AipsIO& ios, uChar* value) { ios >> *value; }
431inline void ValType::get(AipsIO& ios, Short* value) { ios >> *value; }
432inline void ValType::get(AipsIO& ios, uShort* value) { ios >> *value; }
433inline void ValType::get(AipsIO& ios, Int* value) { ios >> *value; }
434inline void ValType::get(AipsIO& ios, uInt* value) { ios >> *value; }
435inline void ValType::get(AipsIO& ios, Int64* value) { ios >> *value; }
436inline void ValType::get(AipsIO& ios, float* value) { ios >> *value; }
437inline void ValType::get(AipsIO& ios, double* value) { ios >> *value; }
438inline void ValType::get(AipsIO& ios, Complex* value) { ios >> *value; }
439inline void ValType::get(AipsIO& ios, DComplex* value) { ios >> *value; }
440inline void ValType::get(AipsIO& ios, String* value) { ios >> *value; }
441inline void ValType::get(AipsIO&, void*) {}
442
443inline void ValType::put(ostream& ios, const Bool* value) { ios << *value; }
444inline void ValType::put(ostream& ios, const Char* value) { ios << *value; }
445inline void ValType::put(ostream& ios, const uChar* value) { ios << *value; }
446inline void ValType::put(ostream& ios, const Short* value) { ios << *value; }
447inline void ValType::put(ostream& ios, const uShort* value) { ios << *value; }
448inline void ValType::put(ostream& ios, const Int* value) { ios << *value; }
449inline void ValType::put(ostream& ios, const uInt* value) { ios << *value; }
450inline void ValType::put(ostream& ios, const Int64* value) { ios << *value; }
451inline void ValType::put(ostream& ios, const float* value) { ios << *value; }
452inline void ValType::put(ostream& ios, const double* value) { ios << *value; }
453inline void ValType::put(ostream& ios, const Complex* value) { ios << *value; }
454inline void ValType::put(ostream& ios, const DComplex* value) { ios << *value; }
455inline void ValType::put(ostream& ios, const String* value) { ios << *value; }
456inline void ValType::put(ostream&, const void*) {}
457
458inline int ValType::isDefined(const Bool* value, const Bool* undef) { return *value != *undef; }
459inline int ValType::isDefined(const Char* value, const Char* undef) { return *value != *undef; }
460inline int ValType::isDefined(const uChar* value, const uChar* undef) { return *value != *undef; }
461inline int ValType::isDefined(const Short* value, const Short* undef) { return *value != *undef; }
462inline int ValType::isDefined(const uShort* value, const uShort* undef) { return *value != *undef; }
463inline int ValType::isDefined(const Int* value, const Int* undef) { return *value != *undef; }
464inline int ValType::isDefined(const uInt* value, const uInt* undef) { return *value != *undef; }
465inline int ValType::isDefined(const Int64* value, const Int64* undef) { return *value != *undef; }
466inline int ValType::isDefined(const float* value, const float* undef) { return *value != *undef; }
467inline int ValType::isDefined(const double* value, const double* undef) { return *value != *undef; }
468inline int ValType::isDefined(const Complex* value, const Complex* undef) {
469 return *value != *undef;
470}
471inline int ValType::isDefined(const DComplex* value, const DComplex* undef) {
472 return *value != *undef;
473}
474inline int ValType::isDefined(const String* value, const String* undef) { return *value != *undef; }
475inline int ValType::isDefined(const void*, const void*) { return 1; }
476
477} // namespace casacore
478
479#endif
size_t ValueFunction(void *to, const void *from, size_t nvalues)
Define the signature of a function converting nvalues values from internal to external format or vice...
Definition Conversion.h:95
String: the storage and methods of handling collections of characters.
Definition String.h:355
static const String & strshort()
Definition ValType.h:290
static void getUndef(Bool *)
Get the "undefined value" for this data type in the argument.
Definition ValType.h:366
static ObjCompareFunc * getCmpFunc(DataType)
Get the pointer to the routine which compares two values.
ValType()
This class is not meant to be constructed.
static const String & strdcomplex()
Definition ValType.h:322
static const String & strint()
Definition ValType.h:298
static const String & strrecord()
Definition ValType.h:330
static float undefFloat()
Definition ValType.h:360
static std::shared_ptr< BaseCompare > getCmpObj(DataType)
Get the object which compares two values.
static Char undefChar()
Definition ValType.h:353
static int getCanonicalSize(DataType, Bool BECanonical=True)
Get the size of data type in canonical format.
static Short undefShort()
Definition ValType.h:355
static Bool undefBool()
Get the "undefined value" for this data type as the function's return value.
Definition ValType.h:352
static const String undefstring
Definition ValType.h:276
static Int undefInt()
Definition ValType.h:357
static const String & strother()
Definition ValType.h:338
static const Char undefchar
Definition ValType.h:265
static String undefString()
Definition ValType.h:364
static const String & strfloat()
Definition ValType.h:310
static const float undeffloat
Definition ValType.h:272
static int getTypeSize(DataType)
Get the size of data type (in local format).
static const Complex undefcomplex
Definition ValType.h:274
static const double undefdouble
Definition ValType.h:273
static const String & strushort()
Definition ValType.h:294
static const String & strchar()
Definition ValType.h:282
static const Short undefshort
Definition ValType.h:267
static Bool isPromotable(DataType from, DataType to)
Test if a data type can be promoted to another.
static const uInt undefuint
Definition ValType.h:270
static const String & strbool()
Definition ValType.h:278
static const String & strint64()
Definition ValType.h:306
static Complex undefComplex()
Definition ValType.h:362
static const uChar undefuchar
Definition ValType.h:266
static DComplex undefDComplex()
Definition ValType.h:363
static const Int64 undefint64
Definition ValType.h:271
static const String & strunknown()
Definition ValType.h:342
static void put(AipsIO &, const Bool *)
Put the value into AipsIO.
Definition ValType.h:413
static const String & strdouble()
Definition ValType.h:314
static const Int undefint
Definition ValType.h:269
static DataType getType(const Bool *)
Get the data type code for this type as the function's return value.
Definition ValType.h:381
static void getCanonicalFunc(DataType dt, Conversion::ValueFunction *&readFunc, Conversion::ValueFunction *&writeFunc, uInt &nrElementsPerValue, Bool BECanonical=True)
Get the functions to convert to/from canonical format.
static Int64 undefInt64()
Definition ValType.h:359
static const String & struchar()
Definition ValType.h:286
static uChar undefUChar()
Definition ValType.h:354
static const String & getTypeStr(DataType)
Get the name of the data type.
static double undefDouble()
Definition ValType.h:361
static const uShort undefushort
Definition ValType.h:268
static uShort undefUShort()
Definition ValType.h:356
static void get(AipsIO &, Bool *)
Get the value from AipsIO.
Definition ValType.h:428
static uInt undefUInt()
Definition ValType.h:358
static const String & strcomplex()
Definition ValType.h:318
static const Bool undefbool
Definition ValType.h:264
static const String & struint()
Definition ValType.h:302
static const DComplex undefdcomplex
Definition ValType.h:275
static const String & strtable()
Definition ValType.h:334
static int isDefined(const Bool *value, const Bool *undef)
Check if a value is defined, i.e.
Definition ValType.h:458
static const String & strstring()
Definition ValType.h:326
For temporary backward namespace compatibility, use casa as alias for casacore.
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
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
const T & get() const
char Char
Definition aipstype.h:44