MADARA  3.4.1
CompositePredecrementNode.cpp
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _COMPOSITE_PREDECREMENT_NODE_CPP_
3 #define _COMPOSITE_PREDECREMENT_NODE_CPP_
4 
5 #ifndef _MADARA_NO_KARL_
6 
7 #include <iostream>
8 
15 
18  : CompositeUnaryNode(logger, right)
19 {
20  var_ = dynamic_cast<VariableNode*>(right);
21 
22  if (!var_)
23  array_ = dynamic_cast<CompositeArrayReference*>(right);
24 }
25 
26 // Dtor
28 {
29 }
30 
33 {
35  record.set_value("--");
36  return record;
37 }
38 
44 {
45  bool right_child_can_change = false;
47 
48  if (this->right_)
49  {
50  right_value = this->right_->prune(right_child_can_change);
51  if (!right_child_can_change && dynamic_cast<LeafNode*>(right_) == 0)
52  {
53  delete this->right_;
54  this->right_ = new LeafNode(*(this->logger_), right_value);
55  }
56  }
57  else if (!var_ && !array_)
58  {
60  "madara::expression::CompositePredecrementNode: "
61  "KARL COMPILE ERROR:"
62  "Preincrement has no var, array, or expression\n");
63 
65  "madara::expression::CompositePreincrementNode: "
66  "KARL COMPILE ERROR: "
67  "Preincrement has no var, array, or expression\n");
68  }
69 
70  can_change = right_child_can_change;
71 
72  return --right_value;
73 }
74 
80 {
81  if (var_)
82  return var_->dec(settings);
83  else if (array_)
84  return array_->dec(settings);
85  else if (right_)
86  return --(this->right_->evaluate(settings));
87  else
88  {
90  "madara::expression::CompositePredecrementNode: "
91  "KARL RUNTIME ERROR: "
92  "Predecrement has no var, array, or expression\n");
93 
95  "madara::expression::CompositePredecrementNode: "
96  "KARL RUNTIME ERROR: "
97  "Predecrement has no var, array, or expression\n");
98  }
99 }
100 
101 // accept a visitor
103  Visitor& visitor) const
104 {
105  visitor.visit(*this);
106 }
107 
108 #endif // _MADARA_NO_KARL_
109 
110 #endif /* _COMPOSITE_PREDECREMENT_NODE_CPP_ */
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:21
An abstract base class defines a simple abstract implementation of an expression tree node.
Definition: ComponentNode.h:37
Defines a terminal node of that references the current value stored in a variable.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the printable character of the node.
CompositePredecrementNode(logger::Logger &logger, ComponentNode *right)
Constructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
CompositeArrayReference * array_
variable index holder
Encapsulates a single expression tree.
virtual ComponentNode * right(void) const
Returns the right expression.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Definition: LeafNode.h:25
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:29
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:93
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
void set_value(const KnowledgeRecord &new_value)
Sets the value from another KnowledgeRecord, does not copy toi, clock, and write_quality.
Settings for applying knowledge updates.
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:165
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:12