explicit function_expression( const std::string& name, const args_list& args, int min_args=-1, int max_args=-1) : name_(name), args_(args) { set_name(name.c_str()); if(min_args >= 0 && args_.size() < static_cast<size_t>(min_args)) { throw formula_error("Too few arguments", "", "", 0); } if(max_args >= 0 && args_.size() > static_cast<size_t>(max_args)) { throw formula_error("Too many arguments", "", "", 0); } }
bool Operator::operator()(bool o) const { try { if (NOT != data) throw formula_error("Invalid formula!"); } catch (formula_error err) { err.process(); } return !o; }
bool Operator::operator()(bool o1, bool o2) const { try { if (XNOR == data) return o1 ^ o2; else if (IMPLICATION == data) { if (!o1) return true; else if (o2) return true; else return false; } else if (OR == data) return o1 || o2; else if (AND == data) return o1 && o2; else throw formula_error("Invalid formula!"); } catch (formula_error err) { err.process(); } }