2 #ifndef _MADARA_NO_KARL_
22 compare_type_(compare_type)
47 value = array_->item();
57 bool left_child_can_change =
false;
58 bool right_child_can_change =
false;
61 if (this->var_ != 0 || this->array_ != 0)
62 left_child_can_change =
true;
66 "madara::expression::VariableCompareNode: "
67 "KARL COMPILE ERROR: Compare has no variable\\n");
70 "KARL COMPILE ERROR: "
71 "Node has no variable left-hand side\n");
76 right_value = this->rhs_->prune(right_child_can_change);
77 if (!right_child_can_change &&
dynamic_cast<LeafNode*
>(rhs_) == 0)
80 this->rhs_ =
new LeafNode(*(this->logger_), right_value);
86 "madara::expression::VariableCompareNode: "
87 "KARL COMPILE ERROR: Compare has no right expression\n");
90 "KARL COMPILE ERROR: "
91 "Node has no right expression\n");
94 can_change = left_child_can_change || right_child_can_change;
108 lhs = var_->evaluate(settings);
110 lhs = array_->evaluate(settings);
114 if (compare_type_ == LESS_THAN)
116 result = lhs < rhs_->evaluate(settings);
118 else if (compare_type_ == LESS_THAN_EQUAL)
120 result = lhs <= rhs_->evaluate(settings);
122 else if (compare_type_ == EQUAL)
124 result = lhs == rhs_->evaluate(settings);
128 result = lhs >= rhs_->evaluate(settings);
132 result = lhs > rhs_->evaluate(settings);
137 if (compare_type_ == LESS_THAN)
139 result = lhs < value_;
141 else if (compare_type_ == LESS_THAN_EQUAL)
143 result = lhs <= value_;
145 else if (compare_type_ == EQUAL)
147 result = lhs == value_;
151 result = lhs >= value_;
155 result = lhs > value_;
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
An abstract base class defines a simple abstract implementation of an expression tree node.
Defines a terminal node of that references the current value stored in a variable.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
CompositeArrayReference * array_
variable index holder
VariableNode * var_
variable holder
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node and its children.
virtual void accept(Visitor &visitor) const
Define the accept() operation used for the Visitor pattern.
virtual ~VariableCompareNode(void)
Dtor.
VariableCompareNode(ComponentNode *lhs, madara::knowledge::KnowledgeRecord value, int type, ComponentNode *rhs, madara::knowledge::ThreadSafeContext &context)
Ctor.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prune the tree of unnecessary nodes.
Defines a terminal node of that references the current value stored in a variable.
Abstract base class for all visitors to all classes that derive from ComponentNode.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...