00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TABLES_EXPRNODEREP_H
00029 #define TABLES_EXPRNODEREP_H
00030
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/Tables/Table.h>
00034 #include <casacore/tables/TaQL/TableExprId.h>
00035 #include <casacore/tables/TaQL/ExprRange.h>
00036 #include <casacore/tables/TaQL/MArray.h>
00037 #include <casacore/casa/BasicSL/Complex.h>
00038 #include <casacore/casa/Quanta/MVTime.h>
00039 #include <casacore/casa/Quanta/Unit.h>
00040 #include <casacore/casa/Utilities/DataType.h>
00041 #include <casacore/casa/Utilities/Regex.h>
00042 #include <casacore/casa/Utilities/StringDistance.h>
00043 #include <casacore/casa/iosfwd.h>
00044
00045 namespace casacore {
00046
00047
00048 class TableExprNode;
00049 class TableExprNodeColumn;
00050 class TableExprGroupFuncBase;
00051 template<class T> class Block;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 class TaqlRegex
00076 {
00077 public:
00078
00079 explicit TaqlRegex (const Regex& regex)
00080 : itsRegex(regex)
00081 {}
00082
00083
00084 explicit TaqlRegex (const StringDistance& dist)
00085 : itsDist(dist)
00086 {}
00087
00088
00089 Bool match (const String& str) const
00090 { return itsRegex.regexp().empty() ?
00091 itsDist.match(str) : str.matches(itsRegex);
00092 }
00093
00094
00095 const Regex& regex() const
00096 { return itsRegex; }
00097
00098 private:
00099 Regex itsRegex;
00100 StringDistance itsDist;
00101 };
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 class TableExprNodeRep
00152 {
00153 public:
00154
00155 enum NodeDataType {
00156 NTBool,
00157 NTInt,
00158 NTDouble,
00159 NTComplex,
00160 NTString,
00161 NTRegex,
00162 NTDate,
00163 NTReal,
00164 NTDouCom,
00165 NTNumeric,
00166 NTAny
00167 };
00168
00169
00170 enum ValueType {
00171 VTScalar,
00172 VTArray,
00173 VTRecord,
00174 VTSetElem,
00175 VTSet,
00176 VTIndex
00177 };
00178
00179
00180
00181 enum OperType {OtPlus, OtMinus, OtTimes, OtDivide, OtModulo,
00182 OtBitAnd, OtBitOr, OtBitXor, OtBitNegate,
00183 OtEQ, OtGE, OtGT, OtNE, OtIN,
00184 OtAND, OtOR, OtNOT, OtMIN,
00185 OtColumn, OtField, OtLiteral, OtFunc, OtSlice, OtUndef,
00186 OtRownr, OtRandom
00187 };
00188
00189
00190 enum ArgType {
00191 NoArr, ArrArr, ArrSca, ScaArr
00192 };
00193
00194
00195 enum ExprType {
00196
00197 Constant,
00198
00199
00200 Variable
00201
00202
00203
00204 };
00205
00206
00207 TableExprNodeRep (NodeDataType, ValueType, OperType, ArgType, ExprType,
00208 Int ndim, const IPosition& shape,
00209 const Table& table);
00210
00211
00212 TableExprNodeRep (NodeDataType, ValueType, OperType, const Table&);
00213
00214
00215 TableExprNodeRep (const TableExprNodeRep&);
00216
00217
00218 virtual ~TableExprNodeRep();
00219
00220
00221 TableExprNodeRep* link();
00222
00223
00224
00225 static void unlink (TableExprNodeRep*);
00226
00227
00228 virtual void disableApplySelection();
00229
00230
00231
00232 virtual void applySelection (const Vector<uInt>& rownrs);
00233
00234
00235
00236 virtual Double getUnitFactor() const;
00237
00238
00239
00240 static void checkAggrFuncs (const TableExprNodeRep* node);
00241
00242
00243 virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00244
00245
00246 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00247
00248
00249
00250
00251 virtual CountedPtr<TableExprGroupFuncBase> makeGroupAggrFunc();
00252
00253
00254
00255
00256 virtual Bool isLazyAggregate() const;
00257
00258
00259
00260
00261
00262
00263 virtual Bool getBool (const TableExprId& id);
00264 virtual Int64 getInt (const TableExprId& id);
00265 virtual Double getDouble (const TableExprId& id);
00266 virtual DComplex getDComplex (const TableExprId& id);
00267 virtual String getString (const TableExprId& id);
00268 virtual TaqlRegex getRegex (const TableExprId& id);
00269 virtual MVTime getDate (const TableExprId& id);
00270
00271
00272
00273
00274
00275
00276
00277 virtual MArray<Bool> getArrayBool (const TableExprId& id);
00278 virtual MArray<Int64> getArrayInt (const TableExprId& id);
00279 virtual MArray<Double> getArrayDouble (const TableExprId& id);
00280 virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
00281 virtual MArray<String> getArrayString (const TableExprId& id);
00282 virtual MArray<MVTime> getArrayDate (const TableExprId& id);
00283
00284
00285
00286
00287 void get (const TableExprId& id, Bool& value)
00288 { value = getBool (id); }
00289 void get (const TableExprId& id, Int64& value)
00290 { value = getInt (id); }
00291 void get (const TableExprId& id, Double& value)
00292 { value = getDouble (id); }
00293 void get (const TableExprId& id, DComplex& value)
00294 { value = getDComplex (id); }
00295 void get (const TableExprId& id, MVTime& value)
00296 { value = getDate (id); }
00297 void get (const TableExprId& id, String& value)
00298 { value = getString (id); }
00299 void get (const TableExprId& id, MArray<Bool>& value)
00300 { value = getArrayBool (id); }
00301 void get (const TableExprId& id, MArray<Int64>& value)
00302 { value = getArrayInt (id); }
00303 void get (const TableExprId& id, MArray<Double>& value)
00304 { value = getArrayDouble (id); }
00305 void get (const TableExprId& id, MArray<DComplex>& value)
00306 { value = getArrayDComplex (id); }
00307 void get (const TableExprId& id, MArray<MVTime>& value)
00308 { value = getArrayDate (id); }
00309 void get (const TableExprId& id, MArray<String>& value)
00310 { value = getArrayString (id); }
00311
00312
00313
00314
00315
00316 MArray<Bool> getBoolAS (const TableExprId& id);
00317 MArray<Int64> getIntAS (const TableExprId& id);
00318 MArray<Double> getDoubleAS (const TableExprId& id);
00319 MArray<DComplex> getDComplexAS (const TableExprId& id);
00320 MArray<String> getStringAS (const TableExprId& id);
00321 MArray<MVTime> getDateAS (const TableExprId& id);
00322
00323
00324
00325
00326
00327 virtual Bool hasBool (const TableExprId& id, Bool value);
00328 virtual Bool hasInt (const TableExprId& id, Int64 value);
00329 virtual Bool hasDouble (const TableExprId& id, Double value);
00330 virtual Bool hasDComplex (const TableExprId& id, const DComplex& value);
00331 virtual Bool hasString (const TableExprId& id, const String& value);
00332 virtual Bool hasDate (const TableExprId& id, const MVTime& value);
00333 virtual MArray<Bool> hasArrayBool (const TableExprId& id,
00334 const MArray<Bool>& value);
00335 virtual MArray<Bool> hasArrayInt (const TableExprId& id,
00336 const MArray<Int64>& value);
00337 virtual MArray<Bool> hasArrayDouble (const TableExprId& id,
00338 const MArray<Double>& value);
00339 virtual MArray<Bool> hasArrayDComplex (const TableExprId& id,
00340 const MArray<DComplex>& value);
00341 virtual MArray<Bool> hasArrayString (const TableExprId& id,
00342 const MArray<String>& value);
00343 virtual MArray<Bool> hasArrayDate (const TableExprId& id,
00344 const MArray<MVTime>& value);
00345
00346
00347
00348
00349
00350 uInt nrow() const;
00351
00352
00353
00354
00355
00356 virtual Bool getColumnDataType (DataType&) const;
00357
00358
00359
00360
00361
00362 virtual Array<Bool> getColumnBool (const Vector<uInt>& rownrs);
00363 virtual Array<uChar> getColumnuChar (const Vector<uInt>& rownrs);
00364 virtual Array<Short> getColumnShort (const Vector<uInt>& rownrs);
00365 virtual Array<uShort> getColumnuShort (const Vector<uInt>& rownrs);
00366 virtual Array<Int> getColumnInt (const Vector<uInt>& rownrs);
00367 virtual Array<uInt> getColumnuInt (const Vector<uInt>& rownrs);
00368 virtual Array<Float> getColumnFloat (const Vector<uInt>& rownrs);
00369 virtual Array<Double> getColumnDouble (const Vector<uInt>& rownrs);
00370 virtual Array<Complex> getColumnComplex (const Vector<uInt>& rownrs);
00371 virtual Array<DComplex> getColumnDComplex (const Vector<uInt>& rownrs);
00372 virtual Array<String> getColumnString (const Vector<uInt>& rownrs);
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 virtual void ranges (Block<TableExprRange>&);
00385
00386
00387
00388
00389
00390
00391
00392 NodeDataType dataType() const;
00393
00394
00395 Bool isReal() const;
00396
00397
00398 ValueType valueType() const;
00399
00400
00401 void setValueType (ValueType vtype);
00402
00403
00404 OperType operType() const;
00405
00406
00407 ExprType exprType() const;
00408
00409
00410 Bool isConstant() const;
00411
00412
00413 const Unit& unit() const;
00414
00415
00416
00417 void setUnit (const Unit& unit);
00418
00419
00420 Int ndim() const;
00421
00422
00423 const IPosition& shape() const;
00424
00425
00426
00427 const IPosition& shape (const TableExprId& id);
00428
00429
00430
00431 virtual Bool isDefined (const TableExprId& id);
00432
00433
00434 virtual void show (ostream&, uInt indent) const;
00435
00436
00437
00438
00439
00440 Table& table();
00441 const Table& table() const;
00442
00443
00444
00445
00446 virtual void adaptSetUnits (const Unit&);
00447
00448
00449 static void createRange (Block<TableExprRange>&,
00450 TableExprNodeColumn*, Double start, Double end);
00451
00452
00453 static void createRange (Block<TableExprRange>&);
00454
00455
00456 static String typeString (NodeDataType);
00457
00458
00459 static String typeString (ValueType);
00460
00461 protected:
00462 uInt count_p;
00463 Table table_p;
00464 NodeDataType dtype_p;
00465 ValueType vtype_p;
00466 OperType optype_p;
00467 ArgType argtype_p;
00468 ExprType exprtype_p;
00469 Int ndim_p;
00470
00471 IPosition shape_p;
00472 Unit unit_p;
00473
00474
00475 virtual const IPosition& getShape (const TableExprId& id);
00476
00477
00478
00479 static TableExprNodeRep* getRep (TableExprNode&);
00480
00481
00482
00483
00484
00485 virtual void convertConstChild();
00486
00487
00488
00489
00490 void checkTablePtr (const TableExprNodeRep* node);
00491 static void checkTablePtr (Table& table,
00492 const TableExprNodeRep* node);
00493
00494
00495
00496
00497 void fillExprType (const TableExprNodeRep* node);
00498 static void fillExprType (ExprType&, const TableExprNodeRep* node);
00499
00500
00501
00502
00503
00504
00505 static TableExprNodeRep* convertNode (TableExprNodeRep* thisNode,
00506 Bool convertConstType);
00507
00508 private:
00509
00510 TableExprNodeRep& operator= (const TableExprNodeRep&);
00511 };
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553 class TableExprNodeBinary : public TableExprNodeRep
00554 {
00555 public:
00556
00557 TableExprNodeBinary (NodeDataType, ValueType, OperType, const Table&);
00558 TableExprNodeBinary (NodeDataType, const TableExprNodeRep&, OperType);
00559
00560
00561 virtual ~TableExprNodeBinary();
00562
00563
00564 virtual void show (ostream&, uInt indent) const;
00565
00566
00567 virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00568
00569
00570 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00571
00572
00573 static NodeDataType getDT (NodeDataType leftDtype,
00574 NodeDataType rightDype,
00575 OperType operType);
00576
00577
00578 static TableExprNodeRep getTypes (const TableExprNodeRep& left,
00579 const TableExprNodeRep& right,
00580 OperType operType);
00581
00582
00583
00584
00585
00586 static TableExprNodeRep* fillNode (TableExprNodeBinary* thisNode,
00587 TableExprNodeRep* left,
00588 TableExprNodeRep* right,
00589 Bool convertConstType,
00590 Bool adaptDataType=True);
00591
00592
00593
00594
00595 virtual void handleUnits();
00596
00597
00598
00599
00600 void convertConstChild();
00601
00602
00603
00604 const TableExprNodeRep* getLeftChild() const
00605 { return lnode_p; }
00606 const TableExprNodeRep* getRightChild() const
00607 { return rnode_p; }
00608
00609
00610 protected:
00611
00612
00613 static const Unit& makeEqualUnits (TableExprNodeRep* left,
00614 TableExprNodeRep*& right);
00615
00616 TableExprNodeRep* lnode_p;
00617 TableExprNodeRep* rnode_p;
00618 };
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 class TableExprNodeMulti : public TableExprNodeRep
00661 {
00662 public:
00663
00664 TableExprNodeMulti (NodeDataType, ValueType, OperType,
00665 const TableExprNodeRep& source);
00666
00667
00668 virtual ~TableExprNodeMulti();
00669
00670
00671 virtual void show (ostream&, uInt indent) const;
00672
00673
00674 virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00675
00676
00677 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
00678
00679
00680
00681
00682 static uInt checkNumOfArg (uInt low, uInt high,
00683 const PtrBlock<TableExprNodeRep*>& nodes);
00684
00685
00686 const PtrBlock<TableExprNodeRep*>& getChildren() const
00687 { return operands_p; }
00688
00689
00690
00691 static NodeDataType checkDT (Block<Int>& dtypeOper,
00692 NodeDataType dtIn, NodeDataType dtOut,
00693 const PtrBlock<TableExprNodeRep*>& nodes);
00694
00695 protected:
00696 PtrBlock<TableExprNodeRep*> operands_p;
00697 };
00698
00699
00700
00701
00702 inline TableExprNodeRep::NodeDataType TableExprNodeRep::dataType() const
00703 { return dtype_p; }
00704
00705 inline Bool TableExprNodeRep::isReal() const
00706 { return dtype_p==NTInt || dtype_p==NTDouble; }
00707
00708
00709 inline TableExprNodeRep::ValueType TableExprNodeRep::valueType() const
00710 { return vtype_p; }
00711
00712
00713 inline void TableExprNodeRep::setValueType (TableExprNodeRep::ValueType vtype)
00714 { vtype_p = vtype; }
00715
00716
00717 inline TableExprNodeRep::OperType TableExprNodeRep::operType() const
00718 { return optype_p; }
00719
00720
00721 inline TableExprNodeRep::ExprType TableExprNodeRep::exprType() const
00722 { return exprtype_p; }
00723
00724
00725 inline Bool TableExprNodeRep::isConstant() const
00726 { return (exprtype_p == Constant); }
00727
00728
00729 inline const Unit& TableExprNodeRep::unit() const
00730 { return unit_p; }
00731
00732
00733 inline Int TableExprNodeRep::ndim() const
00734 { return ndim_p; }
00735
00736
00737 inline const IPosition& TableExprNodeRep::shape() const
00738 { return shape_p; }
00739
00740
00741 inline Table& TableExprNodeRep::table()
00742 { return table_p; }
00743 inline const Table& TableExprNodeRep::table() const
00744 { return table_p; }
00745
00746 inline void TableExprNodeRep::checkTablePtr (const TableExprNodeRep* node)
00747 { checkTablePtr (table_p, node); }
00748 inline void TableExprNodeRep::fillExprType (const TableExprNodeRep* node)
00749 { fillExprType (exprtype_p, node); }
00750
00751
00752 inline TableExprNodeRep* TableExprNodeRep::link()
00753 {
00754 count_p++;
00755 return this;
00756 }
00757
00758
00759 }
00760
00761 #endif