MADARA  3.2.3
SystemCallEval.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
10 
11 
14  const ComponentNodes & nodes)
15  : SystemCallNode (context, nodes)
16 {
17 
18 }
19 
20 // Dtor
22 {
23 }
24 
27 {
29 }
30 
36 {
37  // user can always change a function, and we have no control over
38  // what it does. Consequently, a function node cannot be pruned out
39  // under any situation
40  can_change = true;
41 
43 
44  if (nodes_.size () > 0)
45  {
46  bool arg_can_change = false;
47  result = nodes_[0]->prune (arg_can_change);
48 
49  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
50  {
51  delete nodes_[0];
52  nodes_[0] = new LeafNode (*(this->logger_), result);
53  }
54  }
55  else
56  {
58  "madara::expression::SystemCallEval: "
59  "KARL COMPILE ERROR:"
60  "System call eval requires an argument\n");
61 
62  throw KarlException ("madara::expression::SystemCallEval: "
63  "KARL COMPILE ERROR: "
64  "System call eval requires an argument\n");
65  }
66 
67  return result;
68 }
69 
75 {
76  knowledge::KnowledgeRecord return_value;
77 
78  if (nodes_.size () > 0)
79  {
81  "madara::expression::SystemCallEval: "
82  "System call type is returning the eval of its first argument\n");
83 
85  nodes_[0]->evaluate (settings).to_string ());
86 
87  return expression.expression.evaluate (settings);
88  }
89  else
90  {
92  "madara::expression::SystemCallEval: "
93  "KARL RUNTIME ERROR:"
94  "System call eval requires an argument\n");
95 
96  throw KarlException ("madara::expression::SystemCallEval: "
97  "KARL RUNTIME ERROR: "
98  "System call eval requires an argument\n");
99  }
100 
101  return return_value;
102 }
103 
104 // accept a visitor
105 void
107  madara::expression::Visitor &visitor) const
108 {
109  visitor.visit (*this);
110 }
111 
112 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
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...
SystemCallEval(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
Compiled, optimized KaRL logic.
madara::expression::ExpressionTree expression
the expression tree
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
virtual ~SystemCallEval(void)
Destructor.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:91
madara::knowledge::ThreadSafeContext & context_
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
Interface for a MADARA system call.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
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.
madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Evaluates the expression tree.