[2458] | 1 | #ifndef ASAPACCELERATOR_H
|
---|
| 2 | #define ASAPACCELERATOR_H
|
---|
| 3 | //
|
---|
| 4 | // C++ Interface: CustomTableExprNode
|
---|
| 5 | //
|
---|
| 6 | // Description:
|
---|
| 7 | // Various utilities for speed.
|
---|
| 8 | //
|
---|
| 9 | // Author: Kohji Nakamura <k.nakamura@nao.ac.jp>, (C) 2012
|
---|
| 10 | //
|
---|
| 11 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 12 | //
|
---|
| 13 | //
|
---|
| 14 |
|
---|
[2470] | 15 | #include <casa/Utilities/Assert.h>
|
---|
[3084] | 16 | #include <tables/TaQL/ExprNode.h>
|
---|
[2458] | 17 | #include <tables/Tables/ScalarColumn.h>
|
---|
| 18 |
|
---|
| 19 | namespace asap {
|
---|
| 20 |
|
---|
[3106] | 21 | using namespace casacore;
|
---|
[2458] | 22 |
|
---|
[2470] | 23 | class TableExprPredicate {
|
---|
| 24 | public:
|
---|
| 25 | virtual ~TableExprPredicate() {}
|
---|
| 26 | virtual Bool match(Table const& table, const TableExprId& id) = 0;
|
---|
| 27 | };
|
---|
| 28 |
|
---|
[2458] | 29 | class CustomTableExprNodeRep :public TableExprNodeRep {
|
---|
[2470] | 30 | TableExprPredicate & pred_;
|
---|
[2458] | 31 | public:
|
---|
[2470] | 32 | CustomTableExprNodeRep(const Table &table,
|
---|
| 33 | TableExprPredicate & pred)
|
---|
[2458] | 34 | :TableExprNodeRep(TableExprNodeRep::NTBool,
|
---|
| 35 | TableExprNodeRep::VTScalar,
|
---|
| 36 | TableExprNodeRep::OtUndef,
|
---|
[2470] | 37 | table),
|
---|
| 38 | pred_(pred) {}
|
---|
| 39 | virtual ~CustomTableExprNodeRep() {}
|
---|
| 40 | virtual Bool getBool(const TableExprId& id) {
|
---|
| 41 | return pred_.match(table(), id);
|
---|
| 42 | }
|
---|
[2458] | 43 | };
|
---|
| 44 |
|
---|
| 45 | class CustomTableExprNode: public TableExprNode {
|
---|
| 46 | public:
|
---|
[2470] | 47 | CustomTableExprNode(CustomTableExprNodeRep &nodeRep)
|
---|
| 48 | : TableExprNode(&nodeRep) {
|
---|
[2458] | 49 | }
|
---|
| 50 | virtual ~CustomTableExprNode() {
|
---|
| 51 | }
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | template<typename T, size_t N>
|
---|
| 55 | class SingleTypeEqPredicate: public TableExprPredicate {
|
---|
| 56 | Table const & table;
|
---|
| 57 | ROScalarColumn<T> *cols[N];
|
---|
| 58 | T const *values;
|
---|
| 59 | public:
|
---|
| 60 | SingleTypeEqPredicate(Table const &table_,
|
---|
| 61 | char const*const colNames[],
|
---|
| 62 | T const values_[]):
|
---|
| 63 | table(table_), values(values_) {
|
---|
| 64 | for (size_t i = 0; i < N; i++) {
|
---|
| 65 | cols[i] = new ROScalarColumn<T>(table, colNames[i]);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | virtual ~SingleTypeEqPredicate() {
|
---|
| 69 | for (size_t i = 0; i < N; i++) {
|
---|
| 70 | delete cols[i];
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
[2470] | 73 | virtual Bool match(Table const& table, const TableExprId& id) {
|
---|
| 74 | DebugAssert(&table == &this->table, AipsError);
|
---|
[3069] | 75 | (void)table;
|
---|
[2458] | 76 | for (size_t i = 0; i < N; i++) {
|
---|
| 77 | T v;
|
---|
| 78 | cols[i]->get(id.rownr(), v);
|
---|
| 79 | if (v != values[i]) {
|
---|
| 80 | return false;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | } // asap
|
---|
| 88 |
|
---|
| 89 | #endif // ASAPACCELERATOR_H
|
---|