MADARA  3.4.1
SystemCallGeneric.h
Go to the documentation of this file.
1 #ifndef MADARA_SYSTEM_CALL_GENERIC_H_
2 #define MADARA_SYSTEM_CALL_GENERIC_H_
3 
4 #ifndef _MADARA_NO_KARL_
5 
6 #include <string>
7 #include <stdexcept>
8 #include <functional>
12 
13 namespace madara
14 {
15 namespace expression
16 {
27 {
28 public:
30  std::vector<madara::knowledge::KnowledgeRecord>);
31 
32  using fn_type = std::function<fn_signature>;
33 
38  const ComponentNodes& nodes, const char* name, fn_type fn)
39  : SystemCallNode(context, nodes), name_(name), fn_(fn)
40  {
41  }
42 
48  {
50  }
51 
59  virtual madara::knowledge::KnowledgeRecord prune(bool& can_change)
60  {
61  can_change = true;
62  return {};
63  }
64 
71  {
72  std::vector<madara::knowledge::KnowledgeRecord> args;
73  args.reserve(nodes_.size());
74  for (const auto& node : nodes_)
75  {
76  args.emplace_back(node->evaluate(settings));
77  }
78  return fn_(std::move(args));
79  }
80 
85  virtual void accept(Visitor& visitor) const
86  {
87  visitor.visit(*this);
88  }
89 
90  const char* name() const
91  {
92  return name_;
93  }
94 
95 private:
96  const char* name_;
98 };
99 }
100 }
101 
102 #endif // _MADARA_NO_KARL_
103 
104 #endif // MADARA_SYSTEM_CALL_GENERIC_H_
madara::knowledge::KnowledgeRecord KnowledgeRecord
General purpose system call KaRL node.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
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.
madara::knowledge::KnowledgeRecord(std::vector< madara::knowledge::KnowledgeRecord >) fn_signature
std::function< fn_signature > fn_type
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
SystemCallGeneric(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes, const char *name, fn_type fn)
Constructor.
Interface for a MADARA system call.
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.
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
Copyright(c) 2020 Galois.