casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VirtScaCol.h
Go to the documentation of this file.
00001 //# VirtScaCol.h: Templated base class for virtual scalar column
00002 //# Copyright (C) 1994,1995,1996,1999
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: VirtScaCol.h 20925 2010-07-05 11:41:34Z gervandiepen $
00027 
00028 #ifndef TABLES_VIRTSCACOL_H
00029 #define TABLES_VIRTSCACOL_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/DataManager.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 template<class T> class Vector;
00039 
00040 
00041 // <summary>
00042 // Templated base class for virtual scalar column
00043 // </summary>
00044 
00045 // <use visibility=local>
00046 
00047 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //# Classes you should understand before using this one.
00052 //   <li> DataManagerColumn
00053 //   <li> VirtualColumnEngine
00054 // </prerequisite>
00055 
00056 // <etymology>
00057 // VirtualScalarColumn handles a virtual column containing a scalar.
00058 // </etymology>
00059 
00060 // <synopsis> 
00061 // VirtualScalarColumn is the abstract base class to handle a scalar column
00062 // for a virtual column engine.
00063 // It is derived from DataManagerColumn and reimplements some
00064 // virtual functions to make life easier for the derived classes.
00065 // It does the following:
00066 // <ul>
00067 //  <li>
00068 //   It implements the dataType function, so it is not needed to implement
00069 //   that in derived classes.
00070 //  <li>
00071 //   It has a default implementation of False for function isWritable.
00072 //   Thus by default virtual scalar columns are not writable, which will
00073 //   often be the case. Only if a virtual scalar column can be writable,
00074 //   it has to be implemented in the derived class.
00075 //  <li>
00076 //   Declare a get/put function with the template parameter as its argument.
00077 //   The virtual functions get/putBoolV, etc. (defined in DataManagerColumn)
00078 //   are by default implemented using this (templated) get/put function.
00079 //   This allows for the default implementation of get/putBlock and
00080 //   makes life easier for the implementor of a derived class.
00081 //   However, the disadvantage of this is an extra virtual function call.
00082 //   (E.g. for a Bool value the first one is getBoolV and the second
00083 //    one get(T&), where T is Bool). If efficiency is really necessary,
00084 //    getBoolV, etc. should also be implemented in the derived class.
00085 //  <li>
00086 //   In DataManagerColumn the functions get/putBlockV and get/putColumnV
00087 //   are defined, which have a void* data argument. This is necessary
00088 //   to handle arbitrary data types in the non-templated base class
00089 //   DataManagerColumn.
00090 //   In this templated VirtualScalarColumn class, virtual functions
00091 //   get/putBlock and get/putColumn have been defined. They cast
00092 //   the void* data argument to T&, so in a derived class no care has
00093 //   to be taken for that cast.
00094 //   Furthermore a default implementation of them has been made.
00095 //   <ul>
00096 //    <li> getBlock gets one value using function get.
00097 //    <li> putBlock puts one value at the time using function put.
00098 //    <li> getColumn uses function getBlock.
00099 //    <li> putColumn uses function putBlock.
00100 //   </ul>
00101 //   If efficiency is an issue, these functions should be implemented
00102 //   in the derived class.
00103 // </ul>
00104 // </synopsis> 
00105 
00106 // <motivation>
00107 // This class reimplements some virtual functions implemented by
00108 // DataManagerColumn and types the data argument. In that way they are
00109 // easier to implement in derived classes. Furthermore they allow
00110 // default implementations.
00111 // </motivation>
00112 
00113 // <templating arg=T>
00114 //  <li> default constructor
00115 //  <li> copy constructor
00116 //  <li> assignment operator
00117 //  <li> <src>static String dataTypeId();   // unique name of the class</src>
00118 // </templating>
00119 
00120 // <todo asof="$DATE:$">
00121 //# A List of bugs, limitations, extensions or planned refinements.
00122 // </todo>
00123 
00124 
00125 template<class T>
00126 class VirtualScalarColumn : public DataManagerColumn
00127 {
00128 public:
00129 
00130     // Create a column.
00131     VirtualScalarColumn()
00132         {;}
00133 
00134     // Frees up the storage.
00135     virtual ~VirtualScalarColumn();
00136 
00137     // Return the data type of the column.
00138     int dataType() const;
00139 
00140     // Return the data type Id of the column.
00141     String dataTypeId() const;
00142 
00143     // By default no data can be put in a virtual column.
00144     virtual Bool isWritable() const;
00145 
00146     // Get the scalar value in the given row.
00147     virtual void get (uInt rownr, T& data) = 0;
00148 
00149     // Put the scalar value into the given row.
00150     // The default implementation throws an exception.
00151     virtual void put (uInt rownr, const T& data);
00152 
00153 protected:
00154     // The class can handle a get/putScalarColumn.
00155     Bool canAccessScalarColumn (Bool& reask) const;
00156 
00157     // Get all scalar values in the column.
00158     // The argument dataPtr is in fact a Vector<T>*, but a void*
00159     // is needed to be generic.
00160     // The vector pointed to by dataPtr has to have the correct length
00161     // (which is guaranteed by the ScalarColumn getColumn function).
00162     virtual void getScalarColumn (Vector<T>& data);
00163 
00164     // Put all scalar values in the column.
00165     // The argument dataPtr is in fact a const Vector<T>*, but a const void*
00166     // is needed to be generic.
00167     // The vector pointed to by dataPtr has to have the correct length
00168     // (which is guaranteed by the ScalarColumn putColumn function).
00169     virtual void putScalarColumn (const Vector<T>& data);
00170 
00171     // Get scalars from the given row on with a maximum of nrmax values.
00172     // It returns the actual number of values got.
00173     // This can be used to get an entire column of scalars or to get
00174     // a part of a column (for a cache for example).
00175     // The argument dataPtr is in fact a T*, but a void*
00176     // is needed to be generic. It must have length nrmax.
00177     virtual uInt getBlock (uInt rownr, uInt nrmax, T* dataPtr);
00178 
00179     // Put nrmax scalars from the given row on.
00180     // It returns the actual number of values put.
00181     // This can be used to put an entire column of scalars or to put
00182     // a part of a column (for a cache for example).
00183     // The argument dataPtr is in fact a const T*, but a const void*
00184     // is needed to be generic. It must have length nrmax.
00185     virtual void putBlock (uInt rownr, uInt nrmax, const T* dataPtr);
00186 
00187 
00188 private:
00189     // Implement the virtual functions defined in DataManagerColumn.
00190     // Get the scalar value in the given row.
00191     // <group>
00192     void getBoolV     (uInt rownr, Bool* dataPtr);
00193     void getuCharV    (uInt rownr, uChar* dataPtr);
00194     void getShortV    (uInt rownr, Short* dataPtr);
00195     void getuShortV   (uInt rownr, uShort* dataPtr);
00196     void getIntV      (uInt rownr, Int* dataPtr);
00197     void getuIntV     (uInt rownr, uInt* dataPtr);
00198     void getfloatV    (uInt rownr, float* dataPtr);
00199     void getdoubleV   (uInt rownr, double* dataPtr);
00200     void getComplexV  (uInt rownr, Complex* dataPtr);
00201     void getDComplexV (uInt rownr, DComplex* dataPtr);
00202     void getStringV   (uInt rownr, String* dataPtr);
00203     // This function is the get for all non-standard data types.
00204     void getOtherV    (uInt rownr, void* dataPtr);
00205     // </group>
00206 
00207     // Implement the virtual functions defined in DataManagerColumn.
00208     // Put the scalar value into the given row.
00209     // <group>
00210     void putBoolV     (uInt rownr, const Bool* dataPtr);
00211     void putuCharV    (uInt rownr, const uChar* dataPtr);
00212     void putShortV    (uInt rownr, const Short* dataPtr);
00213     void putuShortV   (uInt rownr, const uShort* dataPtr);
00214     void putIntV      (uInt rownr, const Int* dataPtr);
00215     void putuIntV     (uInt rownr, const uInt* dataPtr);
00216     void putfloatV    (uInt rownr, const float* dataPtr);
00217     void putdoubleV   (uInt rownr, const double* dataPtr);
00218     void putComplexV  (uInt rownr, const Complex* dataPtr);
00219     void putDComplexV (uInt rownr, const DComplex* dataPtr);
00220     void putStringV   (uInt rownr, const String* dataPtr);
00221     // This function is the put for all non-standard data types.
00222     void putOtherV    (uInt rownr, const void* dataPtr);
00223     // </group>
00224 
00225     // Implement the virtual functions defined in DataManagerColumn.
00226     // Get all scalar values in the column.
00227     void getScalarColumnV (void* dataPtr);
00228 
00229     // Implement the virtual functions defined in DataManagerColumn.
00230     // Put all scalar values in the column.
00231     void putScalarColumnV (const void* dataPtr);
00232 
00233     // Implement the virtual functions defined in DataManagerColumn.
00234     // Get scalars from the given row on with a maximum of nrmax values.
00235     uInt getBlockV (uInt rownr, uInt nrmax, void* dataPtr);
00236 
00237     // Implement the virtual functions defined in DataManagerColumn.
00238     // Put nrmax scalars from the given row on.
00239     void putBlockV (uInt rownr, uInt nrmax, const void* dataPtr);
00240 
00241 private:
00242     // The object cannot be copied.
00243     VirtualScalarColumn (const VirtualScalarColumn<T>&);
00244 
00245     // The object cannot be assigned to.
00246     VirtualScalarColumn<T>& operator= (const VirtualScalarColumn<T>&);
00247 };
00248 
00249 
00250 
00251 // <summary>
00252 // Global functions to get or put data of a virtual column
00253 // </summary>
00254 // <synopsis>
00255 // </synopsis>
00256 // <group name=getVirtualScalarColumn>
00257 template<class T>
00258 inline void getVirtualScalarColumn (VirtualScalarColumn<T>* col,
00259                                     uInt rownr, T* dataPtr)
00260     { col->get (rownr, *dataPtr); }
00261 inline void getVirtualScalarColumn (DataManagerColumn* col,
00262                                     uInt, void*)
00263     { col->throwGet(); }
00264 
00265 template<class T>
00266 inline void putVirtualScalarColumn (VirtualScalarColumn<T>* col,
00267                                     uInt rownr, const T* dataPtr)
00268     { col->put (rownr, *dataPtr); }
00269 inline void putVirtualScalarColumn (DataManagerColumn* col,
00270                                     uInt, const void*)
00271     { col->throwPut(); }
00272 // </group>
00273 
00274 
00275 
00276 } //# NAMESPACE CASA - END
00277 
00278 #ifndef CASACORE_NO_AUTO_TEMPLATES
00279 #include <tables/Tables/VirtScaCol.tcc>
00280 #endif //# CASACORE_NO_AUTO_TEMPLATES
00281 #endif