D4FilterClause.cc
// -*- 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;
}
}
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;
}
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
}
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");
}
}
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
libdap::BaseType::d4_ops
virtual bool d4_ops(BaseType *b, int op)
Evaluator a relop for DAP4.
Definition: BaseType.cc:1273
std
STL namespace.
libdap::D4RValue
Definition: D4RValue.h:79
libdap
Definition: AlarmHandler.h:35
libdap::InternalErr
A class for software fault reporting.
Definition: InternalErr.h:64
libdap::DMR
Definition: DMR.h:55
libdap::D4FilterClause
DAP4 filter clauses.
Definition: D4FilterClause.h:114
libdap::BaseType
The basic data type for the DODS DAP types.
Definition: BaseType.h:117
libdap::Error
A class for error processing.
Definition: Error.h:90
libdap::D4RValue::get_kind
value_kind get_kind() const
What kind of thing holds the value Values in DAP4 constraints are either constants, dataset variables or function results. It might be nice to know the source of a given value in order to optimize the evaluation of certain kinds of expressions.
Definition: D4RValue.h:144