casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VirtArrCol.h
Go to the documentation of this file.
00001 //# VirtArrCol.h: Templated base class for virtual array column
00002 //# Copyright (C) 1994,1995,1996,1999,2000
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: VirtArrCol.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_VIRTARRCOL_H
00029 #define TABLES_VIRTARRCOL_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 Array;
00039 class Slicer;
00040 
00041 
00042 // <summary>
00043 // Templated base class for virtual array column
00044 // </summary>
00045 
00046 // <use visibility=local>
00047 
00048 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //# Classes you should understand before using this one.
00053 //   <li> DataManagerColumn
00054 //   <li> VirtualColumnEngine
00055 // </prerequisite>
00056 
00057 // <etymology>
00058 // VirtualArrayColumn handles a virtual column containing an array.
00059 // </etymology>
00060 
00061 // <synopsis> 
00062 // VirtualArrayColumn is the abstract base class to handle an array column
00063 // for a virtual column engine (both direct and indirect arrays).
00064 // It is derived from DataManagerColumn and reimplements some
00065 // virtual functions to make life easier for the derived classes.
00066 // It does the following:
00067 // <ul>
00068 //  <li>
00069 //   It implements the dataType function, so it is not needed to implement
00070 //   that in derived classes.
00071 //  <li>
00072 //   It has a default implementation of False for function isWritable.
00073 //   Thus by default virtual scalar columns are not writable, which will
00074 //   often be the case. Only if a virtual scalar column can be writable,
00075 //   it has to be implemented in the derived class.
00076 //  <li>
00077 //   It has a default implementation for the functions dealing with
00078 //   the array shapes. By default they throw an "invalid operation"
00079 //   exception, so it is needed to implement them in the derived class.
00080 //  <li>
00081 //   In DataManagerColumn the functions get/putArrayV and get/putSliceV
00082 //   are defined, which have a void* data argument. This is necessary
00083 //   to handle arbitrary data types in the non-templated base class
00084 //   DataManagerColumn.
00085 //   In this templated VirtualArrayColumn class, virtual functions
00086 //   get/putArray, get/putSlice, etc. have been defined. They cast
00087 //   the void* data argument to Array<T>&, so in a derived class no care
00088 //   has to be taken for that cast.
00089 //   Furthermore a default implementation of the get/putSlice has been made.
00090 //   They get/put the entire array (using get/putArray) and access the
00091 //   required slice. For this purpose the function canAccessSlice has
00092 //   also been implemented.
00093 //   By default the get/putArray functions thrown an "invalid operation"
00094 //   exception, so they have to be implemented in the derived class.
00095 //  <li>
00096 //   Similarly the functions get/putArrayColumnV and get/putColumnSliceV
00097 //   have been templated to get/putArrayColumn and get/putColumnSlice.
00098 //   The default implementation of these latter functions handle a
00099 //   column by looping through its individual cells.
00100 //   For this purpose the functions canAccessArrayColumn and
00101 //   canAccessColumnSlice have also been implemented.
00102 //  <li>
00103 //   Similarly the functions get/putArrayColumnCellsV and
00104 //   get/putColumnSliceCells have been templated to
00105 //   get/putArrayColumnCells and get/putColumnSliceCells.
00106 //   However, their implementations throw an exception and the function
00107 //   canAccessArrayColumnCells has not implemented (so defaults to False).
00108 //   However, it makes it possible that a derived class
00109 //   (like <linkto class=ScaledComplexData>ScaledComplexData</linkto>)
00110 //   can implement these functions.
00111 // </ul>
00112 // An example of a virtual array column class is ScaledComplexData. Note that
00113 // this class is (indirectly) multiple derived from VirtualColumnEngine and
00114 // VirtualArrayColumn, so it combines the functionality of DataManager
00115 // and DataManagerColumn.
00116 // This is possible, because one ScaledComplexData engine can handle only one
00117 // column.
00118 // </synopsis> 
00119 
00120 // <motivation>
00121 // This class reimplements some virtual functions implemented by
00122 // DataManagerColumn and types the data argument. In that way they are
00123 // easier to implement in derived classes. Furthermore they allow
00124 // default implementations.
00125 // </motivation>
00126 
00127 // <templating arg=T>
00128 //  <li> default constructor
00129 //  <li> copy constructor
00130 //  <li> assignment operator
00131 //  <li> <src>static String dataTypeId();   // unique name of the class</src>
00132 // </templating>
00133 
00134 // <todo asof="$DATE:$">
00135 //# A List of bugs, limitations, extensions or planned refinements.
00136 // </todo>
00137 
00138 
00139 template<class T>
00140 class VirtualArrayColumn : public DataManagerColumn
00141 {
00142 public:
00143 
00144     // Create a column.
00145     VirtualArrayColumn()
00146         {;}
00147 
00148     // Frees up the storage.
00149     virtual ~VirtualArrayColumn();
00150 
00151     // Return the data type of the column.
00152     virtual int dataType() const;
00153 
00154     // Return the data type Id of the column.
00155     virtual String dataTypeId() const;
00156 
00157     // By default no data can be put in a virtual column.
00158     virtual Bool isWritable() const;
00159 
00160     // The class can handle a get/putSlice.
00161     virtual Bool canAccessSlice (Bool& reask) const;
00162 
00163     // The class can handle a get/putArrayColumn.
00164     virtual Bool canAccessArrayColumn (Bool& reask) const;
00165 
00166     // The class can handle a get/putColumnSlice.
00167     virtual Bool canAccessColumnSlice (Bool& reask) const;
00168 
00169 protected:
00170     // Set the shape of all arrays in the column.
00171     // It is only called if the column contains direct arrays.
00172     // By default it throws a "not possible" exception.
00173     virtual void setShapeColumn (const IPosition& shape);
00174 
00175     // Set the shape of an array in the given row.
00176     // It is only called if the column contains indirect arrays.
00177     // By default it throws a "not possible" exception.
00178     virtual void setShape (uInt rownr, const IPosition& shape);
00179 
00180     // Is the value shape defined in the given row?
00181     // By default it throws a "not possible" exception.
00182     virtual Bool isShapeDefined (uInt rownr);
00183 
00184     // Get the dimensionality of the item in the given row.
00185     // By default it throws a "not possible" exception.
00186     virtual uInt ndim (uInt rownr);
00187 
00188     // Get the shape of the item in the given row.
00189     // By default it throws a "not possible" exception.
00190     virtual IPosition shape (uInt rownr);
00191 
00192     // Get the array value in the given row.
00193     // The data array has to have the correct shape
00194     // (which is guaranteed by the ArrayColumn::get function).
00195     virtual void getArray (uInt rownr, Array<T>& data) = 0;
00196 
00197     // Put the array value into the given row.
00198     // The data array has to have the correct shape
00199     // (which is guaranteed by the ArrayColumn::put function).
00200     // By default it throws a "not possible" exception.
00201     virtual void putArray (uInt rownr, const Array<T>& data);
00202 
00203     // Get a section of the array in the given row.
00204     // The data array has to have the correct shape
00205     // (which is guaranteed by the ArrayColumn::getSlice function).
00206     // The default implementation gets the slice by getting the full
00207     // array first.
00208     virtual void getSlice (uInt rownr, const Slicer& slicer, Array<T>& data);
00209 
00210     // Put into a section of the array in the given row.
00211     // The data array has to have the correct shape
00212     // (which is guaranteed by the ArrayColumn::putSlice function).
00213     // The default implementation gets the slice by accessing the full
00214     // array.
00215     virtual void putSlice (uInt rownr, const Slicer& slicer,
00216                            const Array<T>& data);
00217 
00218     // Get an entire column.
00219     // The data array has to have the correct shape
00220     // (which is guaranteed by the ArrayColum::getColumn function).
00221     // The default implementation gets the column row by row.
00222     virtual void getArrayColumn (Array<T>& data);
00223 
00224     // Put an entire column.
00225     // The data array has to have the correct shape
00226     // (which is guaranteed by the ArrayColumn::putColumn function).
00227     // The default implementation puts the column row by row.
00228     virtual void putArrayColumn (const Array<T>& data);
00229 
00230     // Get some array values in the column.
00231     // The data array has to have the correct length
00232     // (which is guaranteed by the ArrayColumn::getColumn function).
00233     // By default it throws a "not possible" exception.
00234     virtual void getArrayColumnCells (const RefRows& rownrs, Array<T>& data);
00235 
00236     // Put some array values in the column.
00237     // The data array has to have the correct length
00238     // (which is guaranteed by the ArrayColumn::putColumn function).
00239     // By default it throws a "not possible" exception.
00240     virtual void putArrayColumnCells (const RefRows& rownrs,
00241                                       const Array<T>& data);
00242 
00243     // Get a section of all arrays in the column.
00244     // The data array has to have the correct shape
00245     // (which is guaranteed by the ArrayColumn::getColumn function).
00246     // The default implementation gets the column row by row.
00247     virtual void getColumnSlice (const Slicer& slicer, Array<T>& data);
00248 
00249     // Put a section of all arrays in the column.
00250     // The data array has to have the correct shape
00251     // (which is guaranteed by the ArrayColumn putColumn function).
00252     // The default implementation puts the column row by row.
00253     virtual void putColumnSlice (const Slicer& slicer, const Array<T>& data);
00254 
00255     // Get a section of some arrays in the column.
00256     // The data array has to have the correct shape
00257     // (which is guaranteed by the ArrayColumn::getColumn function).
00258     // By default it throws a "not possible" exception.
00259     virtual void getColumnSliceCells (const RefRows& rownrs,
00260                                       const Slicer& slicer, Array<T>& data);
00261 
00262     // Put into a section of some arrays in the column.
00263     // The data array has to have the correct shape
00264     // (which is guaranteed by the ArrayColumn::putColumn function).
00265     // By default it throws a "not possible" exception.
00266     virtual void putColumnSliceCells (const RefRows& rownrs,
00267                                       const Slicer& slicer,
00268                                       const Array<T>& data);
00269 
00270 private:
00271     // Implement the virtual functions defined in DataManagerColumn.
00272     // Get the array value in the given row.
00273     void getArrayV (uInt rownr, void* dataPtr);
00274 
00275     // Implement the virtual functions defined in DataManagerColumn.
00276     // Put the array value into the given row.
00277     void putArrayV (uInt rownr, const void* dataPtr);
00278 
00279     // Implement the virtual functions defined in DataManagerColumn.
00280     // Get some array values in the column.
00281     void getArrayColumnCellsV (const RefRows& rownrs, void* dataPtr);
00282 
00283     // Implement the virtual functions defined in DataManagerColumn.
00284     // Put some array values in the column.
00285     void putArrayColumnCellsV (const RefRows& rownrs, const void* dataPtr);
00286 
00287     // Implement the virtual functions defined in DataManagerColumn.
00288     // Get a section of the array in the given row.
00289     void getSliceV (uInt rownr, const Slicer& slicer, void* dataPtr);
00290 
00291     // Implement the virtual functions defined in DataManagerColumn.
00292     // Put into a section of the array in the given row.
00293     void putSliceV (uInt rownr, const Slicer& slicer, const void* dataPtr);
00294 
00295     // Implement the virtual functions defined in DataManagerColumn.
00296     // Get an entire column.
00297     void getArrayColumnV (void* dataPtr);
00298 
00299     // Implement the virtual functions defined in DataManagerColumn.
00300     // Put an entire column.
00301     void putArrayColumnV (const void* dataPtr);
00302 
00303     // Implement the virtual functions defined in DataManagerColumn.
00304     // Get a section of all arrays in the column.
00305     void getColumnSliceV (const Slicer& slicer, void* dataPtr);
00306 
00307     // Implement the virtual functions defined in DataManagerColumn.
00308     // Put into section of all arrays in the column.
00309     void putColumnSliceV (const Slicer& slicer, const void* dataPtr);
00310 
00311     // Implement the virtual functions defined in DataManagerColumn.
00312     // Get a section of some arrays in the column.
00313     virtual void getColumnSliceCellsV (const RefRows& rownrs,
00314                                        const Slicer& slicer, void* dataPtr);
00315 
00316     // Implement the virtual functions defined in DataManagerColumn.
00317     // Put into a section of some arrays in the column.
00318     virtual void putColumnSliceCellsV (const RefRows& rownrs,
00319                                        const Slicer& slicer,
00320                                        const void* dataPtr);
00321 
00322 
00323 private:
00324     // The object cannot be copied.
00325     VirtualArrayColumn (const VirtualArrayColumn<T>&);
00326 
00327     // The object cannot be assigned to.
00328     VirtualArrayColumn<T>& operator= (const VirtualArrayColumn<T>&);
00329 };
00330 
00331 
00332 
00333 
00334 } //# NAMESPACE CASA - END
00335 
00336 #ifndef CASACORE_NO_AUTO_TEMPLATES
00337 #include <tables/Tables/VirtArrCol.tcc>
00338 #endif //# CASACORE_NO_AUTO_TEMPLATES
00339 #endif