casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ScaColData.h
Go to the documentation of this file.
00001 //# ScaColData.h: Access to a table column containing scalars
00002 //# Copyright (C) 1994,1995,1996,1998,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: ScaColData.h 20997 2010-11-17 07:05:29Z gervandiepen $
00027 
00028 #ifndef TABLES_SCACOLDATA_H
00029 #define TABLES_SCACOLDATA_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/PlainColumn.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 class ColumnSet;
00039 template<class T> class ScalarColumnDesc;
00040 class AipsIO;
00041 template<class T> class Vector;
00042 
00043 
00044 // <summary>
00045 // Access to a table column containing scalars
00046 // </summary>
00047 
00048 // <use visibility=local>
00049 
00050 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //# Classes you should understand before using this one.
00055 //   <li> PlainColumn
00056 //   <li> ScalarColumnDesc
00057 //   <li> Table
00058 // </prerequisite>
00059 
00060 // <etymology>
00061 // ScalarColumnData represents a table column containing scalars.
00062 // </etymology>
00063 
00064 // <synopsis> 
00065 // The class ScalarColumnData is derived from PlainColumn.
00066 // It implements the virtual functions accessing a table column
00067 // containing scalars with an arbitrary data type.
00068 //
00069 // It is possible to access an scalar an individual cell (i.e. table row)
00070 // or in the entire column.
00071 //
00072 // The main task of this class is to communicate with the data manager
00073 // column object. This consists of:
00074 // <ul>
00075 //  <li> Binding itself to a data manager.
00076 //  <li> Letting the data manager create its column object.
00077 //  <li> Closing the data manager column object (in putFileDerived).
00078 //  <li> Reconstructing the data manager object for an existing table
00079 //         (in getFileDerived).
00080 //  <li> Transferring get/put calls to the data manager column object.
00081 // </ul>
00082 //
00083 // The class is hidden from the user by the envelope class ScalarColumn.
00084 // It used directly, it should be done with care. It assumes that the
00085 // arrays in the various get and put functions have the correct length.
00086 // ScalarColumn does that check.
00087 // </synopsis>
00088 
00089 // <todo asof="$DATE:$">
00090 //# A List of bugs, limitations, extensions or planned refinements.
00091 // </todo>
00092 
00093 
00094 template<class T>
00095 class ScalarColumnData : public PlainColumn
00096 {
00097 public:
00098 
00099     // Construct a scalar column object from the given description
00100     // in the given column set.
00101     // This constructor is used by ScalarColumnDesc::makeColumn.
00102     ScalarColumnData (const ScalarColumnDesc<T>*, ColumnSet*);
00103 
00104     ~ScalarColumnData();
00105 
00106     // Ask if the data manager can handle a column.
00107     Bool canAccessScalarColumn (Bool& reask) const;
00108 
00109     // Ask if the data manager can handle some cells in a column.
00110     Bool canAccessScalarColumnCells (Bool& reask) const;
00111 
00112     // Initialize the rows from startRownr till endRownr (inclusive)
00113     // with the default value defined in the column description.
00114     void initialize (uInt startRownr, uInt endRownr);
00115 
00116     // Test if the given cell contains a defined value.
00117     Bool isDefined (uInt rownr) const;
00118 
00119     // Get the value from a particular cell.
00120     void get (uInt rownr, void*) const;
00121 
00122     // Get the array of all values in the column.
00123     // The length of the buffer pointed to by dataPtr must match
00124     // the actual length. This is checked by ScalarColumn.
00125     void getScalarColumn (void* dataPtr) const;
00126 
00127     // Get the array of some values in the column (on behalf of RefColumn).
00128     // The length of the buffer pointed to by dataPtr must match
00129     // the actual length. This is checked by ScalarColumn.
00130     void getScalarColumnCells (const RefRows& rownrs, void* dataPtr) const;
00131 
00132     // Put the value in a particular cell.
00133     // The length of the buffer pointed to by dataPtr must match
00134     // the actual length. This is checked by ScalarColumn.
00135     void put (uInt rownr, const void* dataPtr);
00136 
00137     // Put the array of all values in the column.
00138     // The length of the buffer pointed to by dataPtr must match
00139     // the actual length. This is checked by ScalarColumn.
00140     void putScalarColumn (const void* dataPtr);
00141 
00142     // Put the array of some values in the column (on behalf on RefColumn).
00143     // The length of the buffer pointed to by dataPtr must match
00144     // the actual length. This is checked by ScalarColumn.
00145     void putScalarColumnCells (const RefRows& rownrs, const void* dataPtr);
00146 
00147     // Add this column and its data to the Sort object.
00148     // It may allocate some storage on the heap, which will be saved
00149     // in the argument dataSave.
00150     // The function freeSortKey must be called to free this storage.
00151     // <thrown>
00152     //   <li> TableInvSort
00153     // </thrown>
00154     // <group>
00155     void makeSortKey (Sort&, CountedPtr<BaseCompare>& cmpFunc, Int order,
00156                       const void*& dataSave);
00157     // Do it only for the given row numbers.
00158     void makeRefSortKey (Sort&, CountedPtr<BaseCompare>& cmpFunc, Int order,
00159                          const Vector<uInt>& rownrs, const void*& dataSave);
00160     // </group>
00161 
00162     // Free storage on the heap allocated by makeSortkey().
00163     // The pointer will be set to zero.
00164     void freeSortKey (const void*& dataSave);
00165 
00166     // Allocate value buffers for the table iterator.
00167     // Also get a comparison object if undefined.
00168     // The function freeIterBuf must be called to free the buffers.
00169     void allocIterBuf (void*& lastVal, void*& curVal,
00170                        CountedPtr<BaseCompare>& cmpObj);
00171 
00172     // Free the value buffers allocated by allocIterBuf.
00173     void freeIterBuf (void*& lastVal, void*& curVal);
00174 
00175     // Create a data manager column object for this column.
00176     void createDataManagerColumn();
00177 
00178 
00179 private:
00180     // Pointer to column description.
00181     const ScalarColumnDesc<T>* scaDescPtr_p;
00182     // Undefined value can exist?
00183     Bool undefFlag_p;
00184     // Undefined value.
00185     T undefVal_p;
00186     
00187 
00188     // Copy constructor cannot be used.
00189     ScalarColumnData (const ScalarColumnData<T>&);
00190 
00191     // Assignment cannot be used.
00192     ScalarColumnData<T>& operator= (const ScalarColumnData<T>&);
00193 
00194     // Write the column data.
00195     // The control information is written into the given AipsIO object,
00196     // while the data is written/flushed by the data manager.
00197     void putFileDerived (AipsIO&);
00198 
00199     // Read the column data back.
00200     // The control information is read from the given AipsIO object.
00201     // This is used to bind the column to the appropriate data manager.
00202     // Thereafter the data manager gets opened.
00203     void getFileDerived (AipsIO&, const ColumnSet&);
00204 
00205     // Fill in the sort key on behalf of the Table sort function.
00206     // The pointer to the data (which can be allocated on the heap)
00207     // is stored in dataPtr. This is used by freeSortKey to release it.
00208     // It checks if a compare function is given when needed.
00209     // <thrown>
00210     //   <li> TableInvSort
00211     // </thrown>
00212     void fillSortKey (const Vector<T>* dataPtr, Sort&,
00213                       CountedPtr<BaseCompare>& cmpObj, Int order);
00214 };
00215 
00216 
00217 
00218 } //# NAMESPACE CASA - END
00219 
00220 #ifndef CASACORE_NO_AUTO_TEMPLATES
00221 #include <tables/Tables/ScaColData.tcc>
00222 #endif //# CASACORE_NO_AUTO_TEMPLATES
00223 #endif