casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VirtualTaQLColumn.h
Go to the documentation of this file.
1 //# VirtualTaQLColumn.h: Virtual column engine based on TaQL
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TABLES_VIRTUALTAQLCOLUMN_H
29 #define TABLES_VIRTUALTAQLCOLUMN_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
36 
37 namespace casacore {
38 //# Forward Declarations
39 class TableExprNode;
40 
41 
42 // <category lib=aips module="Tables" sect="Virtual Columns">
43 // <summary> Virtual scalar column using TaQL</summary>
44 // <reviewed reviewer="GvD" date="2004/07/09" tests="">
45 //
46 // <prerequisite>
47 //# Classes you should understand before using this one.
48 // <li> VirtualScalarColumn
49 // </prerequisite>
50 //
51 // <synopsis>
52 // VirtualTaQLColumn is a virtual column engine to define the contents of a
53 // column as a TaQL expression in which possibly other columns are used.
54 // It is (of course) only possible to get data from the column; puts cannot
55 // be done.
56 // <br>
57 // The expression result can be a scalar or array of the basic TaQL data types.
58 // The column data type has to be conformant with that TaQL type, thus a
59 // column of any integer type has to be used for an integer TaQL result.
60 // <note role=caution> One has to be careful with deleting columns. If in an
61 // existing table a TaQL expression uses a deleted column, the expression
62 // cannot be parsed anymore and the table cannot be opened anymore.
63 // In the future the Table System will be made more forgiving.
64 // </note>
65 // </synopsis>
66 //
67 // <example>
68 // The following example creates a table with a few columns.
69 // One column is virtual and has a random value if Col3 is true.
70 // Otherwise it has value 0.
71 // <srcblock>
72 // // Create the table description.
73 // TableDesc td;
74 // td.addColumn (ScalarColumnDesc<DComplex>("Col1"));
75 // td.addColumn (ScalarColumnDesc<Int>("Col2"));
76 // td.addColumn (ScalarColumnDesc<Bool>("Col3"));
77 // td.addColumn (ScalarColumnDesc<Double>("ColVirt"));
78 //
79 // // Now create a new table from the description.
80 // SetupNewTable newTab("tmtest", td, Table::New);
81 // // Define the expression of the virtual column and bind the column to it.
82 // // The other columns are by default bound to StandardStMan.
83 // VirtualTaQLColumn engine("iif(Col3,rand(),0)");
84 // newTab.bindColumn("ColVirt", engine);
85 // Table tab(newTab);
86 // </srcblock>
87 // </example>
88 
90 {
91 public:
92 
93  // Construct it with the given TaQL expression.
94  VirtualTaQLColumn (const String& expr);
95 
96  // Construct it with the given specification.
97  VirtualTaQLColumn (const Record& spec);
98 
99  // Destructor is mandatory.
100  virtual ~VirtualTaQLColumn();
101 
102  // Clone the engine object.
103  virtual DataManager* clone() const;
104 
105  // Get the data manager specification.
106  virtual Record dataManagerSpec() const;
107 
108  // Return the type name of the engine.
109  // (i.e. its class name VirtualTaQLColumn).
110  virtual String dataManagerType() const;
111 
112  // Return the name of the class.
113  static String className();
114 
115  // Register the class name and the static makeObject "constructor".
116  // This will make the engine known to the table system.
117  static void registerClass();
118 
119  // Define the "constructor" to construct this engine when a
120  // table is read back.
121  // This "constructor" has to be registered by the user of the engine.
122  // If the engine is commonly used, its registration can be added
123  // into the registerAllCtor function in DataManReg.cc.
124  // This function gets automatically invoked by the table system.
126  const Record& spec);
127 
128  // Return the TaQL expression used.
129  const String& expression() const
130  { return itsExpr; }
131 
132  // Functions to return column info.
133  // <group>
134  virtual int dataType() const;
135  virtual Bool isWritable() const;
136  virtual uInt ndim (uInt rownr);
137  virtual IPosition shape (uInt rownr);
138  virtual Bool isShapeDefined (uInt rownr);
139  // </group>
140 
141 private:
142  // Copy is not needed and therefore forbidden (so it is made private).
144 
145  // Assignment is not needed and therefore forbidden (so it is made private).
147 
148  // Create the column object for the scalar column in this engine.
150  int dataType, const String&);
151 
152  // Create the column object for the indirect array column in this engine.
154  int dataType,
155  const String& dataTypeId);
156 
157  // Let the engine initialize the object for a new table.
158  // It defines a column keyword holding the expression.
159  virtual void create (uInt);
160 
161  // Prepare compiles the expression.
162  virtual void prepare();
163 
164  //# We could also define the getBlockXXV functions, but
165  //# that is not required. The default implementation gets
166  //# one value. Possible optimization can be done by
167  //# implementing it here.
168  //# The same is true for getColumn.
169 
170  // Get the scalar value in the given row.
171  // The default implementation throws an "invalid operation" exception.
172  // <group>
173  virtual void getBoolV (uInt rownr, Bool* dataPtr);
174  virtual void getuCharV (uInt rownr, uChar* dataPtr);
175  virtual void getShortV (uInt rownr, Short* dataPtr);
176  virtual void getuShortV (uInt rownr, uShort* dataPtr);
177  virtual void getIntV (uInt rownr, Int* dataPtr);
178  virtual void getuIntV (uInt rownr, uInt* dataPtr);
179  virtual void getInt64V (uInt rownr, Int64* dataPtr);
180  virtual void getfloatV (uInt rownr, float* dataPtr);
181  virtual void getdoubleV (uInt rownr, double* dataPtr);
182  virtual void getComplexV (uInt rownr, Complex* dataPtr);
183  virtual void getDComplexV (uInt rownr, DComplex* dataPtr);
184  virtual void getStringV (uInt rownr, String* dataPtr);
185  // </group>
186 
187  // Get the array value in the given row.
188  // The argument dataPtr is in fact an Array<T>*, but a void*
189  // is needed to be generic.
190  // The array pointed to by dataPtr has to have the correct shape
191  // (which is guaranteed by the ArrayColumn get function).
192  // The default implementation throws an "invalid operation" exception.
193  virtual void getArrayV (uInt rownr, void* dataPtr);
194 
195  // Get the array result into itsCurResult.
196  IPosition getResult (uInt rownr);
197 
198  // Make the result cache.
199  void makeCurResult();
200 
201  // Clear the result cache.
202  void clearCurResult();
203 
204 
205  //# Now define the data members.
209  String itsExpr; //# TaQL expression
210  TableExprNode* itsNode; //# compiled TaQL expression
212  Int itsCurRow; //# Currently evaluated row
213  void* itsCurResult; //# result in itsCurRow
214  IPosition itsCurShape; //# shape in itsCurRow
215 };
216 
217 
218 } //end namespace casacore
219 
220 #endif
void makeCurResult()
Make the result cache.
virtual void getBoolV(uInt rownr, Bool *dataPtr)
Get the scalar value in the given row.
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
virtual void getComplexV(uInt rownr, Complex *dataPtr)
Abstract base class for virtual column handling.
Definition: VirtColEng.h:111
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
virtual void create(uInt)
Let the engine initialize the object for a new table.
virtual DataManagerColumn * makeIndArrColumn(const String &columnName, int dataType, const String &dataTypeId)
Create the column object for the indirect array column in this engine.
virtual void getShortV(uInt rownr, Short *dataPtr)
const String & columnName() const
Get rhe column name.
Definition: DataManager.h:1003
Abstract base class for a column in a data manager.
Definition: DataManager.h:611
Handle class for a table column expression tree.
Definition: ExprNode.h:155
unsigned char uChar
Definition: aipstype.h:47
virtual String dataManagerType() const
Return the type name of the engine.
virtual void getArrayV(uInt rownr, void *dataPtr)
Get the array value in the given row.
IPosition getResult(uInt rownr)
Get the array result into itsCurResult.
virtual IPosition shape(uInt rownr)
Get the shape of the item in the given row.
virtual void getIntV(uInt rownr, Int *dataPtr)
VirtualTaQLColumn & operator=(const VirtualTaQLColumn &)
Assignment is not needed and therefore forbidden (so it is made private).
virtual String dataManagerName() const
Return the name of the data manager.
const String & expression() const
Return the TaQL expression used.
VirtualTaQLColumn(const String &expr)
Construct it with the given TaQL expression.
short Short
Definition: aipstype.h:48
virtual void getuCharV(uInt rownr, uChar *dataPtr)
virtual Bool isShapeDefined(uInt rownr)
Is the value shape defined in the given row? By default it returns True.
Virtual scalar column using TaQL.
static void registerClass()
Register the class name and the static makeObject &quot;constructor&quot;.
virtual void getuShortV(uInt rownr, uShort *dataPtr)
virtual void getStringV(uInt rownr, String *dataPtr)
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void getfloatV(uInt rownr, float *dataPtr)
virtual Bool isWritable() const
Test if data can be put into this column.
virtual void getuIntV(uInt rownr, uInt *dataPtr)
virtual int dataType() const
Functions to return column info.
virtual Record dataManagerSpec() const
Get the data manager specification.
virtual void getdoubleV(uInt rownr, double *dataPtr)
virtual ~VirtualTaQLColumn()
Destructor is mandatory.
virtual uInt ndim(uInt rownr)
Get the dimensionality of the item in the given row.
Abstract base class for a data manager.
Definition: DataManager.h:224
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void clearCurResult()
Clear the result cache.
virtual void prepare()
Prepare compiles the expression.
virtual void getDComplexV(uInt rownr, DComplex *dataPtr)
virtual DataManager * clone() const
Clone the engine object.
virtual DataManagerColumn * makeScalarColumn(const String &columnName, int dataType, const String &)
Create the column object for the scalar column in this engine.
static String className()
Return the name of the class.
unsigned int uInt
Definition: aipstype.h:51
virtual void getInt64V(uInt rownr, Int64 *dataPtr)
virtual String dataTypeId() const
Get the data type id of the column for dataType==TpOther.
unsigned short uShort
Definition: aipstype.h:49
static DataManager * makeObject(const String &dataManagerName, const Record &spec)
Define the &quot;constructor&quot; to construct this engine when a table is read back.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42