MADARA  3.4.1
SystemCallToBuffer.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
8 
10 
13  : SystemCallNode(context, nodes)
14 {
15 }
16 
17 // Dtor
19 
21  void) const
22 {
23  return madara::knowledge::KnowledgeRecord(nodes_.size());
24 }
25 
31 {
32  // user can always change a function, and we have no control over
33  // what it does. Consequently, a function node cannot be pruned out
34  // under any situation
35  can_change = true;
36 
38 
39  if (nodes_.size() > 0)
40  {
41  bool arg_can_change = false;
42  result = nodes_[0]->prune(arg_can_change);
43 
44  if (!arg_can_change && dynamic_cast<LeafNode*>(nodes_[0]) == 0)
45  {
46  delete nodes_[0];
47  nodes_[0] = new LeafNode(*(this->logger_), result);
48  }
49  }
50 
51  return result;
52 }
53 
59 {
60  knowledge::KnowledgeRecord return_value;
61 
62  if (nodes_.size() > 0)
63  {
65  "madara::expression::SystemCallToBuffer: "
66  "System call to_buffer is converting an argument to an "
67  "unmanaged buffer\n");
68 
69  size_t size;
70  unsigned char* buffer =
71  nodes_[0]->evaluate(settings).to_unmanaged_buffer(size);
72 
73  return_value.set_file(buffer, size);
74  }
75  else
76  {
78  "madara::expression::SystemCallToBuffer: "
79  "KARL RUNTIME ERROR:"
80  "System call to_buffer requires an argument\n");
81 
83  "madara::expression::SystemCallToBuffer: "
84  "KARL RUNTIME ERROR: "
85  "System call to_buffer requires an argument\n");
86  }
87 
88  return return_value;
89 }
90 
91 // accept a visitor
93  madara::expression::Visitor& visitor) const
94 {
95  visitor.visit(*this);
96 }
97 
98 #endif // _MADARA_NO_KARL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
madara::knowledge::KnowledgeRecord KnowlegeRecord
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:21
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Definition: LeafNode.h:25
Interface for a MADARA system call.
SystemCallToBuffer(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual ~SystemCallToBuffer(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:93
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
This class encapsulates an entry in a KnowledgeBase.
void set_file(const unsigned char *new_value, size_t size)
sets the value to an unknown file type
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes