ConstraintEvaluator.h

Go to the documentation of this file.
00001 // -*- mode: c++; c-basic-offset:4 -*-
00002 
00003 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00004 // Access Protocol.
00005 
00006 // Copyright (c) 2006 OPeNDAP, Inc.
00007 // Author: James Gallagher <jgallagher@opendap.org>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00024 
00025 #ifndef constraint_evaluator_h
00026 #define constraint_evaluator_h
00027 
00028 #include <list>
00029 
00030 #ifndef _clause_h
00031 #include "Clause.h"
00032 #endif
00033 
00035 class ConstraintEvaluator
00036 {
00037 private:
00038     // This struct is used to hold all the known `user defined' functions
00039     // (including those that are `built-in').
00040     struct function
00041     {
00042         string name;
00043         bool_func b_func;
00044         btp_func bt_func;
00045         proj_func p_func;
00046 
00047         function(const string &n, const bool_func f)
00048                 : name(n), b_func(f), bt_func(0), p_func(0)
00049         {}
00050         function(const string &n, const btp_func f)
00051                 : name(n), b_func(0), bt_func(f), p_func(0)
00052         {}
00053         function(const string &n, const proj_func f)
00054                 : name(n), b_func(0), bt_func(0), p_func(f)
00055         {}
00056         function(): name(""), b_func(0), bt_func(0), p_func(0)
00057         {}
00058     };
00059 
00060     vector<Clause *> expr;      // List of CE Clauses
00061 
00062     vector<BaseType *> constants;// List of temporary objects
00063 
00064     list<function> functions; // Known external functions
00065 
00066     // The default versions of these methods will break this class. Because
00067     // Clause does not support deep copies, that class will need to be modified
00068     // before these can be properly implemented. jhrg 4/3/06
00069     ConstraintEvaluator(const ConstraintEvaluator &)
00070     {}
00071     ConstraintEvaluator &operator=(const ConstraintEvaluator &)
00072     {
00073         throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
00074     }
00075 
00076     friend class func_name_is;
00077 
00078 public:
00079     typedef std::vector<Clause *>::const_iterator Clause_citer ;
00080     typedef std::vector<Clause *>::iterator Clause_iter ;
00081 
00082     typedef std::vector<BaseType *>::const_iterator Constants_citer ;
00083     typedef std::vector<BaseType *>::iterator Constants_iter ;
00084 
00085     typedef std::list<function>::const_iterator Functions_citer ;
00086     typedef std::list<function>::iterator Functions_iter ;
00087 
00088     ConstraintEvaluator();
00089     virtual ~ConstraintEvaluator();
00090 
00091     void add_function(const string &name, bool_func f);
00092     void add_function(const string &name, btp_func f);
00093     void add_function(const string &name, proj_func f);
00094 
00095     bool find_function(const string &name, bool_func *f) const;
00096     bool find_function(const string &name, btp_func *f) const;
00097     bool find_function(const string &name, proj_func *f) const;
00098 
00099     void append_clause(int op, rvalue *arg1, rvalue_list *arg2);
00100     void append_clause(bool_func func, rvalue_list *args);
00101     void append_clause(btp_func func, rvalue_list *args);
00102 
00103     bool functional_expression();
00104     bool boolean_expression();
00105     bool eval_selection(DDS &dds, const string &dataset);
00106     BaseType *eval_function(DDS &dds, const string &dataset);
00107 
00108 
00109     Clause_iter clause_begin();
00110     Clause_iter clause_end();
00111     bool clause_value(Clause_iter &i, DDS &dds, const string &dataset);
00112 
00113     void parse_constraint(const string &constraint, DDS &dds);
00114     void append_constant(BaseType *btp);
00115 
00116 };
00117 
00118 #endif // constraint_evaluator_h

Generated on Wed Jun 27 12:56:38 2007 for libdap++ by  doxygen 1.4.7