ValueHolderRep.h

Go to the documentation of this file.
00001 //# ValueHolderRep.h: A holder object for the standard CASACORE data
00002 //# Copyright (C) 2005
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 //#
00027 //# $Id$
00028 
00029 
00030 #ifndef CASA_VALUEHOLDERREP_H
00031 #define CASA_VALUEHOLDERREP_H
00032 
00033 //# Includes
00034 #include <casacore/casa/aips.h>
00035 #include <casacore/casa/Utilities/DataType.h>
00036 #include <iosfwd>
00037 
00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00039 
00040 //# Forward Declarations
00041 class AipsIO;
00042 template<class T> class Array;
00043 class Record;
00044 class RecordFieldId;
00045 
00046 
00047 // <summary>
00048 // A holder for a value of any basic type.
00049 // </summary>
00050 
00051 // <use visibility=local>
00052 // <reviewed reviewer="" date="" tests="tValueHolder">
00053 // </reviewed>
00054 
00055 // <synopsis>
00056 // Class ValueHolderRep is the letter class for the envelope class ValueHolder.
00057 // See <linkto class=ValueHolder>that class</linkto> for more information.
00058 // </synopsis>
00059 
00060 // <motivation>
00061 // Copying ValueHolders should be as cheap as possible, so a counted
00062 // referenced letter class is used.
00063 // </motivation>
00064 
00065 class ValueHolderRep
00066 {
00067 public:
00068   // Create the object for the given value.
00069   // <group>
00070   explicit ValueHolderRep (Bool value);
00071   explicit ValueHolderRep (uChar value);
00072   explicit ValueHolderRep (Short value);
00073   explicit ValueHolderRep (uShort value);
00074   explicit ValueHolderRep (Int value);
00075   explicit ValueHolderRep (uInt value);
00076   explicit ValueHolderRep (Int64 value);
00077   explicit ValueHolderRep (Float value);
00078   explicit ValueHolderRep (Double value);
00079   explicit ValueHolderRep (const Complex& value);
00080   explicit ValueHolderRep (const DComplex& value);
00081   explicit ValueHolderRep (const Char* value);
00082   explicit ValueHolderRep (const String& value);
00083   explicit ValueHolderRep (const Array<Bool>& value);
00084   explicit ValueHolderRep (const Array<uChar>& value);
00085   explicit ValueHolderRep (const Array<Short>& value);
00086   explicit ValueHolderRep (const Array<uShort>& value);
00087   explicit ValueHolderRep (const Array<Int>& value);
00088   explicit ValueHolderRep (const Array<uInt>& value);
00089   explicit ValueHolderRep (const Array<Int64>& value);
00090   explicit ValueHolderRep (const Array<Float>& value);
00091   explicit ValueHolderRep (const Array<Double>& value);
00092   explicit ValueHolderRep (const Array<Complex>& value);
00093   explicit ValueHolderRep (const Array<DComplex>& value);
00094   explicit ValueHolderRep (const Array<String>& value);
00095   explicit ValueHolderRep (const Record& value);
00096   // </group>
00097 
00098   // Create an empty N-dim array.
00099   ValueHolderRep (uInt ndim, Bool dummy);
00100 
00101   // Destructor.
00102   ~ValueHolderRep();
00103 
00104   // Get the data type (as defined in DataType.h).
00105   DataType dataType() const;
00106     
00107   // Get the value.
00108   // If possible, it converts the data as needed.
00109   // <group>
00110   Bool                  asBool    () const;
00111   uChar                 asuChar   () const;
00112   Short                 asShort   () const;
00113   uShort                asuShort  () const;
00114   Int                   asInt     () const;
00115   uInt                  asuInt    () const;
00116   Int64                 asInt64   () const;
00117   Float                 asFloat   () const;
00118   Double                asDouble  () const;
00119   Complex               asComplex () const;
00120   DComplex              asDComplex() const;
00121   const String&         asString  () const;
00122   const Array<Bool>     asArrayBool    () const;
00123   const Array<uChar>    asArrayuChar   () const;
00124   const Array<Short>    asArrayShort   () const;
00125   const Array<uShort>   asArrayuShort  () const;
00126   const Array<Int>      asArrayInt     () const;
00127   const Array<uInt>     asArrayuInt    () const;
00128   const Array<Int64>    asArrayInt64   () const;
00129   const Array<Float>    asArrayFloat   () const;
00130   const Array<Double>   asArrayDouble  () const;
00131   const Array<Complex>  asArrayComplex () const; 
00132   const Array<DComplex> asArrayDComplex() const;
00133   const Array<String>   asArrayString  () const;
00134   const Record&         asRecord       () const;
00135   // </group>
00136 
00137   // Put the value as a field in a record.
00138   void toRecord (Record&, const RecordFieldId&) const;
00139 
00140   // Construct the object from the value in a record.
00141   static ValueHolderRep* fromRecord (const Record& rec, const RecordFieldId&);
00142 
00143   // Write the ValueHolderRep to an output stream.
00144   // Arrays are written as normal arrays using ArrayIO.h. 
00145   std::ostream& write (std::ostream& os) const;
00146 
00147   // Compare two ValueHolder objects.
00148   // They must have the same data type.
00149   bool operator< (const ValueHolderRep& right) const;
00150   /*
00151   bool operator== (const ValueHolderRep& right) const;
00152   bool near (const ValueHolderRep& right, tolerance=1e-5) const;
00153   bool nearAbs (const ValueHolderRep& right, double tolerance=1e-5) const;
00154   */
00155 
00156 private:
00157   // Forbid copy ctor and assignment.
00158   //# There is no fundamental reason to forbid them, but it saves
00159   //# implementation work as long as they are not needed.
00160   // <group>
00161   ValueHolderRep (const ValueHolderRep&);
00162   ValueHolderRep& operator= (const ValueHolderRep&);
00163   // </group>
00164 
00165 
00166   uInt     itsNdim;
00167   DataType itsType;
00168   union {
00169     Bool   itsBool;
00170     Int64  itsInt64;
00171     Float  itsFloat;
00172     Double itsDouble;
00173     void*  itsPtr;
00174   };
00175 };
00176 
00177 
00178 inline DataType ValueHolderRep::dataType() const
00179 {
00180   return itsType;
00181 }
00182 
00183 
00184 } //# NAMESPACE CASACORE - END
00185 
00186 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1