MADARA  3.4.1
SystemCallSetClock.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
9 
12  : SystemCallNode(context, nodes)
13 {
14 }
15 
16 // Dtor
18 
20  void) const
21 {
22  return madara::knowledge::KnowledgeRecord(nodes_.size());
23 }
24 
30 {
31  // user can always change a function, and we have no control over
32  // what it does. Consequently, a function node cannot be pruned out
33  // under any situation
34  can_change = true;
35 
37 
38  for (ComponentNodes::iterator i = nodes_.begin(); i != nodes_.end(); ++i)
39  {
40  bool arg_can_change = false;
41  result = (*i)->prune(arg_can_change);
42 
43  if (!arg_can_change && dynamic_cast<LeafNode*>(*i) == 0)
44  {
45  delete *i;
46  *i = new LeafNode(*(this->logger_), result);
47  }
48  }
49 
50  if (nodes_.size() > 2 || nodes_.size() == 0)
51  {
53  "madara::expression::SystemCallSetClock: "
54  "KARL COMPILE ERROR: System call set_clock requires 1-2 arguments, "
55  "e.g., set_clock (5) or set_clock (var, 5)\n");
56  }
57 
58  return result;
59 }
60 
66 {
67  knowledge::KnowledgeRecord return_value;
68 
69  if (nodes_.size() == 1)
70  {
72  "madara::expression::SystemCallSetClock: "
73  "System call set_clock is setting the system clock\n");
74 
75  context_.set_clock(nodes_[0]->evaluate(settings).to_integer());
76 
77  return madara::knowledge::KnowledgeRecord(context_.get_clock());
78  }
79  else if (nodes_.size() == 2)
80  {
82  "madara::expression::SystemCallSetClock: "
83  "System call set_clock is setting a variable clock\n");
84 
85  VariableNode* variable = dynamic_cast<VariableNode*>(nodes_[0]);
86  if (variable)
87  {
88  variable->get_record()->clock =
89  (uint64_t)nodes_[1]->evaluate(settings).to_integer();
90 
92  }
93  else
94  {
96  "madara::expression::SystemCallSetClock: "
97  "KARL RUNTIME ERROR:"
98  "System call set_clock with 2 arguments "
99  "requires the first argument to be a variable\n");
100 
102  "madara::expression::SystemCallSetClock: "
103  "KARL RUNTIME ERROR: "
104  "System call set_clock with 2 arguments "
105  "requires the first argument to be a variable\n");
106  }
107  }
108  else
109  {
111  "madara::expression::SystemCallSetClock: "
112  "KARL RUNTIME ERROR:"
113  "System call set_clock requires 1-2 arguments, "
114  "e.g., set_clock (5) or set_clock (var, 5)\n");
115 
117  "madara::expression::SystemCallSetClock: "
118  "KARL RUNTIME ERROR: "
119  "System call set_clock requires 1-2 arguments, "
120  "e.g., set_clock (5) or set_clock (var, 5)\n");
121  }
122 
123  return return_value;
124 }
125 
126 // accept a visitor
128  madara::expression::Visitor& visitor) const
129 {
130  visitor.visit(*this);
131 }
132 
133 #endif // _MADARA_NO_KARL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:21
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Definition: LeafNode.h:25
Interface for a MADARA system call.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual ~SystemCallSetClock(void)
Destructor.
SystemCallSetClock(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
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 expression tree.
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:29
madara::knowledge::KnowledgeRecord * get_record(void)
Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls).
Definition: VariableNode.h:94
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.
uint64_t clock
last modification lamport clock time
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes