source: branches/hpc34/src/Accelerator.h@ 3020

Last change on this file since 3020 was 2580, checked in by ShinnosukeKawakami, 12 years ago

hpc33 merged asap-trunk

File size: 1.9 KB
Line 
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 <casa/Utilities/Assert.h>
16#include <tables/Tables/ExprNode.h>
17#include <tables/Tables/ScalarColumn.h>
18
19namespace asap {
20
21using namespace casa;
22
23class TableExprPredicate {
24public:
25 virtual ~TableExprPredicate() {}
26 virtual Bool match(Table const& table, const TableExprId& id) = 0;
27};
28
29class CustomTableExprNodeRep :public TableExprNodeRep {
30 TableExprPredicate & pred_;
31public:
32 CustomTableExprNodeRep(const Table &table,
33 TableExprPredicate & pred)
34 :TableExprNodeRep(TableExprNodeRep::NTBool,
35 TableExprNodeRep::VTScalar,
36 TableExprNodeRep::OtUndef,
37 table),
38 pred_(pred) {}
39 virtual ~CustomTableExprNodeRep() {}
40 virtual Bool getBool(const TableExprId& id) {
41 return pred_.match(table(), id);
42 }
43};
44
45class CustomTableExprNode: public TableExprNode {
46public:
47 CustomTableExprNode(CustomTableExprNodeRep &nodeRep)
48 : TableExprNode(&nodeRep) {
49 }
50 virtual ~CustomTableExprNode() {
51 }
52};
53
54template<typename T, size_t N>
55class SingleTypeEqPredicate: public TableExprPredicate {
56 Table const & table;
57 ROScalarColumn<T> *cols[N];
58 T const *values;
59public:
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) {
74 DebugAssert(&table == &this->table, AipsError);
75 for (size_t i = 0; i < N; i++) {
76 T v;
77 cols[i]->get(id.rownr(), v);
78 if (v != values[i]) {
79 return false;
80 }
81 }
82 return true;
83 }
84};
85
86} // asap
87
88#endif // ASAPACCELERATOR_H
Note: See TracBrowser for help on using the repository browser.