Blame Clause.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1995-1999
Packit a4aae4
// Please first read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
Packit a4aae4
Packit a4aae4
// Interface for the CE Clause class.
Packit a4aae4
Packit a4aae4
#ifndef _clause_h
Packit a4aae4
#define _clause_h
Packit a4aae4
Packit a4aae4
Packit a4aae4
#ifndef _expr_h
Packit a4aae4
#include "expr.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _rvalue_h
Packit a4aae4
#include "RValue.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
/** The selection part of a a DAP constraint expression may contain one or
Packit a4aae4
    more clauses, separated by ampersands (\&). This is modeled in the DDS
Packit a4aae4
    class structure as a singly-linked list of Clause objects. In addition, a
Packit a4aae4
    constraint expression may be a single function call, also represented in
Packit a4aae4
    the DDS using an instance of Clause.
Packit a4aae4
Packit a4aae4
    Each clause object can contain a representation of one of three
Packit a4aae4
    possible forms:
Packit a4aae4
Packit a4aae4
    
    Packit a4aae4
    Packit a4aae4
        
  1. A relational clause, where an operator tests the relation
  2. Packit a4aae4
        between two operands.  This kind of clause evaluates to a boolean
    Packit a4aae4
        value. For example: <tt>a > b</tt>.
    Packit a4aae4
    Packit a4aae4
        
  3. A boolean function, where some function operates on
  4. Packit a4aae4
        arguments in the clause to return a boolean value.  For example,
    Packit a4aae4
        consider a scalar A and a list L.  The clause <tt>find(A,L)</tt> might
    Packit a4aae4
        return TRUE if A is a member of L (if the <tt>find()</tt> function is
    Packit a4aae4
        defined).
    Packit a4aae4
    Packit a4aae4
        
  5. A clause that returns a pointer to a DAP BaseType value.
  6. Packit a4aae4
        This is a clause that evaluates to some data value (be it scalar
    Packit a4aae4
        or vector).  For example, <tt>sig0()</tt> might be included in the
    Packit a4aae4
        constraint expression parser to calculate density from pressure,
    Packit a4aae4
        temperature, and salinity.  In this case, <tt>sig0(p,t,s)</tt> would be a
    Packit a4aae4
        clause that evaluates to a data value.
    Packit a4aae4
    Packit a4aae4
        
    Packit a4aae4
    Packit a4aae4
        This might be a bit confusing; in the first, and by far more common, form
    Packit a4aae4
        of constraint expressions (CEs) only the first two types of clauses may
    Packit a4aae4
        appear. In the second form of the CE only the last type of clause may
    Packit a4aae4
        occur. The Clause class, however, can store them all.
    Packit a4aae4
    Packit a4aae4
        The Clause object holds the constraint expression after it
    Packit a4aae4
        has been parsed.  The parser renders the relational operator into
    Packit a4aae4
        an integer, and the functions into pointers.
    Packit a4aae4
    Packit a4aae4
        @brief Holds a fragment of a constraint expression.
    Packit a4aae4
        @see DDS::parse_constraint */
    Packit a4aae4
    struct Clause
    Packit a4aae4
    {
    Packit a4aae4
    Packit a4aae4
    private:
    Packit a4aae4
        /** The relational operator, if any. */
    Packit a4aae4
        int _op;
    Packit a4aae4
        /** A pointer to a valid boolean function. */
    Packit a4aae4
        bool_func _b_func;
    Packit a4aae4
    Packit a4aae4
        /** A pointer to a valid function that returns a pointer to a
    Packit a4aae4
        BaseType. */
    Packit a4aae4
        btp_func _bt_func;
    Packit a4aae4
    Packit a4aae4
        int _argc;   // arg count
    Packit a4aae4
        rvalue *_arg1;  // only for operator
    Packit a4aae4
        rvalue_list *_args;  // vector arg
    Packit a4aae4
    Packit a4aae4
        Clause(const Clause &);
    Packit a4aae4
        Clause &operator=(const Clause &);
    Packit a4aae4
    Packit a4aae4
    public:
    Packit a4aae4
        Clause(const int oper, rvalue *a1, rvalue_list *rv);
    Packit a4aae4
        Clause(bool_func func, rvalue_list *rv);
    Packit a4aae4
        Clause(btp_func func, rvalue_list *rv);
    Packit a4aae4
        Clause();
    Packit a4aae4
    Packit a4aae4
        virtual ~Clause();
    Packit a4aae4
    Packit a4aae4
        bool OK();
    Packit a4aae4
    Packit a4aae4
        bool boolean_clause();
    Packit a4aae4
    Packit a4aae4
        bool value_clause();
    Packit a4aae4
    Packit a4aae4
        bool value(DDS &dds;;
    Packit a4aae4
    Packit a4aae4
        bool value(DDS &dds, BaseType **value);
    Packit a4aae4
    };
    Packit a4aae4
    Packit a4aae4
    } // namespace libdap
    Packit a4aae4
    Packit a4aae4
    #endif // _clause_h