MADARA  3.2.3
SystemCallDeleteVariable.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
9 
10 
13  const ComponentNodes & nodes)
14  : SystemCallNode (context, nodes)
15 {
16 
17 }
18 
19 // Dtor
21 {
22 }
23 
26 {
28 }
29 
35 {
36  // user can always change a function, and we have no control over
37  // what it does. Consequently, a function node cannot be pruned out
38  // under any situation
39  can_change = true;
40 
42 
43  if (nodes_.size () == 1)
44  {
45  bool arg_can_change = false;
46  result = nodes_[0]->prune (arg_can_change);
47 
48  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
49  {
50  delete nodes_[0];
51  nodes_[0] = new LeafNode (*(this->logger_), result);
52  }
53  }
54  else
55  {
57  "madara::expression::SystemCallDeleteVariable: "
58  "KARL COMPILE ERROR:"
59  "System call delete_variable requires 1 argument,"
60  "e.g., #delete_variable ('var')\n");
61 
62  throw KarlException ("madara::expression::SystemCallDeleteVariable: "
63  "KARL COMPILE ERROR: "
64  "System call delete_variable requires 1 argument,"
65  "e.g., #delete_variable ('var')\n");
66  }
67 
68 
69  return result;
70 }
71 
77 {
78  knowledge::KnowledgeRecord return_value;
79 
80  if (nodes_.size () == 1)
81  {
83  "madara::expression::SystemCallDeleteVariable: "
84  "System call delete_variable is returning the clock "
85  "of its first argument\n");
86 
89  nodes_[0]->evaluate (settings).to_string ()));
90  }
91  else
92  {
94  "madara::expression::SystemCallDeleteVariable: "
95  "KARL RUNTIME ERROR:"
96  "System call delete_variable requires 1 argument,"
97  "e.g., #delete_variable ('var')\n");
98 
99  throw KarlException ("madara::expression::SystemCallDeleteVariable: "
100  "KARL RUNTIME ERROR: "
101  "System call delete_variable requires 1 argument,"
102  "e.g., #delete_variable ('var')\n");
103  }
104 
105  return return_value;
106 }
107 
108 // accept a visitor
109 void
111  madara::expression::Visitor &visitor) const
112 {
113  visitor.visit (*this);
114 }
115 
116 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord KnowledgeRecord
SystemCallDeleteVariable(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:97
This class stores variables and their values for use by any entity needing state information in a thr...
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
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.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:91
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
madara::knowledge::ThreadSafeContext & context_
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
Interface for a MADARA system call.
bool delete_variable(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Deletes the key.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.