casa
$Rev:20696$
|
00001 //# ValType.h: Data types and their undefined values 00002 //# Copyright (C) 1993,1994,1995,1996,1998,2001,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: ValType.h 20997 2010-11-17 07:05:29Z gervandiepen $ 00027 00028 #ifndef CASA_VALTYPE_H 00029 #define CASA_VALTYPE_H 00030 00031 00032 //# Includes 00033 #include <casa/Utilities/DataType.h> 00034 #include <casa/BasicSL/String.h> 00035 #include <casa/BasicSL/Complex.h> 00036 #include <casa/Utilities/Compare.h> 00037 #include <casa/Utilities/CountedPtr.h> 00038 #include <casa/OS/Conversion.h> 00039 #include <casa/IO/AipsIO.h> 00040 #include <casa/iosfwd.h> 00041 00042 namespace casa { //# NAMESPACE CASA - BEGIN 00043 00044 //# Forward Declarations 00045 class TableRecord; 00046 00047 00048 // <summary> 00049 // Data types and their undefined values. 00050 // </summary> 00051 00052 // <use visibility=export> 00053 00054 // <reviewed reviewer="Friso olnon" date="1995/03/20" tests="" demos=""> 00055 // </reviewed> 00056 00057 // <prerequisite> 00058 // <li> enum <linkto group="DataType.h#DataType">DataType</linkto> 00059 // </prerequisite> 00060 00061 // <synopsis> 00062 // Class <src>ValType</src> describes the data types and their 00063 // "undefined values". 00064 // 00065 // Supported are built-in data types, <src>Bool</src>, 00066 // <src>String</src>, <src>Complex</src> and <src>DComplex</src>. 00067 // As a rule, the smallest possible value of a data type is used as its 00068 // "undefined value"; for <src>String</src> we use the null string, and 00069 // for <src>Bool</src> the value <em>False</em>. 00070 // 00071 // The class does not contain data. It merely defines constants and 00072 // has overloaded functions that return in some form the "undefined 00073 // value", the data type, or certain other information about the data 00074 // type. 00075 // </synopsis> 00076 00077 00078 class ValType { 00079 public: 00080 00081 // Get the "undefined value" for this data type as the function's 00082 // return value. 00083 //<group> 00084 static Bool undefBool (); 00085 static Char undefChar (); 00086 static uChar undefUChar (); 00087 static Short undefShort (); 00088 static uShort undefUShort (); 00089 static Int undefInt (); 00090 static uInt undefUInt (); 00091 static Int64 undefInt64 (); 00092 static float undefFloat (); 00093 static double undefDouble (); 00094 static Complex undefComplex (); 00095 static DComplex undefDComplex (); 00096 static String undefString (); 00097 //</group> 00098 00099 // Get the "undefined value" for this data type in the argument. 00100 // The <src>void*</src> function is not doing anything and is for 00101 // TpOther types. 00102 //<group> 00103 static void getUndef (Bool*); 00104 static void getUndef (Char*); 00105 static void getUndef (uChar*); 00106 static void getUndef (Short*); 00107 static void getUndef (uShort*); 00108 static void getUndef (Int*); 00109 static void getUndef (uInt*); 00110 static void getUndef (Int64*); 00111 static void getUndef (float*); 00112 static void getUndef (double*); 00113 static void getUndef (Complex*); 00114 static void getUndef (DComplex*); 00115 static void getUndef (String*); 00116 static void getUndef (void*); 00117 //</group> 00118 00119 // Get the data type code for this type as the function's 00120 // return value. 00121 //<group> 00122 static DataType getType (const Bool*); 00123 static DataType getType (const Char*); 00124 static DataType getType (const uChar*); 00125 static DataType getType (const Short*); 00126 static DataType getType (const uShort*); 00127 static DataType getType (const Int*); 00128 static DataType getType (const uInt*); 00129 static DataType getType (const Int64*); 00130 static DataType getType (const float*); 00131 static DataType getType (const double*); 00132 static DataType getType (const Complex*); 00133 static DataType getType (const DComplex*); 00134 static DataType getType (const String*); 00135 static DataType getType (const TableRecord*); 00136 static DataType getType (const void*); 00137 //</group> 00138 00139 // Get the name of the data type. The <src>void*</src> returns 00140 // the string "Other ". 00141 //<group> 00142 static const String& getTypeStr (DataType); 00143 static const String& getTypeStr (const Bool*); 00144 static const String& getTypeStr (const Char*); 00145 static const String& getTypeStr (const uChar*); 00146 static const String& getTypeStr (const Short*); 00147 static const String& getTypeStr (const uShort*); 00148 static const String& getTypeStr (const Int*); 00149 static const String& getTypeStr (const uInt*); 00150 static const String& getTypeStr (const Int64*); 00151 static const String& getTypeStr (const float*); 00152 static const String& getTypeStr (const double*); 00153 static const String& getTypeStr (const Complex*); 00154 static const String& getTypeStr (const DComplex*); 00155 static const String& getTypeStr (const String*); 00156 static const String& getTypeStr (const TableRecord*); 00157 static const String& getTypeStr (const void*); 00158 //</group> 00159 00160 // Get the size of data type (in local format). 00161 static int getTypeSize (DataType); 00162 00163 // Get the size of data type in canonical format. 00164 // <br>The argument <src>BECanonical</src> determines if the big-endian 00165 // or little-endian canonical format is used. 00166 static int getCanonicalSize (DataType, Bool BECanonical = True); 00167 00168 // Get the functions to convert to/from canonical format. 00169 // These functions take the number of pixels as the length argument. 00170 // It returns the number of elements per value; normally this is 1, 00171 // but for complex values it is 2 (since they convert float/double). 00172 // <br>The argument <src>BECanonical</src> determines if the big-endian 00173 // or little-endian canonical format is used. 00174 static void getCanonicalFunc (DataType dt, 00175 Conversion::ValueFunction*& readFunc, 00176 Conversion::ValueFunction*& writeFunc, 00177 uInt& nrElementsPerValue, 00178 Bool BECanonical = True); 00179 00180 // Test if a data type can be promoted to another. 00181 static Bool isPromotable (DataType from, DataType to); 00182 00183 // Get the pointer to the routine which compares two values. 00184 static ObjCompareFunc* getCmpFunc (DataType); 00185 00186 // Get the object which compares two values. 00187 static CountedPtr<BaseCompare> getCmpObj (DataType); 00188 00189 // Put the value into <src>AipsIO</src>. 00190 // The <src>void*</src> function is not doing anything and is for 00191 // TpOther types. 00192 //<group> 00193 static void put (AipsIO&, const Bool*); 00194 static void put (AipsIO&, const Char*); 00195 static void put (AipsIO&, const uChar*); 00196 static void put (AipsIO&, const Short*); 00197 static void put (AipsIO&, const uShort*); 00198 static void put (AipsIO&, const Int*); 00199 static void put (AipsIO&, const uInt*); 00200 static void put (AipsIO&, const Int64*); 00201 static void put (AipsIO&, const float*); 00202 static void put (AipsIO&, const double*); 00203 static void put (AipsIO&, const Complex*); 00204 static void put (AipsIO&, const DComplex*); 00205 static void put (AipsIO&, const String*); 00206 static void put (AipsIO&, const void*); 00207 //</group> 00208 00209 // Get the value from <src>AipsIO</src>. 00210 // The <src>void*</src> function is not doing anything and is for 00211 // TpOther types. 00212 //<group> 00213 static void get (AipsIO&, Bool*); 00214 static void get (AipsIO&, Char*); 00215 static void get (AipsIO&, uChar*); 00216 static void get (AipsIO&, Short*); 00217 static void get (AipsIO&, uShort*); 00218 static void get (AipsIO&, Int*); 00219 static void get (AipsIO&, uInt*); 00220 static void get (AipsIO&, Int64*); 00221 static void get (AipsIO&, float*); 00222 static void get (AipsIO&, double*); 00223 static void get (AipsIO&, Complex*); 00224 static void get (AipsIO&, DComplex*); 00225 static void get (AipsIO&, String*); 00226 static void get (AipsIO&, void*); 00227 //</group> 00228 00229 // Put the value into the <src>ostream</src>. 00230 // The <src>void*</src> function is not doing anything and is for 00231 // TpOther types. 00232 //<group> 00233 static void put (ostream&, const Bool*); 00234 static void put (ostream&, const Char*); 00235 static void put (ostream&, const uChar*); 00236 static void put (ostream&, const Short*); 00237 static void put (ostream&, const uShort*); 00238 static void put (ostream&, const Int*); 00239 static void put (ostream&, const uInt*); 00240 static void put (ostream&, const Int64*); 00241 static void put (ostream&, const float*); 00242 static void put (ostream&, const double*); 00243 static void put (ostream&, const Complex*); 00244 static void put (ostream&, const DComplex*); 00245 static void put (ostream&, const String*); 00246 static void put (ostream&, const void*); 00247 //</group> 00248 00249 // Check if a value is defined, i.e. if it mismatches the given 00250 // undefined value. The <src>void*</src> function (for non-standard 00251 // data types) always returns the value <src>1</src>, since such 00252 // values cannot be undefined. 00253 //<group> 00254 static int isDefined (const Bool* value, const Bool* undef); 00255 static int isDefined (const Char* value, const Char* undef); 00256 static int isDefined (const uChar* value, const uChar* undef); 00257 static int isDefined (const Short* value, const Short* undef); 00258 static int isDefined (const uShort* value, const uShort* undef); 00259 static int isDefined (const Int* value, const Int* undef); 00260 static int isDefined (const uInt* value, const uInt* undef); 00261 static int isDefined (const Int64* value, const Int64* undef); 00262 static int isDefined (const float* value, const float* undef); 00263 static int isDefined (const double* value, const double* undef); 00264 static int isDefined (const Complex* value, const Complex* undef); 00265 static int isDefined (const DComplex* value, const DComplex* undef); 00266 static int isDefined (const String* value, const String* undef); 00267 static int isDefined (const void* value, const void* undef); 00268 //</group> 00269 00270 private: 00271 static const Bool undefbool ; 00272 static const Char undefchar ; 00273 static const uChar undefuchar ; 00274 static const Short undefshort ; 00275 static const uShort undefushort ; 00276 static const Int undefint ; 00277 static const uInt undefuint ; 00278 static const Int64 undefint64 ; 00279 static const float undeffloat ; 00280 static const double undefdouble ; 00281 static const Complex undefcomplex ; 00282 static const DComplex undefdcomplex; 00283 static const String undefstring ; 00284 00285 static const String strbool; 00286 static const String strchar; 00287 static const String struchar; 00288 static const String strshort; 00289 static const String strushort; 00290 static const String strint; 00291 static const String struint; 00292 static const String strint64; 00293 static const String strfloat; 00294 static const String strdouble; 00295 static const String strcomplex; 00296 static const String strdcomplex; 00297 static const String strstring; 00298 static const String strrecord; 00299 static const String strtable; 00300 static const String strother; 00301 static const String strunknown; 00302 // 00303 // This class is not meant to be constructed. 00304 // 00305 ValType (); 00306 }; 00307 00308 00309 00310 inline Bool ValType::undefBool () 00311 {return undefbool;} 00312 inline Char ValType::undefChar () 00313 {return undefchar;} 00314 inline uChar ValType::undefUChar () 00315 {return undefuchar;} 00316 inline Short ValType::undefShort () 00317 {return undefshort;} 00318 inline uShort ValType::undefUShort () 00319 {return undefushort;} 00320 inline Int ValType::undefInt () 00321 {return undefint;} 00322 inline uInt ValType::undefUInt () 00323 {return undefuint;} 00324 inline Int64 ValType::undefInt64 () 00325 {return undefint64;} 00326 inline float ValType::undefFloat () 00327 {return undeffloat;} 00328 inline double ValType::undefDouble () 00329 {return undefdouble;} 00330 inline Complex ValType::undefComplex () 00331 {return undefcomplex;} 00332 inline DComplex ValType::undefDComplex () 00333 {return undefdcomplex;} 00334 inline String ValType::undefString () 00335 {return undefstring;} 00336 00337 00338 inline void ValType::getUndef (Bool* val) 00339 {*val = undefbool;} 00340 inline void ValType::getUndef (Char* val) 00341 {*val = undefchar;} 00342 inline void ValType::getUndef (uChar* val) 00343 {*val = undefuchar;} 00344 inline void ValType::getUndef (Short* val) 00345 {*val = undefshort;} 00346 inline void ValType::getUndef (uShort* val) 00347 {*val = undefushort;} 00348 inline void ValType::getUndef (Int* val) 00349 {*val = undefint;} 00350 inline void ValType::getUndef (uInt* val) 00351 {*val = undefuint;} 00352 inline void ValType::getUndef (Int64* val) 00353 {*val = undefint64;} 00354 inline void ValType::getUndef (float* val) 00355 {*val = undeffloat;} 00356 inline void ValType::getUndef (double* val) 00357 {*val = undefdouble;} 00358 inline void ValType::getUndef (Complex* val) 00359 {*val = undefcomplex;} 00360 inline void ValType::getUndef (DComplex* val) 00361 {*val = undefdcomplex;} 00362 inline void ValType::getUndef (String* val) 00363 {*val = undefstring;} 00364 inline void ValType::getUndef (void*) 00365 {} 00366 00367 inline DataType ValType::getType (const Bool*) 00368 {return TpBool;} 00369 inline DataType ValType::getType (const Char*) 00370 {return TpChar;} 00371 inline DataType ValType::getType (const uChar*) 00372 {return TpUChar;} 00373 inline DataType ValType::getType (const Short*) 00374 {return TpShort;} 00375 inline DataType ValType::getType (const uShort*) 00376 {return TpUShort;} 00377 inline DataType ValType::getType (const Int*) 00378 {return TpInt;} 00379 inline DataType ValType::getType (const uInt*) 00380 {return TpUInt;} 00381 inline DataType ValType::getType (const Int64*) 00382 {return TpInt64;} 00383 inline DataType ValType::getType (const float*) 00384 {return TpFloat;} 00385 inline DataType ValType::getType (const double*) 00386 {return TpDouble;} 00387 inline DataType ValType::getType (const Complex*) 00388 {return TpComplex;} 00389 inline DataType ValType::getType (const DComplex*) 00390 {return TpDComplex;} 00391 inline DataType ValType::getType (const String*) 00392 {return TpString;} 00393 inline DataType ValType::getType (const TableRecord*) 00394 {return TpRecord;} 00395 inline DataType ValType::getType (const void*) 00396 {return TpOther;} 00397 00398 inline const String& ValType::getTypeStr (const Bool*) 00399 {return strbool;} 00400 inline const String& ValType::getTypeStr (const Char*) 00401 {return strchar;} 00402 inline const String& ValType::getTypeStr (const uChar*) 00403 {return struchar;} 00404 inline const String& ValType::getTypeStr (const Short*) 00405 {return strshort;} 00406 inline const String& ValType::getTypeStr (const uShort*) 00407 {return strushort;} 00408 inline const String& ValType::getTypeStr (const Int*) 00409 {return strint;} 00410 inline const String& ValType::getTypeStr (const uInt*) 00411 {return struint;} 00412 inline const String& ValType::getTypeStr (const Int64*) 00413 {return strint64;} 00414 inline const String& ValType::getTypeStr (const float*) 00415 {return strfloat;} 00416 inline const String& ValType::getTypeStr (const double*) 00417 {return strdouble;} 00418 inline const String& ValType::getTypeStr (const Complex*) 00419 {return strcomplex;} 00420 inline const String& ValType::getTypeStr (const DComplex*) 00421 {return strdcomplex;} 00422 inline const String& ValType::getTypeStr (const String*) 00423 {return strstring;} 00424 inline const String& ValType::getTypeStr (const TableRecord*) 00425 {return strrecord;} 00426 inline const String& ValType::getTypeStr (const void*) 00427 {return strother;} 00428 00429 inline void ValType::put (AipsIO& ios, const Bool* value) 00430 {ios << *value;} 00431 inline void ValType::put (AipsIO& ios, const Char* value) 00432 {ios << *value;} 00433 inline void ValType::put (AipsIO& ios, const uChar* value) 00434 {ios << *value;} 00435 inline void ValType::put (AipsIO& ios, const Short* value) 00436 {ios << *value;} 00437 inline void ValType::put (AipsIO& ios, const uShort* value) 00438 {ios << *value;} 00439 inline void ValType::put (AipsIO& ios, const Int* value) 00440 {ios << *value;} 00441 inline void ValType::put (AipsIO& ios, const uInt* value) 00442 {ios << *value;} 00443 inline void ValType::put (AipsIO& ios, const Int64* value) 00444 {ios << *value;} 00445 inline void ValType::put (AipsIO& ios, const float* value) 00446 {ios << *value;} 00447 inline void ValType::put (AipsIO& ios, const double* value) 00448 {ios << *value;} 00449 inline void ValType::put (AipsIO& ios, const Complex* value) 00450 {ios << *value;} 00451 inline void ValType::put (AipsIO& ios, const DComplex* value) 00452 {ios << *value;} 00453 inline void ValType::put (AipsIO& ios, const String* value) 00454 {ios << *value;} 00455 inline void ValType::put (AipsIO&, const void*) 00456 {} 00457 00458 inline void ValType::get (AipsIO& ios, Bool* value) 00459 {ios >> *value;} 00460 inline void ValType::get (AipsIO& ios, Char* value) 00461 {ios >> *value;} 00462 inline void ValType::get (AipsIO& ios, uChar* value) 00463 {ios >> *value;} 00464 inline void ValType::get (AipsIO& ios, Short* value) 00465 {ios >> *value;} 00466 inline void ValType::get (AipsIO& ios, uShort* value) 00467 {ios >> *value;} 00468 inline void ValType::get (AipsIO& ios, Int* value) 00469 {ios >> *value;} 00470 inline void ValType::get (AipsIO& ios, uInt* value) 00471 {ios >> *value;} 00472 inline void ValType::get (AipsIO& ios, Int64* value) 00473 {ios >> *value;} 00474 inline void ValType::get (AipsIO& ios, float* value) 00475 {ios >> *value;} 00476 inline void ValType::get (AipsIO& ios, double* value) 00477 {ios >> *value;} 00478 inline void ValType::get (AipsIO& ios, Complex* value) 00479 {ios >> *value;} 00480 inline void ValType::get (AipsIO& ios, DComplex* value) 00481 {ios >> *value;} 00482 inline void ValType::get (AipsIO& ios, String* value) 00483 {ios >> *value;} 00484 inline void ValType::get (AipsIO&, void*) 00485 {} 00486 00487 inline void ValType::put (ostream& ios, const Bool* value) 00488 {ios << *value;} 00489 inline void ValType::put (ostream& ios, const Char* value) 00490 {ios << *value;} 00491 inline void ValType::put (ostream& ios, const uChar* value) 00492 {ios << *value;} 00493 inline void ValType::put (ostream& ios, const Short* value) 00494 {ios << *value;} 00495 inline void ValType::put (ostream& ios, const uShort* value) 00496 {ios << *value;} 00497 inline void ValType::put (ostream& ios, const Int* value) 00498 {ios << *value;} 00499 inline void ValType::put (ostream& ios, const uInt* value) 00500 {ios << *value;} 00501 inline void ValType::put (ostream& ios, const Int64* value) 00502 {ios << *value;} 00503 inline void ValType::put (ostream& ios, const float* value) 00504 {ios << *value;} 00505 inline void ValType::put (ostream& ios, const double* value) 00506 {ios << *value;} 00507 inline void ValType::put (ostream& ios, const Complex* value) 00508 {ios << *value;} 00509 inline void ValType::put (ostream& ios, const DComplex* value) 00510 {ios << *value;} 00511 inline void ValType::put (ostream& ios, const String* value) 00512 {ios << *value;} 00513 inline void ValType::put (ostream&, const void*) 00514 {} 00515 00516 00517 inline int ValType::isDefined (const Bool* value, const Bool* undef) 00518 {return *value != *undef;} 00519 inline int ValType::isDefined (const Char* value, const Char* undef) 00520 {return *value != *undef;} 00521 inline int ValType::isDefined (const uChar* value, const uChar* undef) 00522 {return *value != *undef;} 00523 inline int ValType::isDefined (const Short* value, const Short* undef) 00524 {return *value != *undef;} 00525 inline int ValType::isDefined (const uShort* value, const uShort* undef) 00526 {return *value != *undef;} 00527 inline int ValType::isDefined (const Int* value, const Int* undef) 00528 {return *value != *undef;} 00529 inline int ValType::isDefined (const uInt* value, const uInt* undef) 00530 {return *value != *undef;} 00531 inline int ValType::isDefined (const Int64* value, const Int64* undef) 00532 {return *value != *undef;} 00533 inline int ValType::isDefined (const float* value, const float* undef) 00534 {return *value != *undef;} 00535 inline int ValType::isDefined (const double* value, const double* undef) 00536 {return *value != *undef;} 00537 inline int ValType::isDefined (const Complex* value, const Complex* undef) 00538 {return *value != *undef;} 00539 inline int ValType::isDefined (const DComplex* value, const DComplex* undef) 00540 {return *value != *undef;} 00541 inline int ValType::isDefined (const String* value, const String* undef) 00542 {return *value != *undef;} 00543 inline int ValType::isDefined (const void*, const void*) 00544 {return 1;} 00545 00546 00547 00548 } //# NAMESPACE CASA - END 00549 00550 #endif 00551 00552 00553