1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// (c) COPYRIGHT URI/MIT 1996,1998,1999
// Please first read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
// Implementation for the CE Clause class.
#include "config.h"
#include "D4RValue.h"
#include "D4FilterClause.h"
using namespace std;
namespace libdap {
void
D4FilterClauseList::m_duplicate(const D4FilterClauseList &src)
{
//D4FilterClauseList &non_c_src = const_cast<D4FilterClauseList &>(src);
for (D4FilterClauseList::citer i = src.cbegin(), e = src.cend(); i != e; ++i) {
D4FilterClause *fc = *i;
d_clauses.push_back(new D4FilterClause(*fc));
}
}
D4FilterClauseList::~D4FilterClauseList()
{
for (D4FilterClauseList::iter i = d_clauses.begin(), e = d_clauses.end(); i != e; ++i) {
delete *i;
}
}
/**
* @brief Evaluate the list of clauses
*
* Evaluate the list of clauses and return false when/if one is found to be false.
* This evaluates the clauses in the order they are stored and stops evaluation a
* the first false clause.
*
* @param dmr Use this DMR when evaluating clauses - for clauses that contain functions,
* not currently in the DAP4 specification.
* @return True if each of the clauses' value is true, otherwise false
*/
bool
D4FilterClauseList::value(DMR &dmr)
{
for (D4FilterClauseList::iter i = d_clauses.begin(), e = d_clauses.end(); i != e; ++i) {
if ((*i)->value(dmr) == false)
return false;
}
return true;
}
/**
* @brief Evaluate the list of clauses
*
* This version of value() does not need a DMR parameter (but will not work
* if the clauses contain a function call (which is not currently supported
* by the spec).
*
* @return True if each clauses' value is true, false otherwise
* @see D4FilterClauseList::value(DMR &dmr)
*/
bool
D4FilterClauseList::value()
{
for (D4FilterClauseList::iter i = d_clauses.begin(), e = d_clauses.end(); i != e; ++i) {
if ((*i)->value() == false)
return false;
}
return true;
}
void D4FilterClause::m_duplicate(const D4FilterClause &rhs) {
d_op = rhs.d_op;
d_arg1 = new D4RValue(*rhs.d_arg1);
d_arg2 = new D4RValue(*rhs.d_arg2);
#if 0
// Copy the D4RValue pointer if the 'value_kind' is a basetype,
// but build a new D4RValue if it is a constant (because the
// basetype is a weak pointer.
switch (rhs.d_arg1->get_kind()) {
case D4RValue::basetype:
d_arg1 = rhs.d_arg1;
break;
case D4RValue::constant:
d_arg1 = new D4RValue(*(rhs.d_arg1));
break;
default:
throw Error(malformed_expr, "found a filter clause with a function call.");
}
switch (rhs.d_arg2->get_kind()) {
case D4RValue::basetype:
d_arg2 = rhs.d_arg2;
break;
case D4RValue::constant:
d_arg2 = new D4RValue(*(rhs.d_arg2));
break;
default:
throw Error(malformed_expr, "found a filter clause with a function call.");
}
#endif
}
/**
* @brief Get the value of this relational expression.
* This version of value() works for function clauses, although that's
* not supported by the syntax at this time.
* @param dmr The DMR to use when evaluating a function
* @return True if the clause is true, false otherwise.
*/
bool D4FilterClause::value(DMR &dmr)
{
switch (d_op) {
case null:
throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Found a null operator");
case less:
case greater:
case less_equal:
case greater_equal:
case equal:
case not_equal:
case match:
return cmp(d_op, d_arg1->value(dmr), d_arg2->value(dmr));
case ND:
case map:
throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Filter operator not implemented");
default:
throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Unrecognized operator");
}
}
/**
* @brief Get the value of this relational expression.
* This version of value() will not work for clauses where one of the
* rvalues is a function call. This is not currently supported by the
* DAP4 specification, so it's probably no great loss.
* @return True if the clause is true, false otherwise.
*/
bool D4FilterClause::value()
{
switch (d_op) {
case null:
throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Found a null operator");
case less:
case greater:
case less_equal:
case greater_equal:
case equal:
case not_equal:
case match:
return cmp(d_op, d_arg1->value(), d_arg2->value());
case ND:
case map:
throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Filter operator not implemented");
default:
throw InternalErr(__FILE__, __LINE__, "While evaluating a constraint filter clause: Unrecognized operator");
}
}
// It may be better to use the code in the Byte, ..., classes that was
// impl'd for DAP2 (with extensions). For now, test this and build the
// rest of the filter implementation. But there is certainly a more _compact_
// way to code this!
//
// Optimize the extraction of constant values.
bool D4FilterClause::cmp(ops op, BaseType *arg1, BaseType *arg2)
{
return arg1->d4_ops(arg2, op);
}
} // namespace libdap
|