MADARA  3.4.1
SystemCallToString.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
8 
11  : SystemCallNode(context, nodes)
12 {
13 }
14 
15 // Dtor
17 
19  void) const
20 {
21  return madara::knowledge::KnowledgeRecord(nodes_.size());
22 }
23 
29 {
30  // user can always change a function, and we have no control over
31  // what it does. Consequently, a function node cannot be pruned out
32  // under any situation
33  can_change = true;
34 
36 
37  for (ComponentNodes::iterator i = nodes_.begin(); i != nodes_.end(); ++i)
38  {
39  bool arg_can_change = false;
40  result = (*i)->prune(arg_can_change);
41 
42  if (!arg_can_change && dynamic_cast<LeafNode*>(*i) == 0)
43  {
44  delete *i;
45  *i = new LeafNode(*(this->logger_), result);
46  }
47  }
48 
49  return result;
50 }
51 
57 {
59 
60  if (nodes_.size() > 0)
61  {
62  std::string delimiter = ", ";
63 
64  if (nodes_.size() > 1)
65  {
66  // user wants to use a special delimiter
67  delimiter = nodes_[1]->evaluate(settings).to_string(delimiter);
68 
69  if (nodes_.size() > 2)
70  {
72  "madara::expression::SystemCallToString: "
73  "KARL RUNTIME ERROR:"
74  "System call to_string"
75  " may have up to 2 arguments. First is a value to change to string."
76  " An optional second is a delimiter for array stringification\n");
77 
79  "madara::expression::SystemCallToString: "
80  "KARL RUNTIME ERROR: "
81  "System call to_string"
82  " may have up to 2 arguments. First is a value to change to string."
83  " An optional second is a delimiter for array stringification\n");
84  }
85  }
86 
88  "madara::expression::SystemCallToString: "
89  "System call to_string is converting an argument\n");
90 
92  nodes_[0]->evaluate(settings).to_string(delimiter));
93  }
94  else
95  {
97  "madara::expression::SystemCallToString: "
98  "KARL RUNTIME ERROR:"
99  "System call to_string requires an argument\n");
100 
102  "madara::expression::SystemCallToString: "
103  "KARL RUNTIME ERROR: "
104  "System call to_string requires an argument\n");
105 
106  result.set_value("");
107  }
108 
109  return result;
110 }
111 
112 // accept a visitor
114  madara::expression::Visitor& visitor) const
115 {
116  visitor.visit(*this);
117 }
118 
119 #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 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.
virtual ~SystemCallToString(void)
Destructor.
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 madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
SystemCallToString(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
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_value(const KnowledgeRecord &new_value)
Sets the value from another KnowledgeRecord, does not copy toi, clock, and write_quality.
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
constexpr string_t string