1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2006 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #ifndef constraint_evaluator_h
26 #define constraint_evaluator_h
27 
28 #include <vector>
29 
30 #include "expr.h"
31 #include "RValue.h"
32 
33 namespace libdap
34 {
35 
36 class DDS;
37 class DataDDS;
38 struct Clause;
39 class ServerFunctionsList;
40 
41 /** @brief Evaluate a constraint expression */
42 class ConstraintEvaluator
43 {
44 private:
45     std::vector<Clause *> expr;      // List of CE Clauses
46 
47     std::vector<BaseType *> constants;// List of temporary objects
48 
49     ServerFunctionsList *d_functions_list;  // Known external functions from
50                                             // modules
51 
52     // The default versions of these methods will break this class. Because
53     // Clause does not support deep copies, that class will need to be modified
54     // before these can be properly implemented. jhrg 4/3/06
55     ConstraintEvaluator(const ConstraintEvaluator &);
56     ConstraintEvaluator &operator=(const ConstraintEvaluator &);
57 
58     friend class func_name_is;
59 
60 public:
61     typedef std::vector<Clause *>::const_iterator Clause_citer ;
62     typedef std::vector<Clause *>::iterator Clause_iter ;
63 
64     typedef std::vector<BaseType *>::const_iterator Constants_citer ;
65     typedef std::vector<BaseType *>::iterator Constants_iter ;
66 
67     ConstraintEvaluator();
68 
69     virtual ~ConstraintEvaluator();
70     bool find_function(const std::string &name, bool_func *f) const;
71     bool find_function(const std::string &name, btp_func *f) const;
72     bool find_function(const std::string &name, proj_func *f) const;
73 
74     void append_clause(int op, rvalue *arg1, rvalue_list *arg2);
75     void append_clause(bool_func func, rvalue_list *args);
76     void append_clause(btp_func func, rvalue_list *args);
77 
78     bool functional_expression();
79     bool boolean_expression();
80     bool eval_selection(DDS &dds, const std::string &dataset);
81     BaseType *eval_function(DDS &dds, const std::string &dataset);
82 
83     // New for libdap 3.11. These methods provide a way to evaluate multiple
84     // functions in one CE
85     bool function_clauses();
86     DDS *eval_function_clauses(DDS &dds);
87     DataDDS *eval_function_clauses(DataDDS &dds);
88 
89     Clause_iter clause_begin();
90     Clause_iter clause_end();
91     bool clause_value(Clause_iter &i, DDS &dds);
92 
93     void parse_constraint(const std::string &constraint, DDS &dds);
94     void append_constant(BaseType *btp);
95 
96 };
97 
98 } // namespace libdap
99 
100 #endif // constraint_evaluator_h
101