ValType.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1