libdap++  Updated for version 3.8.2
ConstraintEvaluator.h
Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <list>
29 
30 #ifndef _dds_h
31 #include "DDS.h"
32 #endif
33 
34 #ifndef _datadds_h
35 #include "DataDDS.h"
36 #endif
37 
38 #ifndef _clause_h
39 #include "Clause.h"
40 #endif
41 
42 namespace libdap
43 {
44 
47 {
48 private:
49  // This struct is used to hold all the known `user defined' functions
50  // (including those that are `built-in').
51  struct function
52  {
53  string name;
54  bool_func b_func;
55  btp_func bt_func;
56  proj_func p_func;
57 
58  function(const string &n, const bool_func f)
59  : name(n), b_func(f), bt_func(0), p_func(0)
60  {}
61  function(const string &n, const btp_func f)
62  : name(n), bt_func(f), p_func(0)
63  {}
64  function(const string &n, const proj_func f)
65  : name(n), bt_func(0), p_func(f)
66  {}
67  function(): name(""), bt_func(0), p_func(0)
68  {}
69  };
70 
71  vector<Clause *> expr; // List of CE Clauses
72 
73  vector<BaseType *> constants;// List of temporary objects
74 
75  list<function> functions; // Known external functions
76 
77  // The default versions of these methods will break this class. Because
78  // Clause does not support deep copies, that class will need to be modified
79  // before these can be properly implemented. jhrg 4/3/06
81  {}
82  ConstraintEvaluator &operator=(const ConstraintEvaluator &)
83  {
84  throw InternalErr(__FILE__, __LINE__, "Unimplemented method");
85  }
86 
87  friend class func_name_is;
88 
89 public:
90  typedef std::vector<Clause *>::const_iterator Clause_citer ;
91  typedef std::vector<Clause *>::iterator Clause_iter ;
92 
93  typedef std::vector<BaseType *>::const_iterator Constants_citer ;
94  typedef std::vector<BaseType *>::iterator Constants_iter ;
95 
96  typedef std::list<function>::const_iterator Functions_citer ;
97  typedef std::list<function>::iterator Functions_iter ;
98 
100  virtual ~ConstraintEvaluator();
101 
102  void add_function(const string &name, bool_func f);
103  void add_function(const string &name, btp_func f);
104  void add_function(const string &name, proj_func f);
105 
106  bool find_function(const string &name, bool_func *f) const;
107  bool find_function(const string &name, btp_func *f) const;
108  bool find_function(const string &name, proj_func *f) const;
109 
110  void append_clause(int op, rvalue *arg1, rvalue_list *arg2);
111  void append_clause(bool_func func, rvalue_list *args);
112  void append_clause(btp_func func, rvalue_list *args);
113 
114  bool functional_expression();
115  bool boolean_expression();
116  bool eval_selection(DDS &dds, const string &dataset);
117  BaseType *eval_function(DDS &dds, const string &dataset);
118 
119  // New for libdap 3.11. These methods provide a way to evaluate multiple
120  // functions in one CE
121  bool function_clauses();
124 
127  bool clause_value(Clause_iter &i, DDS &dds);
128 
129  void parse_constraint(const string &constraint, DDS &dds);
130  void append_constant(BaseType *btp);
131 
132 };
133 
134 } // namespace libdap
135 
136 #endif // constraint_evaluator_h
std::vector< rvalue * > rvalue_list
Definition: RValue.h:67
bool boolean_expression()
Does the current constraint expression return a boolean value?
std::list< function >::const_iterator Functions_citer
BaseType * eval_function(DDS &dds, const string &dataset)
Evaluate a function-valued constraint expression.
void parse_constraint(const string &constraint, DDS &dds)
Parse the constraint expression given the current DDS.
A class for software fault reporting.
Definition: InternalErr.h:64
std::vector< BaseType * >::const_iterator Constants_citer
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
DDS * eval_function_clauses(DDS &dds)
Evaluate a function-valued constraint expression that contains several function calls.
std::vector< BaseType * >::iterator Constants_iter
Evaluate a constraint expression.
bool functional_expression()
Does the current constraint expression return a BaseType pointer? This method does not evaluate the c...
void add_function(const string &name, bool_func f)
Add a boolean function to the list.
std::vector< Clause * >::const_iterator Clause_citer
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
void append_constant(BaseType *btp)
bool clause_value(Clause_iter &i, DDS &dds)
bool function_clauses()
Does the current constraint expression return a DDS pointer?
std::vector< Clause * >::iterator Clause_iter
Holds a DAP2 DDS.
Definition: DataDDS.h:77
void append_clause(int op, rvalue *arg1, rvalue_list *arg2)
Add a clause to a constraint expression.
std::list< function >::iterator Functions_iter
bool find_function(const string &name, bool_func *f) const
Find a Boolean function with a given name in the function list.