casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
BaseColumn.h
Go to the documentation of this file.
00001 //# BaseColumn.h: Abstract base class for a table column
00002 //# Copyright (C) 1994,1995,1996,1997,1998
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: BaseColumn.h 21130 2011-10-18 07:39:05Z gervandiepen $
00027 
00028 #ifndef TABLES_BASECOLUMN_H
00029 #define TABLES_BASECOLUMN_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/ColumnDesc.h>
00035 #include <casa/Utilities/Compare.h>
00036 #include <casa/Utilities/CountedPtr.h>
00037 #include <casa/BasicSL/Complex.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 class BaseColumnDesc;
00043 class ColumnCache;
00044 class TableRecord;
00045 class RefRows;
00046 class IPosition;
00047 class Slicer;
00048 class Sort;
00049 template<class T> class Array;
00050 template<class T> class Vector;
00051 
00052 // <summary>
00053 // Abstract base class for a table column
00054 // </summary>
00055 
00056 // <use visibility=local>
00057 
00058 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00059 // </reviewed>
00060 
00061 // <prerequisite>
00062 //# Classes you should understand before using this one.
00063 //   <li> ColumnDesc
00064 //   <li> Table
00065 // </prerequisite>
00066 
00067 // <etymology>
00068 // This is the (abstract) base class to access a column in a table.
00069 // </etymology>
00070 
00071 // <synopsis> 
00072 // This class is the base class for the derived column classes.
00073 // It is a private class in the sense that the user cannot get
00074 // access to it. All user access to a column is done via the
00075 // classes TableColumn, ScalarColumn and ArrayColumn. They call
00076 // the corresponding functions in this class and its derived classes.
00077 // </synopsis> 
00078 
00079 // <motivation>
00080 // This class serves a the base for the more specialized column classes
00081 // like FilledScalarColumn and RefColumn. It defines many virtual
00082 // functions, which are implemented in the derived classes.
00083 // Some of these functions are purely virtual, some have a default
00084 // implementation throwing an "invalid operation" exception. In that
00085 // way those latter functions only have to be implemented in the
00086 // classes which handle those cases.
00087 // <note role=tip> The class RefColumn is in fact implemented in terms of
00088 // this class. Almost every function in RefColumn calls the corresponding
00089 // function in BaseColumn with the correct row number.
00090 // </note>
00091 // </motivation>
00092 
00093 // <todo asof="$DATE:$">
00094 //# A List of bugs, limitations, extensions or planned refinements.
00095 // </todo>
00096 
00097 
00098 class BaseColumn
00099 {
00100 public:
00101 
00102     // Construct it using the given column description.
00103     BaseColumn (const BaseColumnDesc*);
00104 
00105     virtual ~BaseColumn();
00106 
00107     // Test if the column is writable.
00108     virtual Bool isWritable() const = 0;
00109 
00110     // Test if the column is stored (otherwise it is virtual).
00111     virtual Bool isStored() const = 0;
00112 
00113     // Get access to the column keyword set.
00114     // <group>
00115     virtual TableRecord& rwKeywordSet() = 0;
00116     virtual TableRecord& keywordSet() = 0;
00117     // </group>
00118 
00119     // Get const access to the column description.
00120     const ColumnDesc& columnDesc() const
00121         { return colDesc_p; }
00122 
00123     // Get nr of rows in the column.
00124     virtual uInt nrow() const = 0;
00125 
00126     // Test if the given cell contains a defined value.
00127     virtual Bool isDefined (uInt rownr) const = 0;
00128 
00129     // Set the shape of the array in the given row.
00130     virtual void setShape (uInt rownr, const IPosition& shape);
00131 
00132     // Set the shape and tile shape of the array in the given row.
00133     virtual void setShape (uInt rownr, const IPosition& shape,
00134                            const IPosition& tileShape);
00135 
00136     // Get the global #dimensions of an array (ie. for all rows).
00137     virtual uInt ndimColumn() const;
00138 
00139     // Get the global shape of an array (ie. for all rows).
00140     virtual IPosition shapeColumn() const;
00141 
00142     // Get the #dimensions of an array in a particular cell.
00143     virtual uInt ndim (uInt rownr) const;
00144 
00145     // Get the shape of an array in a particular cell.
00146     virtual IPosition shape (uInt rownr) const;
00147 
00148     // Ask the data manager if the shape of an existing array can be changed.
00149     // Default is no.
00150     virtual Bool canChangeShape() const;
00151 
00152     // Ask if the data manager can handle a scalar column.
00153     // Default is never.
00154     virtual Bool canAccessScalarColumn (Bool& reask) const;
00155 
00156     // Ask if the data manager can handle an array column.
00157     // Default is never.
00158     virtual Bool canAccessArrayColumn (Bool& reask) const;
00159 
00160     // Ask if the data manager can handle a collection of cells in a
00161     // scalar column. Default is never.
00162     virtual Bool canAccessScalarColumnCells (Bool& reask) const;
00163 
00164     // Ask if the data manager can handle a collection of cells in an
00165     // array column. Default is never.
00166     virtual Bool canAccessArrayColumnCells (Bool& reask) const;
00167 
00168     // Ask if the data manager can handle a cell slice.
00169     // Default is never.
00170     virtual Bool canAccessSlice (Bool& reask) const;
00171 
00172     // Ask if the data manager can handle a column slice.
00173     // Default is never.
00174     virtual Bool canAccessColumnSlice (Bool& reask) const;
00175 
00176     // Initialize the rows from startRow till endRow (inclusive)
00177     // with the default value defined in the column description.
00178     virtual void initialize (uInt startRownr, uInt endRownr) = 0;
00179 
00180     // Get the value from a particular cell.
00181     // This can be a scalar or an array.
00182     virtual void get (uInt rownr, void* dataPtr) const = 0;
00183 
00184     // Get a slice of an N-dimensional array in a particular cell.
00185     virtual void getSlice (uInt rownr, const Slicer&, void* dataPtr) const;
00186 
00187     // Get the vector of all scalar values in a column.
00188     virtual void getScalarColumn (void* dataPtr) const;
00189 
00190     // Get the array of all array values in a column.
00191     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00192     // The arrays in the column have to have the same shape in all cells.
00193     virtual void getArrayColumn (void* dataPtr) const;
00194 
00195     // Get subsections from all arrays in the column.
00196     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00197     // The arrays in the column have to have the same shape in all cells.
00198     virtual void getColumnSlice (const Slicer&, void* dataPtr) const;
00199 
00200     // Get the vector of some scalar values in a column.
00201     virtual void getScalarColumnCells (const RefRows& rownrs,
00202                                        void* dataPtr) const;
00203 
00204     // Get the array of some array values in a column.
00205     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00206     // The arrays in the column have to have the same shape in all cells.
00207     virtual void getArrayColumnCells (const RefRows& rownrs,
00208                                       void* dataPtr) const;
00209 
00210     // Get subsections from some arrays in the column.
00211     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00212     // The arrays in the column have to have the same shape in all cells.
00213     virtual void getColumnSliceCells (const RefRows& rownrs,
00214                                       const Slicer&, void* dataPtr) const;
00215 
00216     // Put the value in a particular cell.
00217     // This can be a scalar or an array.
00218     virtual void put (uInt rownr, const void* dataPtr) = 0;
00219 
00220     // Put a slice of an N-dimensional array in a particular cell.
00221     virtual void putSlice (uInt rownr, const Slicer&, const void* dataPtr);
00222 
00223     // Put the vector of all scalar values in the column.
00224     virtual void putScalarColumn (const void* dataPtr);
00225 
00226     // Put the array of all array values in the column.
00227     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00228     // The arrays in the column have to have the same shape in all cells.
00229     virtual void putArrayColumn (const void* dataPtr);
00230 
00231     // Put into subsections of all table arrays in the column.
00232     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00233     // The arrays in the column have to have the same shape in all cells.
00234     virtual void putColumnSlice (const Slicer&, const void* dataPtr);
00235 
00236     // Get the vector of some scalar values in a column.
00237     virtual void putScalarColumnCells (const RefRows& rownrs,
00238                                        const void* dataPtr);
00239 
00240     // Get the array of some array values in a column.
00241     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00242     // The arrays in the column have to have the same shape in all cells.
00243     virtual void putArrayColumnCells (const RefRows& rownrs,
00244                                       const void* dataPtr);
00245 
00246     // Put subsections of some arrays in the column.
00247     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00248     // The arrays in the column have to have the same shape in all cells.
00249     virtual void putColumnSliceCells (const RefRows& rownrs,
00250                                       const Slicer&, const void* dataPtr);
00251 
00252     // Get the value from the row and convert it to the required type.
00253     // This can only be used for scalar columns with a standard data type.
00254     // Note that an unsigned integer caanot be converted to a signed integer
00255     // with the same length. So only Int64 can handle all integer values.
00256     // <group>
00257     void getScalar (uInt rownr, Bool& value) const;
00258     void getScalar (uInt rownr, uChar& value) const;
00259     void getScalar (uInt rownr, Short& value) const;
00260     void getScalar (uInt rownr, uShort& value) const;
00261     void getScalar (uInt rownr, Int& value) const;
00262     void getScalar (uInt rownr, uInt& value) const;
00263     void getScalar (uInt rownr, Int64& value) const;
00264     void getScalar (uInt rownr, float& value) const;
00265     void getScalar (uInt rownr, double& value) const;
00266     void getScalar (uInt rownr, Complex& value) const;
00267     void getScalar (uInt rownr, DComplex& value) const;
00268     void getScalar (uInt rownr, String& value) const;
00269     void getScalar (uInt rownr, TableRecord& value) const;
00270     // </group>
00271 
00272     // Get a scalar for the other data types.
00273     // The given data type id must match the data type id of this column.
00274     void getScalar (uInt rownr, void* value, const String& dataTypeId) const;
00275 
00276     // Put the value into the row and convert it from the given type.
00277     // This can only be used for scalar columns with a standard data type.
00278     // <group>
00279     void putScalar (uInt rownr, const Bool& value);
00280     void putScalar (uInt rownr, const uChar& value);
00281     void putScalar (uInt rownr, const Short& value);
00282     void putScalar (uInt rownr, const uShort& value);
00283     void putScalar (uInt rownr, const Int& value);
00284     void putScalar (uInt rownr, const uInt& value);
00285     void putScalar (uInt rownr, const float& value);
00286     void putScalar (uInt rownr, const double& value);
00287     void putScalar (uInt rownr, const Complex& value);
00288     void putScalar (uInt rownr, const DComplex& value);
00289     void putScalar (uInt rownr, const String& value);
00290     void putScalar (uInt rownr, const Char* value)
00291         { putScalar (rownr, String(value)); }
00292     void putScalar (uInt rownr, const TableRecord& value);
00293     // </group>
00294 
00295     // Get a pointer to the underlying column cache.
00296     virtual ColumnCache& columnCache() = 0;
00297 
00298     // Set the maximum cache size (in bytes) to be used by a storage manager.
00299     virtual void setMaximumCacheSize (uInt nbytes) = 0;
00300 
00301     // Add this column and its data to the Sort object.
00302     // It may allocate some storage on the heap, which will be saved
00303     // in the argument dataSave.
00304     // The function freeSortKey must be called to free this storage.
00305     // <group>
00306     virtual void makeSortKey (Sort&, CountedPtr<BaseCompare>& cmpObj,
00307                               Int order, const void*& dataSave);
00308     // Do it only for the given row numbers.
00309     virtual void makeRefSortKey (Sort&, CountedPtr<BaseCompare>& cmpObj,
00310                                  Int order, const Vector<uInt>& rownrs,
00311                                  const void*& dataSave);
00312     // </group>
00313 
00314     // Free storage on the heap allocated by makeSortkey().
00315     // The pointer will be set to zero.
00316     virtual void freeSortKey (const void*& dataSave);
00317 
00318     // Allocate value buffers for the table iterator.
00319     // Also get a comparison object if undefined.
00320     // The function freeIterBuf must be called to free the buffers.
00321     virtual void allocIterBuf (void*& lastVal, void*& curVal,
00322                                CountedPtr<BaseCompare>& cmpObj);
00323 
00324     // Free the value buffers allocated by allocIterBuf.
00325     virtual void freeIterBuf (void*& lastVal, void*& curVal);
00326 
00327 protected:
00328     // Throw exceptions for invalid scalar get or put.
00329     // <group>
00330     void throwGetScalar() const;
00331     void throwPutScalar() const;
00332     void throwGetType (const String& type) const;
00333     void throwPutType (const String& type) const;
00334     // </group>
00335 
00336     //# Data members
00337     const BaseColumnDesc*  colDescPtr_p;
00338     //# This ColumnDesc object is created to be able to return 
00339     //# a const ColumnDesc& by function columnDesc().
00340     ColumnDesc             colDesc_p;
00341 };
00342 
00343 
00344 
00345 
00346 } //# NAMESPACE CASA - END
00347 
00348 #endif