libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4FilterClause.cc
Go to the documentation of this file.
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) 2002,2003 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// (c) COPYRIGHT URI/MIT 1996,1998,1999
27// Please first read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32// Implementation for the CE Clause class.
33
34#include "config.h"
35
36#include "D4FilterClause.h"
37#include "D4RValue.h"
38
39using namespace std;
40
41namespace libdap {
42
43void D4FilterClauseList::m_duplicate(const D4FilterClauseList &src) {
44 // D4FilterClauseList &non_c_src = const_cast<D4FilterClauseList &>(src);
45
46 for (D4FilterClauseList::citer i = src.cbegin(), e = src.cend(); i != e; ++i) {
47 D4FilterClause *fc = *i;
48 d_clauses.push_back(new D4FilterClause(*fc));
49 }
50}
51
53 for (D4FilterClauseList::iter i = d_clauses.begin(), e = d_clauses.end(); i != e; ++i) {
54 delete *i;
55 }
56}
57
70 for (D4FilterClauseList::iter i = d_clauses.begin(), e = d_clauses.end(); i != e; ++i) {
71 if ((*i)->value(dmr) == false)
72 return false;
73 }
74
75 return true;
76}
77
89 for (D4FilterClauseList::iter i = d_clauses.begin(), e = d_clauses.end(); i != e; ++i) {
90 if ((*i)->value() == false)
91 return false;
92 }
93
94 return true;
95}
96
97void D4FilterClause::m_duplicate(const D4FilterClause &rhs) {
98 d_op = rhs.d_op;
99
100 d_arg1 = new D4RValue(*rhs.d_arg1);
101 d_arg2 = new D4RValue(*rhs.d_arg2);
102
103#if 0
104 // Copy the D4RValue pointer if the 'value_kind' is a basetype,
105 // but build a new D4RValue if it is a constant (because the
106 // basetype is a weak pointer.
107 switch (rhs.d_arg1->get_kind()) {
109 d_arg1 = rhs.d_arg1;
110 break;
112 d_arg1 = new D4RValue(*(rhs.d_arg1));
113 break;
114 default:
115 throw Error(malformed_expr, "found a filter clause with a function call.");
116 }
117
118 switch (rhs.d_arg2->get_kind()) {
120 d_arg2 = rhs.d_arg2;
121 break;
123 d_arg2 = new D4RValue(*(rhs.d_arg2));
124 break;
125 default:
126 throw Error(malformed_expr, "found a filter clause with a function call.");
127 }
128#endif
129}
130
139 switch (d_op) {
140 case null:
141 throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Found a null operator");
142
143 case less:
144 case greater:
145 case less_equal:
146 case greater_equal:
147 case equal:
148 case not_equal:
149 case match:
150 return cmp(d_op, d_arg1->value(dmr), d_arg2->value(dmr));
151
152 case ND:
153 case map:
154 throw InternalErr(__FILE__, __LINE__,
155 "While evaluating a constraint filter clause: Filter operator not implemented");
156
157 default:
158 throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Unrecognized operator");
159 }
160}
161
170 switch (d_op) {
171 case null:
172 throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Found a null operator");
173
174 case less:
175 case greater:
176 case less_equal:
177 case greater_equal:
178 case equal:
179 case not_equal:
180 case match:
181 return cmp(d_op, d_arg1->value(), d_arg2->value());
182
183 case ND:
184 case map:
185 throw InternalErr(__FILE__, __LINE__,
186 "While evaluating a constraint filter clause: Filter operator not implemented");
187
188 default:
189 throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Unrecognized operator");
190 }
191}
192
193// It may be better to use the code in the Byte, ..., classes that was
194// impl'd for DAP2 (with extensions). For now, test this and build the
195// rest of the filter implementation. But there is certainly a more _compact_
196// way to code this!
197//
198// Optimize the extraction of constant values.
199bool D4FilterClause::cmp(ops op, BaseType *arg1, BaseType *arg2) { return arg1->d4_ops(arg2, op); }
200
201} // namespace libdap
#define malformed_expr
(400)
Definition Error.h:66
The basic data type for the DODS DAP types.
Definition BaseType.h:118
virtual bool d4_ops(BaseType *b, int op)
Evaluator a relop for DAP4.
Definition BaseType.cc:1125
List of DAP4 Filter Clauses.
std::vector< D4FilterClause * >::iterator iter
std::vector< D4FilterClause * >::const_iterator citer
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 ...
value_kind get_kind() const
What kind of thing holds the value Values in DAP4 constraints are either constants,...
Definition D4RValue.h:139
A class for error processing.
Definition Error.h:92
A class for software fault reporting.
Definition InternalErr.h:61
top level DAP object to house generic methods
Definition AISConnect.cc:30