MADARA  3.4.1
CompositePostincrementNode.cpp
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _COMPOSITE_PREINCREMENT_NODE_CPP_
3 #define _COMPOSITE_PREINCREMENT_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  void)
29 {
30 }
31 
34 {
36  record.set_value("++");
37  return record;
38 }
39 
45 {
46  bool right_child_can_change = false;
48 
49  if (this->right_)
50  {
51  right_value = this->right_->prune(right_child_can_change);
52  if (!right_child_can_change && dynamic_cast<LeafNode*>(right_) == 0)
53  {
54  delete this->right_;
55  this->right_ = new LeafNode(*(this->logger_), right_value);
56  }
57  }
58  else if (!var_ && !array_)
59  {
61  "madara::expression::CompositePostdecrementNode: "
62  "KARL COMPILE ERROR:"
63  "Postincrement has no var, array, or expression\n");
64 
66  "madara::expression::CompositePostincrementNode: "
67  "KARL COMPILE ERROR: "
68  "Postincrement has no var, array, or expression\n");
69  }
70 
71  can_change = right_child_can_change;
72 
73  return ++right_value;
74 }
75 
81 {
83 
84  if (var_)
85  {
86  return_value = var_->evaluate(settings);
87  var_->inc(settings);
88  }
89  else if (array_)
90  {
91  return_value = array_->evaluate(settings);
92  array_->inc(settings);
93  }
94  else if (right_)
95  {
96  return_value = ++(this->right_->evaluate(settings));
97  }
98  else
99  {
101  "madara::expression::CompositePostincrementNode: "
102  "KARL RUNTIME ERROR: "
103  "Preincrement has no var, array, or expression\n");
104 
106  "madara::expression::CompositePostincrementNode: "
107  "KARL RUNTIME ERROR: "
108  "Preincrement has no var, array, or expression\n");
109  }
110 
111  return return_value;
112 }
113 
114 // accept a visitor
116  Visitor& visitor) const
117 {
118  visitor.visit(*this);
119 }
120 
121 #endif // _MADARA_NO_KARL_
122 
123 #endif /* _COMPOSITE_PREINCREMENT_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 item(void) const
Returns the printable character of the node.
CompositeArrayReference * array_
variable index holder
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node.
CompositePostincrementNode(logger::Logger &logger, ComponentNode *right)
Constructor.
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