casa
$Rev:20696$
|
00001 //# ExprDerNode.h: Nodes representing scalars in table select expression tree 00002 //# Copyright (C) 1994,1995,1996,1997,1999,2000,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: ExprDerNode.h 21298 2012-12-07 14:53:03Z gervandiepen $ 00027 00028 #ifndef TABLES_EXPRDERNODE_H 00029 #define TABLES_EXPRDERNODE_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <tables/Tables/ExprNodeRep.h> 00034 #include <casa/Arrays/Vector.h> 00035 #include <casa/BasicMath/Random.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 //# Forward Declarations 00040 class TableColumn; 00041 class Table; 00042 00043 //# This file defines classes derived from TableExprNode representing 00044 //# the data type and operator in a table expression. 00045 //# 00046 //# Data types Bool, Int64, Double, DComplex and String are used. 00047 //# Char, uChar, Short, uShort, Int, and uInt are converted to Int64, 00048 //# Float to Double, and Complex to DComplex. 00049 //# Binary operators +, -, *, /, ==, >=, >, <, <= and != are recognized. 00050 //# Also &&, ||, parentheses and unary +, - and ! are recognized. 00051 00052 00053 00054 // <summary> 00055 // Constant Bool in table select expression tree 00056 // </summary> 00057 00058 // <use visibility=local> 00059 00060 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00061 // </reviewed> 00062 00063 // <prerequisite> 00064 //# Classes you should understand before using this one. 00065 // <li> TableExprNode 00066 // </prerequisite> 00067 00068 // <synopsis> 00069 // This class represents a constant in a table select expression tree. 00070 // This is also used to hold the value of a table keyword, which is 00071 // constant over the entire table. 00072 // </synopsis> 00073 00074 class TableExprNodeConstBool : public TableExprNodeBinary 00075 { 00076 public: 00077 TableExprNodeConstBool (const Bool& value); 00078 ~TableExprNodeConstBool(); 00079 Bool getBool (const TableExprId& id); 00080 private: 00081 Bool value_p; 00082 }; 00083 00084 00085 // <summary> 00086 // Constant Int64 in table select expression tree 00087 // </summary> 00088 00089 // <use visibility=local> 00090 00091 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00092 // </reviewed> 00093 00094 // <prerequisite> 00095 //# Classes you should understand before using this one. 00096 // <li> TableExprNode 00097 // </prerequisite> 00098 00099 // <synopsis> 00100 // This class represents a constant in a table select expression tree. 00101 // This is also used to hold the value of a table keyword, which is 00102 // constant over the entire table. 00103 // </synopsis> 00104 00105 class TableExprNodeConstInt : public TableExprNodeBinary 00106 { 00107 public: 00108 TableExprNodeConstInt (const Int64& value); 00109 ~TableExprNodeConstInt(); 00110 Int64 getInt (const TableExprId& id); 00111 Double getDouble (const TableExprId& id); 00112 DComplex getDComplex (const TableExprId& id); 00113 private: 00114 Int64 value_p; 00115 }; 00116 00117 00118 // <summary> 00119 // Constant Double in table select expression tree 00120 // </summary> 00121 00122 // <use visibility=local> 00123 00124 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00125 // </reviewed> 00126 00127 // <prerequisite> 00128 //# Classes you should understand before using this one. 00129 // <li> TableExprNode 00130 // </prerequisite> 00131 00132 // <synopsis> 00133 // This class represents a constant in a table select expression tree. 00134 // This is also used to hold the value of a table keyword, which is 00135 // constant over the entire table. 00136 // </synopsis> 00137 00138 class TableExprNodeConstDouble : public TableExprNodeBinary 00139 { 00140 public: 00141 TableExprNodeConstDouble (const Double& value); 00142 ~TableExprNodeConstDouble(); 00143 Double getDouble (const TableExprId& id); 00144 DComplex getDComplex (const TableExprId& id); 00145 private: 00146 Double value_p; 00147 }; 00148 00149 00150 // <summary> 00151 // Constant DComplex in table select expression tree 00152 // </summary> 00153 00154 // <use visibility=local> 00155 00156 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00157 // </reviewed> 00158 00159 // <prerequisite> 00160 //# Classes you should understand before using this one. 00161 // <li> TableExprNode 00162 // </prerequisite> 00163 00164 // <synopsis> 00165 // This class represents a constant in a table select expression tree. 00166 // This is also used to hold the value of a table keyword, which is 00167 // constant over the entire table. 00168 // </synopsis> 00169 00170 class TableExprNodeConstDComplex : public TableExprNodeBinary 00171 { 00172 public: 00173 TableExprNodeConstDComplex (const DComplex& value); 00174 ~TableExprNodeConstDComplex(); 00175 DComplex getDComplex (const TableExprId& id); 00176 private: 00177 DComplex value_p; 00178 }; 00179 00180 00181 // <summary> 00182 // Constant String in table select expression tree 00183 // </summary> 00184 00185 // <use visibility=local> 00186 00187 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00188 // </reviewed> 00189 00190 // <prerequisite> 00191 //# Classes you should understand before using this one. 00192 // <li> TableExprNode 00193 // </prerequisite> 00194 00195 // <synopsis> 00196 // This class represents a constant in a table select expression tree. 00197 // This is also used to hold the value of a table keyword, which is 00198 // constant over the entire table. 00199 // </synopsis> 00200 00201 class TableExprNodeConstString : public TableExprNodeBinary 00202 { 00203 public: 00204 TableExprNodeConstString (const String& value); 00205 ~TableExprNodeConstString(); 00206 String getString (const TableExprId& id); 00207 private: 00208 String value_p; 00209 }; 00210 00211 00212 // <summary> 00213 // Constant Regex or StringDistance in table select expression tree 00214 // </summary> 00215 00216 // <use visibility=local> 00217 00218 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00219 // </reviewed> 00220 00221 // <prerequisite> 00222 //# Classes you should understand before using this one. 00223 // <li> TableExprNode 00224 // </prerequisite> 00225 00226 // <synopsis> 00227 // This class represents a constant in a table select expression tree. 00228 // This is also used to hold the value of a table keyword, which is 00229 // constant over the entire table. 00230 // </synopsis> 00231 00232 class TableExprNodeConstRegex : public TableExprNodeBinary 00233 { 00234 public: 00235 TableExprNodeConstRegex (const TaqlRegex& value); 00236 ~TableExprNodeConstRegex(); 00237 TaqlRegex getRegex (const TableExprId& id); 00238 private: 00239 TaqlRegex value_p; 00240 StringDistance dist_p; 00241 }; 00242 00243 00244 // <summary> 00245 // Constant Date in table select expression tree 00246 // </summary> 00247 00248 // <use visibility=local> 00249 00250 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00251 // </reviewed> 00252 00253 // <prerequisite> 00254 //# Classes you should understand before using this one. 00255 // <li> TableExprNode 00256 // </prerequisite> 00257 00258 // <synopsis> 00259 // This class represents a constant in a table select expression tree. 00260 // This is also used to hold the value of a table keyword, which is 00261 // constant over the entire table. 00262 // </synopsis> 00263 00264 class TableExprNodeConstDate : public TableExprNodeBinary 00265 { 00266 public: 00267 TableExprNodeConstDate (const MVTime& value); 00268 ~TableExprNodeConstDate(); 00269 Double getDouble(const TableExprId& id); 00270 MVTime getDate (const TableExprId& id); 00271 private: 00272 MVTime value_p; 00273 }; 00274 00275 00276 00277 // <summary> 00278 // Scalar column in table select expression tree 00279 // </summary> 00280 00281 // <use visibility=local> 00282 00283 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00284 // </reviewed> 00285 // 00286 // <prerequisite> 00287 //# Classes you should understand before using this one. 00288 // <li> TableExprNode 00289 // </prerequisite> 00290 00291 // <synopsis> 00292 // This class represents a scalar column in a table select expression tree. 00293 // When the select expression gets evaluated, the value of the 00294 // given row in the column is used. 00295 // </synopsis> 00296 00297 00298 class TableExprNodeColumn : public TableExprNodeBinary 00299 { 00300 public: 00301 TableExprNodeColumn (const Table&, const String& columnName); 00302 ~TableExprNodeColumn(); 00303 00304 Bool getBool (const TableExprId& id); 00305 Int64 getInt (const TableExprId& id); 00306 Double getDouble (const TableExprId& id); 00307 DComplex getDComplex (const TableExprId& id); 00308 String getString (const TableExprId& id); 00309 const TableColumn& getColumn() const; 00310 00311 // Get the data type of this scalar column. 00312 Bool getColumnDataType (DataType&) const; 00313 00314 Array<Bool> getColumnBool (const Vector<uInt>& rownrs); 00315 Array<uChar> getColumnuChar (const Vector<uInt>& rownrs); 00316 Array<Short> getColumnShort (const Vector<uInt>& rownrs); 00317 Array<uShort> getColumnuShort (const Vector<uInt>& rownrs); 00318 Array<Int> getColumnInt (const Vector<uInt>& rownrs); 00319 Array<uInt> getColumnuInt (const Vector<uInt>& rownrs); 00320 Array<Float> getColumnFloat (const Vector<uInt>& rownrs); 00321 Array<Double> getColumnDouble (const Vector<uInt>& rownrs); 00322 Array<Complex> getColumnComplex (const Vector<uInt>& rownrs); 00323 Array<DComplex> getColumnDComplex (const Vector<uInt>& rownrs); 00324 Array<String> getColumnString (const Vector<uInt>& rownrs); 00325 00326 // Get the column unit (can be empty). 00327 static Unit getColumnUnit (const TableColumn&); 00328 00329 protected: 00330 TableColumn* tabColPtr_p; //# pointer to table column 00331 }; 00332 00333 00334 00335 // <summary> 00336 // Rownumber in table select expression tree 00337 // </summary> 00338 00339 // <use visibility=local> 00340 00341 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00342 // </reviewed> 00343 00344 // <prerequisite> 00345 //# Classes you should understand before using this one. 00346 // <li> TableExprNode 00347 // </prerequisite> 00348 00349 // <synopsis> 00350 // This class represents the rownumber() function in a table 00351 // select expression tree. 00352 // The origin is stored to indicate whether the first rownumber 00353 // should be zero (in C++) or an other value (1 in TaQL) 00354 // </synopsis> 00355 00356 class TableExprNodeRownr : public TableExprNodeBinary 00357 { 00358 public: 00359 TableExprNodeRownr (const Table&, uInt origin); 00360 ~TableExprNodeRownr(); 00361 Int64 getInt (const TableExprId& id); 00362 private: 00363 uInt origin_p; 00364 }; 00365 00366 00367 00368 // <summary> 00369 // Rowid in table select expression tree 00370 // </summary> 00371 00372 // <use visibility=local> 00373 00374 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00375 // </reviewed> 00376 00377 // <prerequisite> 00378 //# Classes you should understand before using this one. 00379 // <li> TableExprNode 00380 // </prerequisite> 00381 00382 // <synopsis> 00383 // This class represents the rowid() function in a table 00384 // select expression tree. 00385 // It is meant to get the original row number in a GIVING clause, 00386 // but, of course, it can also be used in the SELECT clause. 00387 // The row number returned is 0-based. 00388 // </synopsis> 00389 00390 class TableExprNodeRowid : public TableExprNodeBinary 00391 { 00392 public: 00393 TableExprNodeRowid (const Table&); 00394 ~TableExprNodeRowid(); 00395 Int64 getInt (const TableExprId& id); 00396 private: 00397 Vector<uInt> rownrs_p; 00398 }; 00399 00400 00401 00402 // <summary> 00403 // Random number in table select expression tree 00404 // </summary> 00405 00406 // <use visibility=local> 00407 00408 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00409 // </reviewed> 00410 00411 // <prerequisite> 00412 //# Classes you should understand before using this one. 00413 // <li> TableExprNode 00414 // </prerequisite> 00415 00416 // <synopsis> 00417 // This class represents the rand() function in a table 00418 // select expression tree. 00419 // </synopsis> 00420 00421 class TableExprNodeRandom : public TableExprNodeBinary 00422 { 00423 public: 00424 TableExprNodeRandom (const Table&); 00425 ~TableExprNodeRandom(); 00426 Double getDouble (const TableExprId& id); 00427 private: 00428 MLCG generator_p; 00429 Uniform random_p; 00430 }; 00431 00432 00433 00434 } //# NAMESPACE CASA - END 00435 00436 #endif