MADARA  3.1.8
SystemCallPrint.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 () > 0)
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  "KARL COMPILE ERROR: System call size requires an argument\n");
58  }
59 
60  return result;
61 }
62 
68 {
69  knowledge::KnowledgeRecord return_value;
70 
71  if (nodes_.size () == 1)
72  {
74  "System call print is printing the first argument and returning the"
75  " size of the first argument\n");
76 
77  std::string statement (nodes_[0]->evaluate (settings).to_string ());
78 
79  context_.print (statement, 0);
80 
81  return_value = knowledge::KnowledgeRecord (0);
82  }
83  else if (nodes_.size () == 2)
84  {
85  std::string statement (nodes_[0]->evaluate (settings).to_string ());
86  unsigned int log_level =
87  (unsigned int) nodes_[1]->evaluate (settings).to_integer ();
88 
90  "System call print is printing the first argument at log level %d.\n",
91  log_level);
92 
93  context_.print (statement, log_level);
94 
95  return_value = knowledge::KnowledgeRecord (0);
96  }
97  else
98  {
100  "KARL RUNTIME ERROR: System call print requires an argument\n");
101  }
102 
103  return return_value;
104 }
105 
106 // accept a visitor
107 void
109  madara::expression::Visitor &visitor) const
110 {
111  visitor.visit (*this);
112 }
113 
114 #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...
void print(unsigned int level) const
Atomically prints all variables and values in the context.
virtual ~SystemCallPrint(void)
Destructor.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
SystemCallPrint(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
#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
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
Integer to_integer(void) const
converts the value to an integer
madara::knowledge::ThreadSafeContext & context_
static constexpr struct madara::knowledge::tags::string_t string
Interface for a MADARA system call.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.