MADARA  3.4.1
SystemCallClearVariable.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
8 
11  : SystemCallNode(context, nodes)
12 {
13 }
14 
15 // Dtor
17 
20 {
21  return madara::knowledge::KnowledgeRecord(nodes_.size());
22 }
23 
29 {
30  // user can always change a function, and we have no control over
31  // what it does. Consequently, a function node cannot be pruned out
32  // under any situation
33  can_change = true;
34 
36 
37  if (nodes_.size() == 1)
38  {
39  bool arg_can_change = false;
40  result = nodes_[0]->prune(arg_can_change);
41 
42  if (!arg_can_change && dynamic_cast<LeafNode*>(nodes_[0]) == 0)
43  {
44  delete nodes_[0];
45  nodes_[0] = new LeafNode(*(this->logger_), result);
46  }
47  }
48  else
49  {
51  "madara::expression::SystemCallClearVariable: "
52  "KARL COMPILE ERROR:"
53  "System call clear requires 1 argument,"
54  "e.g., #clear ('var')\n");
55 
57  "madara::expression::SystemCallClearVariable: "
58  "KARL COMPILE ERROR: "
59  "System call clear requires 1 argument,"
60  "e.g., #clear ('var')\n");
61  }
62 
63  return result;
64 }
65 
71 {
72  knowledge::KnowledgeRecord return_value;
73 
74  if (nodes_.size() == 1)
75  {
76  std::string name = nodes_[0]->evaluate(settings).to_string();
77 
79  "madara::expression::SystemCallClearVariable: "
80  "System call clear is clearing variable "
81  "%s\n",
82  name.c_str());
83 
84  return knowledge::KnowledgeRecord(context_.clear(name));
85  }
86  else
87  {
89  "madara::expression::SystemCallClearVariable: "
90  "KARL RUNTIME ERROR:"
91  "System call clear requires 1 argument,"
92  "e.g., #clear ('var')\n");
93 
95  "madara::expression::SystemCallClearVariable: "
96  "KARL RUNTIME ERROR: "
97  "System call clear requires 1 argument,"
98  "e.g., #clear ('var')\n");
99  }
100 
101  return return_value;
102 }
103 
104 // accept a visitor
106  madara::expression::Visitor& visitor) const
107 {
108  visitor.visit(*this);
109 }
110 
111 #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
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
SystemCallClearVariable(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
Interface for a MADARA system call.
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.
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
constexpr string_t string