2 #ifndef _EXPRESSION_TREE_CPP_ 3 #define _EXPRESSION_TREE_CPP_ 5 #ifndef _MADARA_NO_KARL_ 136 TRAVERSAL_MAP::iterator iter =
traversal_map_.find (traversal_order);
144 return (this->*ptmf) (tree, end_iter);
155 : logger_ (&logger), root_ (0)
204 return root_.get_ptr () == 0;
214 bool root_can_change =
false;
217 if (this->
root_.get_ptr ())
219 root_value = this->
root_->prune (root_can_change);
220 if (!root_can_change &&
221 dynamic_cast <LeafNode *> (this->
root_.get_ptr ()) == 0)
237 if (
root_.get_ptr () != 0)
238 return root_->evaluate (settings);
248 return root_.get_ptr ();
256 return root_->item ();
324 root_->accept (visitor);
327 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord item(void) const
Returns value of tree.
Encapsulates a MADARA KaRL expression into an evaluatable tree.
madara::knowledge::KnowledgeRecord KnowledgeRecord
ExpressionTree(logger::Logger &logger=*logger::global_logger.get())
Constructor.
bool is_null(void) const
Checks if root pointer is null.
iterator end(const std::string &traversal_order)
Returns an iterator to the end of the expression tree.
Iterates through an ExpressionTree in in-order.
Constant iterator over an expression tree.
ExpressionTreeIteratorImpl *(ExpressionTreeIteratorFactory::* TRAVERSAL_PTMF)(ExpressionTree &tree, bool end_iter)
void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
Non-const iterator for traversing an expression tree.
ExpressionTreeIteratorImpl * make_post_order_tree_iterator(ExpressionTree &tree, bool end_iter)
Dynamically allocate a new ExpressionTreePostOrderIteratorImpl object based on the designated end_ite...
madara::knowledge::KnowledgeRecord prune(void)
Prunes the expression tree of unnecessary nodes.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Provides knowledge logging services to files and terminals.
Implementation of a factory pattern that dynamically allocates the appropriate ExpressionTreeIterator...
A multi-threaded logger for logging to one or more destinations.
ExpressionTreeIteratorImpl * make_in_order_tree_iterator(ExpressionTree &tree, bool end_iter)
Dynamically allocate a new ExpressionTreeLevelOrderIteratorImpl object based on the designated end_it...
static madara::expression::ExpressionTreeIteratorFactory tree_iterator_factory
ExpressionTreeConstIterator const_iterator
Iterates through an ExpressionTree in post-order.
ExpressionTreeIteratorImpl * make_level_order_tree_iterator(ExpressionTree &tree, bool end_iter)
Dynamically allocate a new ExpressionTreeLevelOrderIteratorImpl object based on the designated end_it...
ComponentNode * get_root(void)
Returns the root node of the expression tree.
Iterates through an ExpressionTree in level-order.
An abstract base class defines a simple abstract implementation of an expression tree node...
Abstract base class for all visitors to all classes that derive from ComponentNode.
ExpressionTree left(void)
Returns the left expression of this tree.
ExpressionTreeIteratorFactory(void)
Constructor.
TRAVERSAL_MAP traversal_map_
ExpressionTree right(void)
Returns the right expression of this tree.
::std::map< std::string, TRAVERSAL_PTMF > TRAVERSAL_MAP
Iterates through an ExpressionTree in level-order.
logger::Logger * logger_
handle for logging information
ExpressionTreeIterator iterator
ExpressionTreeIteratorImpl * make_pre_order_tree_iterator(ExpressionTree &tree, bool end_iter)
Dynamically allocate a new ExpressionTreePreOrderIteratorImpl object based on the designated end_iter...
ExpressionTreeIteratorImpl * make_tree_iterator(ExpressionTree &tree, const std::string &traversal_order, bool end_iter)
Dynamically allocate a new ExpressionTreeIteratorImpl object based on the designated traversal_order ...
~ExpressionTree(void)
Destructor.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
madara::utility::Refcounter< ComponentNode > root_
root of the expression tree
Implementation of the ExpressionTreeIterator pattern that is used to define the various iterations al...
void operator=(const ExpressionTree &tree)
Non-deep copies an expression tree into this instance.
madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Evaluates the expression tree.
iterator begin(const std::string &traversal_order)
Returns an iterator to the beginning of the expression tree.