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