casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RefColumn.h
Go to the documentation of this file.
00001 //# RefColumn.h: A column in a reference table
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: RefColumn.h 20997 2010-11-17 07:05:29Z gervandiepen $
00027 
00028 #ifndef TABLES_REFCOLUMN_H
00029 #define TABLES_REFCOLUMN_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/BaseColumn.h>
00035 #include <tables/Tables/ColumnCache.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 class RefTable;
00041 class BaseColumnDesc;
00042 class TableRecord;
00043 class Slicer;
00044 class IPosition;
00045 template<class T> class Vector;
00046 
00047 
00048 // <summary>
00049 // A column in a reference table
00050 // </summary>
00051 
00052 // <use visibility=local>
00053 
00054 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //# Classes you should understand before using this one.
00059 //   <li> RefTable
00060 //   <li> BaseColumn
00061 // </prerequisite>
00062 
00063 // <etymology>
00064 // RefTable represents a column in a RefTable. A RefTable is a table
00065 // referencing another table, usually as the result of a select, etc..
00066 // </etymology>
00067 
00068 // <synopsis> 
00069 // RefColumn handles the access of a column in a RefTable.
00070 // It calls the corresponding function in the referenced column
00071 // while converting the given row number to the row number in the
00072 // referenced table.
00073 // </synopsis> 
00074 
00075 // <motivation>
00076 // This class is untyped, i.e. not templated.
00077 // Every call is sent to the underlying referenced BaseColumn which
00078 // is typed by the virtual function mechanism.
00079 // A RefColumn can never be used directly. A user always has to
00080 // construct a typed ArrayColumn or ScalarColumn object to access a column.
00081 // This means everyting is fully type safe.
00082 // </motivation>
00083 
00084 // <todo asof="$DATE:$">
00085 //# A List of bugs, limitations, extensions or planned refinements.
00086 //   <li> Act upon removal of rows or the underlying column
00087 // </todo>
00088 
00089 
00090 class RefColumn : public BaseColumn
00091 {
00092 public:
00093 
00094     // Construct the RefColumn. It will point to the given column
00095     // description, RefTable and referenced column.
00096     // The RefTable will be used to convert the rownr to the rownr
00097     // in the referenced column.
00098     RefColumn (const BaseColumnDesc*, RefTable*, BaseColumn* referencedColumn);
00099 
00100     ~RefColumn();
00101 
00102     // Test if the column is writable in the parent table.
00103     virtual Bool isWritable() const;
00104 
00105     // Test if the column is stored (otherwise it is virtual).
00106     virtual Bool isStored() const;
00107 
00108     // Get access to the column keyword set.
00109     // This is the keyword set in the referenced column.
00110     // <group>
00111     virtual TableRecord& rwKeywordSet();
00112     virtual TableRecord& keywordSet();
00113     // </group>
00114 
00115     // Get nr of rows in the column.
00116     virtual uInt nrow() const;
00117 
00118     // Test if a value in a particular cell has been defined.
00119     virtual Bool isDefined (uInt rownr) const;
00120 
00121     // Set the shape of the array in the given row.
00122     virtual void setShape (uInt rownr, const IPosition& shape);
00123 
00124     // Set the shape and tile shape of the array in the given row.
00125     virtual void setShape (uInt rownr, const IPosition& shape,
00126                            const IPosition& tileShape);
00127 
00128     // Get the global #dimensions of an array (i.e. for all rows).
00129     virtual uInt ndimColumn() const;
00130 
00131     // Get the global shape of an array (i.e. for all rows).
00132     virtual IPosition shapeColumn() const;
00133 
00134     // Get the #dimensions of an array in a particular cell.
00135     virtual uInt ndim (uInt rownr) const;
00136 
00137     // Get the shape of an array in a particular cell.
00138     virtual IPosition shape (uInt rownr) const;
00139 
00140     // It can change shape if the underlying column can.
00141     virtual Bool canChangeShape() const;
00142 
00143     // It can handle a scalar column if the underlying column
00144     // can handle cells in a scalar column.
00145     virtual Bool canAccessScalarColumn (Bool& reask) const;
00146 
00147     // It can handle an array column if the underlying column
00148     // can handle cells in an array column.
00149     virtual Bool canAccessArrayColumn (Bool& reask) const;
00150 
00151     // It can handle a cell slice if the underlying column can do it.
00152     virtual Bool canAccessSlice (Bool& reask) const;
00153 
00154     // It can handle a column slice if the underlying column
00155     // can handle a collection of cells in a column and a column slice.
00156     virtual Bool canAccessColumnSlice (Bool& reask) const;
00157 
00158     // It can handle cells in a scalar column if the underlying column
00159     // can do it.
00160     virtual Bool canAccessScalarColumnCells (Bool& reask) const;
00161 
00162     // It can handle cells in an array column if the underlying column
00163     // can do it.
00164     virtual Bool canAccessArrayColumnCells (Bool& reask) const;
00165 
00166     // Initialize the rows from startRownr till endRownr (inclusive)
00167     // with the default value defined in the column description (if defined).
00168     void initialize (uInt startRownr, uInt endRownr);
00169 
00170     // Get the value from a particular cell.
00171     // This can be a scalar or an array.
00172     virtual void get (uInt rownr, void* dataPtr) const;
00173 
00174     // Get a slice of an N-dimensional array in a particular cell.
00175     virtual void getSlice (uInt rownr, const Slicer&, void* dataPtr) const;
00176 
00177     // Get the vector of all scalar values in a column.
00178     virtual void getScalarColumn (void* dataPtr) const;
00179 
00180     // Get the array of all array values in a column.
00181     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00182     // The arrays in the column have to have the same shape in all cells.
00183     virtual void getArrayColumn (void* dataPtr) const;
00184 
00185     // Get subsections from all arrays in the column.
00186     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00187     // The arrays in the column have to have the same shape in all cells.
00188     virtual void getColumnSlice (const Slicer&, void* dataPtr) const;
00189 
00190     // Get the vector of some scalar values in a column.
00191     virtual void getScalarColumnCells (const RefRows& rownrs,
00192                                        void* dataPtr) const;
00193 
00194     // Get the array of some array values in a column.
00195     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00196     // The arrays in the column have to have the same shape in all cells.
00197     virtual void getArrayColumnCells (const RefRows& rownrs,
00198                                       void* dataPtr) const;
00199 
00200     // Get subsections from some arrays in the column.
00201     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00202     // The arrays in the column have to have the same shape in all cells.
00203     virtual void getColumnSliceCells (const RefRows& rownrs,
00204                                       const Slicer&, void* dataPtr) const;
00205 
00206     // Put the value in a particular cell.
00207     // This can be a scalar or an array.
00208     virtual void put (uInt rownr, const void* dataPtr);
00209 
00210     // Put a slice of an N-dimensional array in a particular cell.
00211     virtual void putSlice (uInt rownr, const Slicer&, const void* dataPtr);
00212 
00213     // Put the vector of all scalar values in the column.
00214     virtual void putScalarColumn (const void* dataPtr);
00215 
00216     // Put the array of all array values in the column.
00217     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00218     // The arrays in the column have to have the same shape in all cells.
00219     virtual void putArrayColumn (const void* dataPtr);
00220 
00221     // Put into subsections of all table arrays in the column.
00222     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00223     // The arrays in the column have to have the same shape in all cells.
00224     virtual void putColumnSlice (const Slicer&, const void* dataPtr);
00225 
00226     // Get the vector of some scalar values in a column.
00227     virtual void putScalarColumnCells (const RefRows& rownrs,
00228                                        const void* dataPtr);
00229 
00230     // Get the array of some array values in a column.
00231     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00232     // The arrays in the column have to have the same shape in all cells.
00233     virtual void putArrayColumnCells (const RefRows& rownrs,
00234                                       const void* dataPtr);
00235 
00236     // Put subsections of some arrays in the column.
00237     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00238     // The arrays in the column have to have the same shape in all cells.
00239     virtual void putColumnSliceCells (const RefRows& rownrs,
00240                                       const Slicer&, const void* dataPtr);
00241 
00242     // Get the underlying column cache.
00243     virtual ColumnCache& columnCache();
00244 
00245     // Set the maximum cache size (in bytes) to be used by a storage manager.
00246     virtual void setMaximumCacheSize (uInt nbytes);
00247 
00248     // Add this column and its data to the Sort object.
00249     // It may allocate some storage on the heap, which will be saved
00250     // in the argument dataSave.
00251     // The function freeSortKey must be called to free this storage.
00252     virtual void makeSortKey (Sort&, CountedPtr<BaseCompare>& cmpObj,
00253                               Int order, const void*& dataSave);
00254 
00255     // Free storage on the heap allocated by makeSortkey().
00256     // The pointer will be set to zero.
00257     virtual void freeSortKey (const void*& dataSave);
00258 
00259     // Allocate value buffers for the table iterator.
00260     // Also get a comparison functiuon if undefined.
00261     // The function freeIterBuf must be called to free the buffers.
00262     virtual void allocIterBuf (void*& lastVal, void*& curVal,
00263                                CountedPtr<BaseCompare>& cmpObj);
00264 
00265     // Free the value buffers allocated by allocIterBuf.
00266     virtual void freeIterBuf (void*& lastVal, void*& curVal);
00267 
00268 protected:
00269     RefTable*        refTabPtr_p;
00270     BaseColumn*      colPtr_p;
00271     ColumnCache      colCache_p;
00272 };
00273 
00274 
00275 
00276 
00277 } //# NAMESPACE CASA - END
00278 
00279 #endif