libdap Updated for version 3.20.11
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4FilterClause.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2015 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26#ifndef _d4_filter_clause_h
27#define _d4_filter_clause_h
28
29#include <cassert>
30#include <vector>
31
32#include "ce_expr.tab.hh" // Use the same codes for D4 as we use in DAP2
33
34namespace libdap
35{
36
37class D4Rvalue;
38class D4FilterClause;
39
45{
46private:
47 std::vector<D4FilterClause *> d_clauses;
48
49 void m_duplicate(const D4FilterClauseList &src);
50
51public:
52 typedef std::vector<D4FilterClause *>::iterator iter;
53 typedef std::vector<D4FilterClause *>::const_iterator citer;
54
56 D4FilterClauseList(const D4FilterClauseList &src) { m_duplicate(src); }
57
58 D4FilterClauseList(D4FilterClause *c) { add_clause(c); }
59
60 virtual ~D4FilterClauseList();
61
62 D4FilterClauseList &operator=(const D4FilterClauseList &rhs) {
63 if (this == &rhs)
64 return *this;
65
66 m_duplicate(rhs);
67
68 return *this;
69 }
70
71 void add_clause(D4FilterClause *c) {
72 d_clauses.push_back(c);
73 }
74
75 D4FilterClause *get_clause(unsigned int i) {
76 return d_clauses.at(i);
77 }
78
79 citer cbegin() const { return d_clauses.begin(); }
80 citer cend() const { return d_clauses.end(); }
81
82 unsigned int size() const { return d_clauses.size(); }
83
84 // get the clause value; this version supports functional clauses
85 bool value(DMR &dmr);
86
87 bool value();
88};
89
115{
116public:
117 enum ops {
118 // Stock relops
119 null = 0,
120 less = SCAN_LESS,
121 greater = SCAN_GREATER,
122 less_equal = SCAN_LESS_EQL,
123 greater_equal = SCAN_GREATER_EQL,
124 equal = SCAN_EQUAL,
125 not_equal = SCAN_NOT_EQUAL,
126 // Regex match for strings
127 match = SCAN_REGEXP,
128 // The mapping operator; not sure if this will be implemented
129 map,
130 // No Data 'operator' for array filtering; may not be impl'd
131 ND
132 };
133
134private:
136 ops d_op;
137
138 D4RValue *d_arg1, *d_arg2;
139
140 D4FilterClause() : d_op(null), d_arg1(0), d_arg2(0) { }
141
142 void m_duplicate(const D4FilterClause &rhs);
143
144 // These methods factor out first the first argument and then the
145 // second. I could write one really large cmp() for all of this...
146 //template<typename T> bool cmp(ops op, BaseType *arg1, T arg2);
147 bool cmp(ops op, BaseType *arg1, BaseType *arg2);
148
149 friend class D4FilterClauseList;
150
151public:
169 D4FilterClause(const ops op, D4RValue *arg1, D4RValue *arg2) :
170 d_op(op), d_arg1(arg1), d_arg2(arg2) {
171 assert(op != null && "null operator");
172 assert(arg1 && "null arg1");
173 assert(arg2 && "null arg2");
174 }
175
176 D4FilterClause(const D4FilterClause &src) {
177 m_duplicate(src);
178 }
179
180 D4FilterClause &operator=(const D4FilterClause &rhs) {
181 if (this == &rhs)
182 return *this;
183
184 m_duplicate(rhs);
185
186 return *this;
187 }
188
189 virtual ~D4FilterClause() {
190 delete d_arg1;
191 delete d_arg2;
192 }
193
194 // get the clause value; this version supports functional clauses
195 bool value(DMR &dmr);
196
197 bool value();
198};
199
200} // namespace libdap
201
202#endif // _clause_h
The basic data type for the DODS DAP types.
Definition: BaseType.h:118
List of DAP4 Filter Clauses.
bool value()
Evaluate the list of clauses.
DAP4 filter clauses.
bool value()
Get the value of this relational expression. This version of value() will not work for clauses where ...
D4FilterClause(const ops op, D4RValue *arg1, D4RValue *arg2)
top level DAP object to house generic methods
Definition: AlarmHandler.h:36