| 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 |
|
|---|
| 15 | #include <tables/Tables/ExprNode.h>
|
|---|
| 16 | #include <tables/Tables/ScalarColumn.h>
|
|---|
| 17 |
|
|---|
| 18 | namespace asap {
|
|---|
| 19 |
|
|---|
| 20 | using namespace casa;
|
|---|
| 21 |
|
|---|
| 22 | class CustomTableExprNodeRep :public TableExprNodeRep {
|
|---|
| 23 | public:
|
|---|
| 24 | CustomTableExprNodeRep(const Table &table)
|
|---|
| 25 | :TableExprNodeRep(TableExprNodeRep::NTBool,
|
|---|
| 26 | TableExprNodeRep::VTScalar,
|
|---|
| 27 | TableExprNodeRep::OtUndef,
|
|---|
| 28 | table) {}
|
|---|
| 29 | };
|
|---|
| 30 |
|
|---|
| 31 | class TableExprPredicate {
|
|---|
| 32 | public:
|
|---|
| 33 | virtual ~TableExprPredicate() {}
|
|---|
| 34 | virtual Bool match(Table const& table, const TableExprId& id) const = 0;
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | class CustomTableExprNode: public TableExprNode {
|
|---|
| 38 | CustomTableExprNodeRep const nodeRep;
|
|---|
| 39 | TableExprPredicate const & pred_;
|
|---|
| 40 | public:
|
|---|
| 41 | CustomTableExprNode(Table const &table, TableExprPredicate const &pred)
|
|---|
| 42 | : TableExprNode(), nodeRep(table), pred_(pred) {
|
|---|
| 43 | }
|
|---|
| 44 | virtual ~CustomTableExprNode() {
|
|---|
| 45 | }
|
|---|
| 46 | const TableExprNodeRep* getNodeRep() const {
|
|---|
| 47 | return &nodeRep;
|
|---|
| 48 | }
|
|---|
| 49 | void get(const TableExprId& id, Bool& value) const {
|
|---|
| 50 | value = pred_.match(nodeRep.table(), id);
|
|---|
| 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 | }
|
|---|
| 73 | virtual Bool match(Table const& table, const TableExprId& id) const {
|
|---|
| 74 | for (size_t i = 0; i < N; i++) {
|
|---|
| 75 | T v;
|
|---|
| 76 | cols[i]->get(id.rownr(), v);
|
|---|
| 77 | if (v != values[i]) {
|
|---|
| 78 | return false;
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | return true;
|
|---|
| 82 | }
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 | } // asap
|
|---|
| 86 |
|
|---|
| 87 | #endif // ASAPACCELERATOR_H
|
|---|