casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VirtColEng.h
Go to the documentation of this file.
00001 //# VirtColEng.h: Abstract base class for virtual column handling
00002 //# Copyright (C) 1994,1995,1996,1997,1999,2001
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: VirtColEng.h 20926 2010-07-05 11:42:12Z gervandiepen $
00027 
00028 #ifndef TABLES_VIRTCOLENG_H
00029 #define TABLES_VIRTCOLENG_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 
00039 
00040 // <summary>
00041 // Abstract base class for virtual column handling
00042 // </summary>
00043 
00044 // <use visibility=local>
00045 
00046 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //# Classes you should understand before using this one.
00051 //   <li> DataManager
00052 //   <li> Table
00053 // </prerequisite>
00054 
00055 // <etymology>
00056 // VirtualColumnEngine is the abstract data manager class for specialized
00057 // classes (engines) handling a group of virtual columns.
00058 // </etymology>
00059 
00060 // <synopsis> 
00061 // VirtualColumnEngine is the data manager for classes handling
00062 // a group of virtual columns in tables. It is an abstract base class
00063 // for the specialized virtual column engines.
00064 // Each virtual column as such is represented by a class which has
00065 // to be derived from the abstract base classes VirtualScalarColumn
00066 // or VirtualArrayColumn. The engine has to create the various
00067 // column objects via the functions makeXXXColumn.
00068 //
00069 // Initialization of the virtual column engine is done by the
00070 // functions create (for new tables), open (for existing tables) and prepare.
00071 // The engine can be flushed by the function flush, which allows to
00072 // write some data. The function open can read these data back.
00073 // VirtualColumnEngine is closely related with the table system.
00074 //
00075 // A number of (pure) virtual functions have been defined. The pure
00076 // virtual functions must be implemented in the derived class.
00077 // The non-pure virtual functions have a default implementation throwing
00078 // a "not possible" exception. They need to be implemented if they
00079 // are used for this engine (e.g. makeIndArrColumn does not need to
00080 // be implemented if the engine does not handle arrays).
00081 // Furthermore the pure virtual function dataManagerType (defined in
00082 // DataManager.h) has to be implemented. This should return the name
00083 // of the data manager, which is usually its class name. This name
00084 // has to be unique; so if the engine is templated, the template
00085 // parameter has to be part of the data manager name.
00086 //
00087 // The engine has to be registered before it can be used by the table system.
00088 // This means that a special makeObject function has to be made
00089 // known to the table system, which allows the table system to
00090 // reconstruct the engine using its name.
00091 //
00092 // An example of a virtual column engine can be found in dVirtColEng.{h,cc}
00093 // in the test directory of the Tables module.
00094 // Another exanple is class ScaledArray.
00095 // </synopsis> 
00096 
00097 // <motivation>
00098 // It is nice if a table column can be expressed as a function
00099 // of other columns (maybe even in other tables). A virtual column
00100 // provides this functionality in a very flexible way.
00101 // A specialized class can calculate the data of a virtual column,
00102 // but a common base class is required to interface it to the
00103 // table system.
00104 // </motivation>
00105 
00106 // <todo asof="$DATE:$">
00107 //# A List of bugs, limitations, extensions or planned refinements.
00108 // </todo>
00109 
00110 
00111 class VirtualColumnEngine : public DataManager
00112 {
00113 public:
00114 
00115     // Create the object.
00116     VirtualColumnEngine()
00117         {};
00118 
00119     virtual ~VirtualColumnEngine();
00120 
00121 private:
00122     // The copy constructor cannot be used for this base class.
00123     // The clone function should be used instead.
00124     // The private declaration of this constructor makes it unusable.
00125     VirtualColumnEngine (const VirtualColumnEngine& that);
00126 
00127     // Assignment cannot be used for this base class.
00128     // The private declaration of this operator makes it unusable.
00129     VirtualColumnEngine& operator= (const VirtualColumnEngine&);
00130 
00131     // The data manager is not a storage manager?
00132     virtual Bool isStorageManager() const;
00133 
00134     // Does the data manager allow to add rows? (default no)
00135     virtual Bool canAddRow() const;
00136 
00137     // Does the data manager allow to delete rows? (default no)
00138     virtual Bool canRemoveRow() const;
00139 
00140     // Add rows to all columns.
00141     // The default implementation does nothing.
00142     virtual void addRow (uInt nrrow);
00143 
00144     // Delete a row from all columns.
00145     // The default implementation does nothing.
00146     virtual void removeRow (uInt rownr);
00147 
00148     // Flush the data in the engine object.
00149     // If the object contains persistent data, this is the place to write them.
00150     // This can be done in two ways:
00151     // <ul>
00152     // <li>
00153     // They can be written in the main table file (using the AipsIO argument).
00154     // This should preferably be used if the object contains only little data.
00155     // <li>
00156     // They can be written in a file of its own. A unique filename
00157     // can be acquired using DataManager::fileName().
00158     // This way is preferred when the object contains a lot of data.
00159     // Possibly this file could already be created in function create
00160     // and only be flushed and closed in this function. This allows
00161     // getting and putting of data as needed.
00162     // </ul>
00163     // Another way of storing information is by storing it as a keyword
00164     // in the table. In this case it is important to know that close
00165     // is called AFTER the keywords are written. Thus, in this way the
00166     // information has to be stored and read back in create, open and/or
00167     // prepare.
00168     // It returns a True status if it had to flush (i.e. if data have changed).
00169     // <br>The default implementation does nothing and returns False.
00170     virtual Bool flush (AipsIO&, Bool fsync);
00171 
00172     // Resync the storage manager with the new file contents.
00173     // This is done by clearing the cache.
00174     // The default implementation does nothing.
00175     virtual void resync (uInt nrrow);
00176 
00177     // Initialize the object for a new table containing initially nrrow rows.
00178     // It can be used to initialize variables (possibly using data
00179     // from other columns in the table).
00180     // The default implementation does nothing.
00181     virtual void create (uInt initialNrrow);
00182 
00183     // Initialize the object for an existing table containing nrrow rows.
00184     // It can be used to read values back (written by close) and/or
00185     // to initialize variables (possibly using data from other columns
00186     // in the table).
00187     // The default implementation does nothing.
00188     virtual void open (uInt nrrow, AipsIO& mainTableFile);
00189 
00190     // Let the data manager initialize itself further.
00191     // Prepare is called after create/open has been called for all
00192     // columns. In this way one can be sure that referenced columns
00193     // are read back and partly initialized.
00194     // The default implementation does nothing.
00195     virtual void prepare();
00196 
00197     // The data manager will be deleted (because all its columns are
00198     // requested to be deleted).
00199     // So clean up the things needed (e.g. delete files).
00200     // By default it assumes that nothing has to be done.
00201     virtual void deleteManager();
00202 
00203     // Make a column object in the engine on behalf of a table column.
00204     // This column object class is derived from VirtualScalarColumn
00205     // or VirtualArrayColumn. It handles the gets and puts of data.
00206     // <group>
00207     // Create a scalar column.
00208     // The default implementation throws an exception that it cannot
00209     // do it for this column.
00210     virtual DataManagerColumn* makeScalarColumn (const String& columnName,
00211                                                  int dataType,
00212                                                  const String& dataTypeId);
00213     // Create a direct array column.
00214     // The default implementation calls makeIndArrColumn
00215     // (when reading the user sees no difference between direct and indirect).
00216     virtual DataManagerColumn* makeDirArrColumn (const String& columnName,
00217                                                  int dataType,
00218                                                  const String& dataTypeId);
00219     // Create an indirect array column.
00220     // The default implementation throws an exception that it cannot
00221     // do it for this column.
00222     virtual DataManagerColumn* makeIndArrColumn (const String& columnName,
00223                                                  int dataType,
00224                                                  const String& dataTypeId);
00225     // </group>
00226 };
00227 
00228 
00229 
00230 } //# NAMESPACE CASA - END
00231 
00232 #endif
00233 
00234 
00235