casacore
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/BasicSL/Complex.h>
33 #include <casacore/casa/BasicSL/String.h>
34 
35 #include <casacore/casa/iosfwd.h>
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 class Table;
39 template<class T> class Array;
40 template<class T> class Quantum;
41 class String;
42 class 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>
141 enum 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.
162 ostream &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>
171 inline DataType whatType(const void *) { return TpOther; }
172 inline DataType whatType(const Bool *) { return TpBool; }
173 inline DataType whatType(const Char *) { return TpChar; }
174 inline DataType whatType(const uChar *) { return TpUChar; }
175 inline DataType whatType(const Short*) {return TpShort ; }
176 inline DataType whatType(const uShort*) {return TpUShort ; }
177 inline DataType whatType(const Int*) {return TpInt ; }
178 inline DataType whatType(const uInt*) {return TpUInt ; }
179 inline DataType whatType(const Int64*) {return TpInt64 ; }
180 inline DataType whatType(const float*) {return TpFloat ; }
181 inline DataType whatType(const double*) {return TpDouble ; }
182 inline DataType whatType(const Complex*) {return TpComplex ; }
183 inline DataType whatType(const DComplex*) {return TpDComplex ; }
184 inline DataType whatType(const String*) {return TpString ; }
185 inline DataType whatType(const Table*) {return TpTable ; }
186 inline DataType whatType(const Array<Bool> *) { return TpArrayBool; }
187 inline DataType whatType(const Array<Char> *) { return TpArrayChar; }
188 inline DataType whatType(const Array<uChar> *) { return TpArrayUChar; }
189 inline DataType whatType(const Array<Short>*) {return TpArrayShort ; }
190 inline DataType whatType(const Array<uShort> *) {return TpArrayUShort ; }
191 inline DataType whatType(const Array<Int> *) {return TpArrayInt ; }
192 inline DataType whatType(const Array<uInt> *) {return TpArrayUInt ; }
193 inline DataType whatType(const Array<Int64> *) {return TpArrayInt64 ; }
194 inline DataType whatType(const Array<float> *) {return TpArrayFloat ; }
195 inline DataType whatType(const Array<double> *) {return TpArrayDouble ; }
196 inline DataType whatType(const Array<Complex> *) {return TpArrayComplex ; }
197 inline DataType whatType(const Array<DComplex> *) {return TpArrayDComplex ; }
198 inline DataType whatType(const Array<String> *) {return TpArrayString ; }
199 inline DataType whatType(const Record *) {return TpRecord ; }
200 inline 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>
210 DataType asScalar(DataType type);
211 DataType asArray(DataType type);
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>
218 Bool isScalar(DataType type);
219 Bool isArray(DataType type);
220 Bool 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.
226 Bool isReal(DataType type);
227 
228 // Returns True for Complex or DComplex scalar or array types
229 Bool isComplex(DataType type);
230 
231 // Returns True if the type is either Real or Complex/DComplex
232 Bool isNumeric(DataType type);
233 
234 // </group>
235 
236 
237 } //# NAMESPACE CASACORE - END
238 
239 #endif
casacore::DataType_global_functions_DataType::isArray
Bool isArray(DataType type)
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Int64 > *)
Definition: DataType.h:193
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Bool > *)
Definition: DataType.h:186
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< double > *)
Definition: DataType.h:195
casacore::DataType_global_functions_DataType::asScalar
DataType asScalar(DataType type)
It is sometimes useful to discover what the corresponding scalar (or array) type is for a given array...
casacore::DataType_global_functions_DataType::TpDouble
@ TpDouble
Definition: DataType.h:144
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Int64 *)
Definition: DataType.h:179
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Short *)
Definition: DataType.h:175
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const uShort *)
Definition: DataType.h:176
casacore::DataType_global_functions_DataType::TpArrayQuantity
@ TpArrayQuantity
Definition: DataType.h:153
casacore::DataType_global_functions_DataType::TpQuantity
@ TpQuantity
Definition: DataType.h:153
casacore::DataType_global_functions_DataType::isScalar
Bool isScalar(DataType type)
It is occasionally useful to discover whether or not a DataType represents an array or scalar value.
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const void *)
These (overloaded) functions return DataType that corresponds to to the type that is being pointed at...
Definition: DataType.h:171
casacore::DataType_global_functions_DataType::TpArrayShort
@ TpArrayShort
Definition: DataType.h:148
Complexfwd_global_functions_Complexfwd::casacore::DComplex
std::complex< Double > DComplex
Definition: Complexfwd.h:50
casacore::DataType_global_functions_DataType::TpComplex
@ TpComplex
Definition: DataType.h:145
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Quantum< Double > *)
Definition: DataType.h:200
casacore::uChar
unsigned char uChar
Definition: aipstype.h:47
casacore::DataType_global_functions_DataType::DataType
DataType
Definition: DataType.h:142
casacore::DataType_global_functions_DataType::TpArrayDouble
@ TpArrayDouble
Definition: DataType.h:149
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Char > *)
Definition: DataType.h:187
casacore::DataType_global_functions_DataType::TpBool
@ TpBool
Definition: DataType.h:142
casacore::DataType_global_functions_DataType::TpOther
@ TpOther
Definition: DataType.h:151
casacore::DataType_global_functions_DataType::TpInt
@ TpInt
Definition: DataType.h:143
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Quantum< Double > > *)
Definition: DataType.h:201
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< uShort > *)
Definition: DataType.h:190
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< float > *)
Definition: DataType.h:194
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const float *)
Definition: DataType.h:180
casacore::DataType_global_functions_DataType::TpArrayInt
@ TpArrayInt
Definition: DataType.h:148
casacore::DataType_global_functions_DataType::TpArrayUChar
@ TpArrayUChar
Definition: DataType.h:147
casacore::DataType_global_functions_DataType::TpArrayComplex
@ TpArrayComplex
Definition: DataType.h:150
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Table *)
Definition: DataType.h:185
casacore::DataType_global_functions_DataType::TpTable
@ TpTable
Definition: DataType.h:146
casacore::DataType_global_functions_DataType::isComplex
Bool isComplex(DataType type)
Returns True for Complex or DComplex scalar or array types.
casacore::DataType_global_functions_DataType::TpRecord
@ TpRecord
Definition: DataType.h:151
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const double *)
Definition: DataType.h:181
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Int > *)
Definition: DataType.h:191
casacore::DataType_global_functions_DataType::TpChar
@ TpChar
Definition: DataType.h:142
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< String > *)
Definition: DataType.h:198
casacore::Table
Main interface class to a read/write table.
Definition: Table.h:153
casacore::DataType_global_functions_DataType::TpUChar
@ TpUChar
Definition: DataType.h:142
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const uChar *)
Definition: DataType.h:174
casacore::DataType_global_functions_DataType::isNumeric
Bool isNumeric(DataType type)
Returns True if the type is either Real or Complex/DComplex.
casacore::uShort
unsigned short uShort
Definition: aipstype.h:49
casacore::DataType_global_functions_DataType::TpShort
@ TpShort
Definition: DataType.h:143
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::DataType_global_functions_DataType::TpUShort
@ TpUShort
Definition: DataType.h:143
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Bool *)
Definition: DataType.h:172
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Char *)
Definition: DataType.h:173
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Complex *)
Definition: DataType.h:182
casacore::DataType_global_functions_DataType
Data types (primarily) in the table system.
Definition: DataType.h:141
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const DComplex *)
Definition: DataType.h:183
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::DataType_global_functions_DataType::TpArrayFloat
@ TpArrayFloat
Definition: DataType.h:149
casacore::DataType_global_functions_DataType::operator<<
ostream & operator<<(ostream &os, DataType type)
Write a formated representation (e.g., Type=Bool) of the given data type.
casacore::DataType_global_functions_DataType::TpArrayInt64
@ TpArrayInt64
Definition: DataType.h:154
casacore::DataType_global_functions_DataType::isReal
Bool isReal(DataType type)
It is sometimes useful to discover if a DataType represents a real numeric value (i....
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Record *)
Definition: DataType.h:199
casacore::DataType_global_functions_DataType::TpString
@ TpString
Definition: DataType.h:145
casacore::DataType_global_functions_DataType::TpArrayBool
@ TpArrayBool
Definition: DataType.h:147
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Complex > *)
Definition: DataType.h:196
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
casacore::DataType_global_functions_DataType::TpArrayUInt
@ TpArrayUInt
Definition: DataType.h:148
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< Short > *)
Definition: DataType.h:189
casacore::DataType_global_functions_DataType::TpArrayDComplex
@ TpArrayDComplex
Definition: DataType.h:150
casacore::Array< Bool >
casacore::DataType_global_functions_DataType::TpDComplex
@ TpDComplex
Definition: DataType.h:145
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::DataType_global_functions_DataType::asArray
DataType asArray(DataType type)
casacore::DataType_global_functions_DataType::TpArrayChar
@ TpArrayChar
Definition: DataType.h:147
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< uInt > *)
Definition: DataType.h:192
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Complexfwd_global_functions_Complexfwd::casacore::Complex
std::complex< Float > Complex
Definition: Complexfwd.h:49
casacore::operator<<
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
casacore::DataType_global_functions_DataType::TpInt64
@ TpInt64
Definition: DataType.h:154
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const String *)
Definition: DataType.h:184
casacore::Record
A hierarchical collection of named fields of various types.
Definition: Record.h:180
casacore::Short
short Short
Definition: aipstype.h:48
casacore::DataType_global_functions_DataType::isScalarFun
Bool isScalarFun(DataType type)
casacore::DataType_global_functions_DataType::TpNumberOfTypes
@ TpNumberOfTypes
Since we start at zero, this is the number of types in the enum.
Definition: DataType.h:157
casacore::DataType_global_functions_DataType::TpFloat
@ TpFloat
Definition: DataType.h:144
casacore::DataType_global_functions_DataType::TpArrayString
@ TpArrayString
Definition: DataType.h:150
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Int *)
Definition: DataType.h:177
casacore::Char
char Char
Definition: aipstype.h:46
casacore::DataType_global_functions_DataType::TpUInt
@ TpUInt
Definition: DataType.h:143
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< uChar > *)
Definition: DataType.h:188
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const uInt *)
Definition: DataType.h:178
casacore::Quantum< Double >
casacore::DataType_global_functions_DataType::TpArrayUShort
@ TpArrayUShort
Definition: DataType.h:148
casacore::DataType_global_functions_DataType::whatType
DataType whatType(const Array< DComplex > *)
Definition: DataType.h:197