D4FilterClause.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2015 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.
#ifndef _d4_filter_clause_h
#define _d4_filter_clause_h
#include <cassert>
#include <vector>
#include "ce_expr.tab.hh" // Use the same codes for D4 as we use in DAP2
namespace libdap
{
class D4Rvalue;
class D4FilterClause;
class D4FilterClauseList
{
private:
std::vector<D4FilterClause *> d_clauses;
void m_duplicate(const D4FilterClauseList &src);
public:
typedef std::vector<D4FilterClause *>::iterator iter;
typedef std::vector<D4FilterClause *>::const_iterator citer;
D4FilterClauseList() { }
D4FilterClauseList(const D4FilterClauseList &src) { m_duplicate(src); }
D4FilterClauseList(D4FilterClause *c) { add_clause(c); }
virtual ~D4FilterClauseList();
D4FilterClauseList &operator=(const D4FilterClauseList &rhs) {
if (this == &rhs)
return *this;
m_duplicate(rhs);
return *this;
}
void add_clause(D4FilterClause *c) {
d_clauses.push_back(c);
}
D4FilterClause *get_clause(unsigned int i) {
return d_clauses.at(i);
}
citer cbegin() const { return d_clauses.begin(); }
citer cend() const { return d_clauses.end(); }
unsigned int size() const { return d_clauses.size(); }
// get the clause value; this version supports functional clauses
bool value(DMR &dmr);
bool value();
};
class D4FilterClause
{
public:
enum ops {
// Stock relops
null = 0,
less = SCAN_LESS,
greater = SCAN_GREATER,
less_equal = SCAN_LESS_EQL,
greater_equal = SCAN_GREATER_EQL,
equal = SCAN_EQUAL,
not_equal = SCAN_NOT_EQUAL,
// Regex match for strings
match = SCAN_REGEXP,
// The mapping operator; not sure if this will be implemented
map,
// No Data 'operator' for array filtering; may not be impl'd
ND
};
private:
ops d_op;
D4RValue *d_arg1, *d_arg2;
D4FilterClause() : d_op(null), d_arg1(0), d_arg2(0) { }
void m_duplicate(const D4FilterClause &rhs);
// These methods factor out first the first argument and then the
// second. I could write one really large cmp() for all of this...
//template<typename T> bool cmp(ops op, BaseType *arg1, T arg2);
bool cmp(ops op, BaseType *arg1, BaseType *arg2);
friend class D4FilterClauseList;
public:
D4FilterClause(const ops op, D4RValue *arg1, D4RValue *arg2) :
d_op(op), d_arg1(arg1), d_arg2(arg2) {
assert(op != null && "null operator");
assert(arg1 && "null arg1");
assert(arg2 && "null arg2");
}
D4FilterClause(const D4FilterClause &src) {
m_duplicate(src);
}
D4FilterClause &operator=(const D4FilterClause &rhs) {
if (this == &rhs)
return *this;
m_duplicate(rhs);
return *this;
}
virtual ~D4FilterClause() {
delete d_arg1;
delete d_arg2;
}
// get the clause value; this version supports functional clauses
bool value(DMR &dmr);
bool value();
};
} // namespace libdap
#endif // _clause_h
libdap::D4RValue
Definition: D4RValue.h:79
libdap
Definition: AlarmHandler.h:35
libdap::D4FilterClauseList::value
bool value()
Evaluate the list of clauses.
Definition: D4FilterClause.cc:95
libdap::D4FilterClauseList
List of DAP4 Filter Clauses.
Definition: D4FilterClause.h:44
libdap::DMR
Definition: DMR.h:55
libdap::D4FilterClause::D4FilterClause
D4FilterClause(const ops op, D4RValue *arg1, D4RValue *arg2)
Definition: D4FilterClause.h:169
libdap::D4FilterClause
DAP4 filter clauses.
Definition: D4FilterClause.h:114
libdap::BaseType
The basic data type for the DODS DAP types.
Definition: BaseType.h:117