casacore
Loading...
Searching...
No Matches
DataType.h
Go to the documentation of this file.
1//# DataType.h: data types (primarily) in the table system
2//# Copyright (C) 1993,1994,1995,1996,1999,2000,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_DATATYPE_H
29#define CASA_DATATYPE_H
30
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/ArrayFwd.h>
33#include <casacore/casa/BasicSL/Complex.h>
34#include <casacore/casa/BasicSL/String.h>
35
36#include <casacore/casa/iosfwd.h>
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39class Table;
40template<class T> class Quantum;
41class String;
42class Record;
43
44// <summary> Data types (primarily) in the table system </summary>
45// <use visibility=export>
46// <reviewed reviewer="Paul Shannon" date="1995/05/01" tests="tDataType" demos="">
47// </reviewed>
48
49// <synopsis>
50// DataType enumerates possible data types. While this enum is primarily
51// used in the <linkto module="Tables:description">table</linkto> system, some
52// use of it is made elsewhere. Besides the enum
53// itself, <src>operator<<</src> is defined for DataType; it prints a DataType
54// in the form <src>DataType=Bool</src>.
55//
56// Also, global functions are written which take a "const pointer to type" and
57// return its DataType (TpOther if unknown). These functions can occasionally
58// allow one to avoid a switch on type, and can be useful in constructing
59// templated classes which are only valid for certain types.
60//
61// Global functions are also provided which allow one to convert an
62// array type to the equivalent scalar type and vice versa.
63//
64// <note role=warning>
65// New data types should be added just before TpNumberOfTypes, and after all
66// the existing enumerations, to avoid changing the number of an existing type
67// which would cause misinterpretation of data types stored in existing files.
68// Note also that if any new scalar and array types are added that this
69// will break the exising isScalar, isArray, asScalar and asArray functions.
70// </note>
71//
72// <note role=tip>
73// Data types <src>long</src> and <src>unsigned long</src> are not
74// possible. The types <src>Int</src> and <src>uInt</src> are always
75// 4 bytes, so <src>long</src> is not needed and may only cause
76// confusion.
77// </note>
78//
79// </synopsis>
80
81// <example>
82// The simplest uses of the DataType enumeration and functions are fairly
83// obvious, for example:
84// <srcblock>
85// Double d;
86// DataType type = whatType(&d);
87// cout << type << endl;
88// switch(type) {
89// case TpChar: ...
90// ...
91// case TpDouble: ...
92// }
93// </srcblock>
94//
95// A less obvious use is for "attaching" a templated object or function to a
96// non-templated object in a safe way. For example:
97// <srcblock>
98// class IntFloatContainer {
99// public:
100// Int intval;
101// Float floatval;
102// void *ptr(DataType type) {
103// if (type == whatType(&intval))
104// return &intval;
105// else if (type == whatType(&floatval))
106// return &floatval;
107// else
108// return 0; // Illegal type
109// }
110// };
111//
112// template<class T> class ValueAccessor {
113// public:
114// ValueAccessor(IntFloatContainer *container) : container_p(container) {
115// if (container_p->ptr(whatType(static_cast<T *>(0))) == 0)
116// throw(AipsError("Illegal type..."));
117// }
118// T &value() { return *((T*)container_p->ptr(whatType(static_cast<T *>(0)))); }
119// private:
120// IntFloatContainer *container_p;
121// };
122// </srcblock>
123//
124// So, this example provides a typesafe interface to values of only a small
125// number of types (and it fairly gracefully allows additional types to be
126// added; in particular the accessor class needs no modification). Techniques
127// such as this are appropriate for situations where one needs to deal with
128// many (but finite) numbers of types. For example, with FITS.
129// </example>
130
131// <todo asof="1995/03/01">
132// <li> Clean up comment as soon as enum's are properly extracted.
133// </todo>
134
135// <linkfrom anchor=DataType modules="Tables">
136// Enumeration of the <here>data types</here> in the table system
137// </linkfrom>
138//
139// Enumeration of the possible data types for keywords and table columns.
140// <group name=DataType>
141enum DataType {TpBool, TpChar, TpUChar,
142 TpShort, TpUShort, TpInt, TpUInt,
143 TpFloat, TpDouble,
144 TpComplex, TpDComplex, TpString,
145 TpTable,
146 TpArrayBool, TpArrayChar, TpArrayUChar,
147 TpArrayShort, TpArrayUShort, TpArrayInt, TpArrayUInt,
148 TpArrayFloat, TpArrayDouble,
149 TpArrayComplex, TpArrayDComplex, TpArrayString,
150 TpRecord, TpOther,
151//#// TpLDouble,
152//#// TpArrayLDouble,
153 TpQuantity, TpArrayQuantity,
154 TpInt64, TpArrayInt64,
155 // Since we start at zero, this is the number of types in the
156 // enum.
157 TpNumberOfTypes
158 };
159
160
161// Write a formated representation (e.g., Type=Bool) of the given data type.
162ostream &operator<<(ostream &os, DataType type);
163
164// These (overloaded) functions return DataType that corresponds to to the
165// type that is being pointed at. A pointer is used to avoid to avoid having
166// to create the object if it is of Array or Table types. At least for CFront,
167// it also avoids those types from being instantiated (they are forward
168// declared). The void* function matches any type (if none other will), and
169// returns TpOther.
170// <group>
171inline DataType whatType(const void *) { return TpOther; }
172inline DataType whatType(const Bool *) { return TpBool; }
173inline DataType whatType(const Char *) { return TpChar; }
174inline DataType whatType(const uChar *) { return TpUChar; }
175inline DataType whatType(const Short*) {return TpShort ; }
176inline DataType whatType(const uShort*) {return TpUShort ; }
177inline DataType whatType(const Int*) {return TpInt ; }
178inline DataType whatType(const uInt*) {return TpUInt ; }
179inline DataType whatType(const Int64*) {return TpInt64 ; }
180inline DataType whatType(const float*) {return TpFloat ; }
181inline DataType whatType(const double*) {return TpDouble ; }
182inline DataType whatType(const Complex*) {return TpComplex ; }
183inline DataType whatType(const DComplex*) {return TpDComplex ; }
184inline DataType whatType(const String*) {return TpString ; }
185inline DataType whatType(const Table*) {return TpTable ; }
186inline DataType whatType(const Array<Bool> *) { return TpArrayBool; }
187inline DataType whatType(const Array<Char> *) { return TpArrayChar; }
188inline DataType whatType(const Array<uChar> *) { return TpArrayUChar; }
189inline DataType whatType(const Array<Short>*) {return TpArrayShort ; }
190inline DataType whatType(const Array<uShort> *) {return TpArrayUShort ; }
191inline DataType whatType(const Array<Int> *) {return TpArrayInt ; }
192inline DataType whatType(const Array<uInt> *) {return TpArrayUInt ; }
193inline DataType whatType(const Array<Int64> *) {return TpArrayInt64 ; }
194inline DataType whatType(const Array<float> *) {return TpArrayFloat ; }
195inline DataType whatType(const Array<double> *) {return TpArrayDouble ; }
196inline DataType whatType(const Array<Complex> *) {return TpArrayComplex ; }
197inline DataType whatType(const Array<DComplex> *) {return TpArrayDComplex ; }
198inline DataType whatType(const Array<String> *) {return TpArrayString ; }
199inline DataType whatType(const Record *) {return TpRecord ; }
200inline DataType whatType(const Quantum<Double> *) {return TpQuantity ; }
202 {return TpArrayQuantity ; }
203// </group>
204
205// It is sometimes useful to discover what the corresponding
206// scalar (or array) type is for a given array (or scalar) type.
207// Calling these with TpOther, TpTable, and TpRecord results
208// in an exception being thrown.
209// <group>
212// </group>
213
214// It is occasionally useful to discover whether or not a DataType represents
215// an array or scalar value. Note that TpTable, TpRecord, and TpOther are neither
216// scalar nor array types.
217// <group>
220Bool isScalarFun(DataType type); //{return isScalar(type);}
221// </group>
222
223// It is sometimes useful to discover if a DataType represents a real
224// numeric value (i.e., can it be cast to a Double?) This returns True
225// for both real scalar and array type.
227
228// Returns True for Complex or DComplex scalar or array types
230
231// Returns True if the type is either Real or Complex/DComplex
233
234// </group>
235
236
237} //# NAMESPACE CASACORE - END
238
239#endif
String: the storage and methods of handling collections of characters.
Definition String.h:225
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:47
short Short
Definition aipstype.h:48
unsigned int uInt
Definition aipstype.h:51
unsigned short uShort
Definition aipstype.h:49
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
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:42
char Char
Definition aipstype.h:46
Bool isScalar(DataType type)
It is occasionally useful to discover whether or not a DataType represents an array or scalar value.
ostream & operator<<(ostream &os, DataType type)
Write a formated representation (e.g., Type=Bool) of the given data type.
DataType whatType(const Array< Short > *)
Definition DataType.h:189
DataType whatType(const Array< Complex > *)
Definition DataType.h:196
Bool isComplex(DataType type)
Returns True for Complex or DComplex scalar or array types.
Bool isReal(DataType type)
It is sometimes useful to discover if a DataType represents a real numeric value (i....
DataType whatType(const Array< Int > *)
Definition DataType.h:191
DataType asScalar(DataType type)
It is sometimes useful to discover what the corresponding scalar (or array) type is for a given array...
DataType whatType(const Array< String > *)
Definition DataType.h:198
DataType whatType(const Array< DComplex > *)
Definition DataType.h:197
DataType whatType(const Array< Quantum< Double > > *)
Definition DataType.h:201
DataType whatType(const Array< float > *)
Definition DataType.h:194
Bool isNumeric(DataType type)
Returns True if the type is either Real or Complex/DComplex.
DataType whatType(const void *)
These (overloaded) functions return DataType that corresponds to to the type that is being pointed at...
Definition DataType.h:171
DataType whatType(const DComplex *)
Definition DataType.h:183
DataType whatType(const Array< Int64 > *)
Definition DataType.h:193
DataType whatType(const Array< uInt > *)
Definition DataType.h:192
@ TpNumberOfTypes
Since we start at zero, this is the number of types in the enum.
Definition DataType.h:157
DataType whatType(const Array< uChar > *)
Definition DataType.h:188
DataType whatType(const Array< uShort > *)
Definition DataType.h:190
DataType whatType(const Array< double > *)
Definition DataType.h:195
DataType whatType(const Array< Char > *)
Definition DataType.h:187
DataType whatType(const Quantum< Double > *)
Definition DataType.h:200
DataType whatType(const Array< Bool > *)
Definition DataType.h:186