29 #include "ServerFunctionsList.h" 30 #include "ConstraintEvaluator.h" 34 #include "ce_parser.h" 39 struct yy_buffer_state;
44 void ce_expr_switch_to_buffer(
void *new_buffer);
45 void ce_expr_delete_buffer(
void * buffer);
46 void *ce_expr_string(
const char *yy_str);
50 ConstraintEvaluator::ConstraintEvaluator()
59 d_functions_list = ServerFunctionsList::TheList();
62 ConstraintEvaluator::~ConstraintEvaluator()
65 for (Constants_iter j = constants.begin(); j != constants.end(); j++) {
71 for (Clause_iter k = expr.begin(); k != expr.end(); k++) {
96 throw InternalErr(__FILE__, __LINE__,
"There are no CE clauses for *this* DDS object.");
98 return (*iter)->value(dds);
117 expr.push_back(clause);
133 expr.push_back(clause);
149 expr.push_back(clause);
161 constants.push_back(btp);
206 if (expr.size() != 1)
207 throw InternalErr(__FILE__, __LINE__,
"The length of the list of CE clauses is not 1.");
211 if (cp->
value(dds, &result))
231 for (
unsigned int i = 0; i < expr.size(); ++i) {
259 throw InternalErr(__FILE__, __LINE__,
"The constraint expression is empty.");
262 for (
unsigned int i = 0; i < expr.size(); ++i) {
265 if (cp->
value(dds, &result)) {
272 throw Error(internal_error,
"A function was called but failed to return a value.");
288 throw InternalErr(__FILE__, __LINE__,
"The constraint expression is empty.");
293 for (
unsigned int i = 0; i < expr.size(); ++i) {
296 if (cp->
value(dds, &result)) {
301 throw Error(internal_error,
"A function was called but failed to return a value.");
315 for (Clause_iter i = expr.begin(); i != expr.end(); i++) {
316 boolean =
boolean && (*i)->boolean_clause();
332 DBG(cerr <<
"No selection recorded" << endl);
336 DBG(cerr <<
"Eval selection" << endl);
343 for (Clause_iter i = expr.begin(); i != expr.end() && result; i++) {
345 if (!((*i)->boolean_clause()))
346 throw InternalErr(__FILE__, __LINE__,
"A selection expression must contain only boolean clauses.");
347 result = result && (*i)->value(dds);
365 void *buffer = ce_expr_string(constraint.c_str());
367 ce_expr_switch_to_buffer(buffer);
374 ce_expr_delete_buffer(buffer);
378 ce_expr_delete_buffer(buffer);
bool boolean_expression()
Does the current constraint expression return a boolean value?
bool find_function(const std::string &name, bool_func *f) const
Find a Boolean function with a given name in the function list.
virtual bool find_function(const std::string &name, bool_func *f) const
Find a boolean function with a given name in the function list.
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
string get_dataset_name() const
BaseType * eval_function(DDS &dds, const std::string &dataset)
Evaluate a function-valued constraint expression.
top level DAP object to house generic methods
A class for software fault reporting.
bool value(DDS &dds)
Evaluate a clause which returns a boolean value This method must only be evaluated for clauses with r...
DDS * eval_function_clauses(DDS &dds)
Evaluate a function-valued constraint expression that contains several function calls.
void parse_constraint(const std::string &constraint, DDS &dds)
Parse the constraint expression given the current DDS.
bool functional_expression()
Does the current constraint expression return a BaseType pointer? This method does not evaluate the c...
Clause_iter clause_begin()
string get_version() const
Get the server version string, unparsed.
The basic data type for the DODS DAP types.
void append_constant(BaseType *btp)
bool clause_value(Clause_iter &i, DDS &dds)
bool eval_selection(DDS &dds, const std::string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator and is called ...
Holds a fragment of a constraint expression.
bool function_clauses()
Does the current constraint expression contain function clauses.
A class for error processing.
BaseTypeFactory * get_factory() const
bool value_clause()
Return true if the clause returns a value in a BaseType pointer.
void append_clause(int op, rvalue *arg1, rvalue_list *arg2)
Add a clause to a constraint expression.