MADARA  3.2.3
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  "madara::expression::SystemCallSize: "
57  "KARL COMPILE ERROR:"
58  "System call size requires an argument\n");
59 
60  throw KarlException ("madara::expression::SystemCallSize: "
61  "KARL COMPILE ERROR: "
62  "System call size requires an argument\n");
63  }
64 
65  return result;
66 }
67 
73 {
74  knowledge::KnowledgeRecord return_value;
75 
76  if (nodes_.size () > 0)
77  {
79  "madara::expression::SystemCallSize: "
80  "System call size is returning the size of its first argument\n");
81 
83  nodes_[0]->evaluate (settings).size ());
84  }
85  else
86  {
88  "madara::expression::SystemCallSize: "
89  "KARL RUNTIME ERROR:"
90  "System call size requires an argument\n");
91 
92  throw KarlException ("madara::expression::SystemCallSize: "
93  "KARL RUNTIME ERROR: "
94  "System call size requires an argument\n");
95  }
96 
97  return return_value;
98 }
99 
100 // accept a visitor
101 void
103  madara::expression::Visitor &visitor) const
104 {
105  visitor.visit (*this);
106 }
107 
108 #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: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.
#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
SystemCallSize(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
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.