VirtualTaQLColumn.h

Go to the documentation of this file.
00001 //# VirtualTaQLColumn.h: Virtual column engine based on TaQL
00002 //# Copyright (C) 2005
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$
00027 
00028 #ifndef TABLES_VIRTUALTAQLCOLUMN_H
00029 #define TABLES_VIRTUALTAQLCOLUMN_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/DataMan/VirtColEng.h>
00034 #include <casacore/tables/DataMan/DataManager.h>
00035 #include <casacore/casa/Arrays/IPosition.h>
00036 
00037 namespace casacore {
00038 //# Forward Declarations
00039 class TableExprNode;
00040 
00041 
00042 // <category lib=aips module="Tables" sect="Virtual Columns">
00043 // <summary> Virtual scalar column using TaQL</summary>
00044 // <reviewed reviewer="GvD" date="2004/07/09" tests="">
00045 //
00046 // <prerequisite>
00047 //# Classes you should understand before using this one.
00048 //   <li> VirtualScalarColumn
00049 // </prerequisite>
00050 //
00051 // <synopsis> 
00052 // VirtualTaQLColumn is a virtual column engine to define the contents of a
00053 // column as a TaQL expression in which possibly other columns are used.
00054 // It is (of course) only possible to get data from the column; puts cannot
00055 // be done.
00056 // <br>
00057 // The expression result can be a scalar or array of the basic TaQL data types.
00058 // The column data type has to be conformant with that TaQL type, thus a
00059 // column of any integer type has to be used for an integer TaQL result.
00060 // <note role=caution> One has to be careful with deleting columns. If in an
00061 // existing table a TaQL expression uses a deleted column, the expression
00062 // cannot be parsed anymore and the table cannot be opened anymore.
00063 // In the future the Table System will be made more forgiving.
00064 // </note>
00065 // </synopsis> 
00066 //
00067 // <example>
00068 // The following example creates a table with a few columns.
00069 // One column is virtual and has a random value if Col3 is true.
00070 // Otherwise it has value 0.
00071 // <srcblock>
00072 //    // Create the table description.
00073 //    TableDesc td;
00074 //    td.addColumn (ScalarColumnDesc<DComplex>("Col1"));
00075 //    td.addColumn (ScalarColumnDesc<Int>("Col2"));
00076 //    td.addColumn (ScalarColumnDesc<Bool>("Col3"));
00077 //    td.addColumn (ScalarColumnDesc<Double>("ColVirt"));
00078 //  
00079 //    // Now create a new table from the description.
00080 //    SetupNewTable newTab("tmtest", td, Table::New);
00081 //    // Define the expression of the virtual column and bind the column to it.
00082 //    // The other columns are by default bound to StandardStMan.
00083 //    VirtualTaQLColumn engine("iif(Col3,rand(),0)");
00084 //    newTab.bindColumn("ColVirt", engine);
00085 //    Table tab(newTab);
00086 // </srcblock>
00087 // </example>
00088 
00089 class VirtualTaQLColumn : public VirtualColumnEngine, public DataManagerColumn
00090 {
00091 public:
00092 
00093   // Construct it with the given TaQL expression.
00094   VirtualTaQLColumn (const String& expr);
00095 
00096   // Construct it with the given specification.
00097   VirtualTaQLColumn (const Record& spec);
00098 
00099   // Destructor is mandatory.
00100   virtual ~VirtualTaQLColumn();
00101 
00102   // Clone the engine object.
00103   virtual DataManager* clone() const;
00104 
00105   // Get the data manager specification.
00106   virtual Record dataManagerSpec() const;
00107 
00108   // Return the type name of the engine.
00109   // (i.e. its class name VirtualTaQLColumn).
00110   virtual String dataManagerType() const;
00111 
00112   // Return the name of the class.
00113   static String className();
00114 
00115   // Register the class name and the static makeObject "constructor".
00116   // This will make the engine known to the table system.
00117   static void registerClass();
00118 
00119   // Define the "constructor" to construct this engine when a
00120   // table is read back.
00121   // This "constructor" has to be registered by the user of the engine.
00122   // If the engine is commonly used, its registration can be added
00123   // into the registerAllCtor function in DataManReg.cc. 
00124   // This function gets automatically invoked by the table system.
00125   static DataManager* makeObject (const String& dataManagerName,
00126                                   const Record& spec);
00127 
00128   // Return the TaQL expression used.
00129   const String& expression() const
00130     { return itsExpr; }
00131 
00132   // Functions to return column info.
00133   // <group>
00134   virtual int dataType() const;
00135   virtual Bool isWritable() const;
00136   virtual uInt ndim (uInt rownr);
00137   virtual IPosition shape (uInt rownr);
00138   virtual Bool isShapeDefined (uInt rownr);
00139   // </group>
00140 
00141 private:
00142   // Copy is not needed and therefore forbidden (so it is made private).
00143   VirtualTaQLColumn (const VirtualTaQLColumn&);
00144 
00145   // Assignment is not needed and therefore forbidden (so it is made private).
00146   VirtualTaQLColumn& operator= (const VirtualTaQLColumn&);
00147 
00148   // Create the column object for the scalar column in this engine.
00149   virtual DataManagerColumn* makeScalarColumn (const String& columnName,
00150                                                int dataType, const String&);
00151 
00152   // Create the column object for the indirect array column in this engine.
00153   virtual DataManagerColumn* makeIndArrColumn (const String& columnName,
00154                                                int dataType,
00155                                                const String& dataTypeId);
00156 
00157   // Let the engine initialize the object for a new table.
00158   // It defines a column keyword holding the expression.
00159   virtual void create (uInt);
00160 
00161   // Prepare compiles the expression.
00162   virtual void prepare();
00163 
00164   //# We could also define the getBlockXXV functions, but
00165   //# that is not required. The default implementation gets
00166   //# one value. Possible optimization can be done by
00167   //# implementing it here.
00168   //# The same is true for getColumn.
00169 
00170   // Get the scalar value in the given row.
00171   // The default implementation throws an "invalid operation" exception.
00172   // <group>
00173   virtual void getBoolV     (uInt rownr, Bool* dataPtr);
00174   virtual void getuCharV    (uInt rownr, uChar* dataPtr);
00175   virtual void getShortV    (uInt rownr, Short* dataPtr);
00176   virtual void getuShortV   (uInt rownr, uShort* dataPtr);
00177   virtual void getIntV      (uInt rownr, Int* dataPtr);
00178   virtual void getuIntV     (uInt rownr, uInt* dataPtr);
00179   virtual void getfloatV    (uInt rownr, float* dataPtr);
00180   virtual void getdoubleV   (uInt rownr, double* dataPtr);
00181   virtual void getComplexV  (uInt rownr, Complex* dataPtr);
00182   virtual void getDComplexV (uInt rownr, DComplex* dataPtr);
00183   virtual void getStringV   (uInt rownr, String* dataPtr);
00184   // </group>
00185 
00186   // Get the array value in the given row.
00187   // The argument dataPtr is in fact an Array<T>*, but a void*
00188   // is needed to be generic.
00189   // The array pointed to by dataPtr has to have the correct shape
00190   // (which is guaranteed by the ArrayColumn get function).
00191   // The default implementation throws an "invalid operation" exception.
00192   virtual void getArrayV (uInt rownr, void* dataPtr);
00193 
00194   // Get the result.
00195   IPosition getResult (uInt rownr, void* dataPtr);
00196 
00197   // Clear the result cache.
00198   void clearCurResult();
00199 
00200 
00201   //# Now define the data members.
00202   int            itsDataType;
00203   Bool           itsIsArray;
00204   String         itsColumnName;
00205   String         itsExpr;             //# TaQL expression
00206   TableExprNode* itsNode;             //# compiled TaQL expression
00207   Bool           itsTempWritable;
00208   Int            itsCurRow;           //# Currently evaluated row
00209   void*          itsCurResult;        //# result in itsCurRow
00210   IPosition      itsCurShape;         //# shape in itsCurRow
00211 };
00212 
00213 
00214 } //end namespace casacore
00215 
00216 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1