MADARA  3.1.8
SystemCallSize.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
8 
9 
12  const ComponentNodes & nodes)
13  : SystemCallNode (context, nodes)
14 {
15 
16 }
17 
18 // Dtor
20 {
21 }
22 
25 {
27 }
28 
34 {
35  // user can always change a function, and we have no control over
36  // what it does. Consequently, a function node cannot be pruned out
37  // under any situation
38  can_change = true;
39 
41 
42  if (nodes_.size () > 0)
43  {
44  bool arg_can_change = false;
45  result = nodes_[0]->prune (arg_can_change);
46 
47  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
48  {
49  delete nodes_[0];
50  nodes_[0] = new LeafNode (*(this->logger_), result);
51  }
52  }
53  else
54  {
56  "KARL COMPILE ERROR: System call size requires an argument\n");
57  }
58 
59  return result;
60 }
61 
67 {
68  knowledge::KnowledgeRecord return_value;
69 
70  if (nodes_.size () > 0)
71  {
73  "System call size is returning the size of its first argument\n");
74 
76  nodes_[0]->evaluate (settings).size ());
77  }
78  else
79  {
81  "KARL RUNTIME ERROR: System call size requires an argument\n");
82  }
83 
84  return return_value;
85 }
86 
87 // accept a visitor
88 void
90  madara::expression::Visitor &visitor) const
91 {
92  visitor.visit (*this);
93 }
94 
95 #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
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:96
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.
#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:90
SystemCallSize(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
Interface for a MADARA system call.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual ~SystemCallSize(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.