MADARA  3.2.3
SystemCallToString.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  for (ComponentNodes::iterator i = nodes_.begin (); i != nodes_.end ();
44  ++i)
45  {
46  bool arg_can_change = false;
47  result = (*i)->prune (arg_can_change);
48 
49  if (!arg_can_change && dynamic_cast <LeafNode *> (*i) == 0)
50  {
51  delete *i;
52  *i = new LeafNode (*(this->logger_), result);
53  }
54  }
55 
56  return result;
57 }
58 
64 {
66 
67  if (nodes_.size () > 0)
68  {
69  std::string delimiter = ", ";
70 
71  if (nodes_.size () > 1)
72  {
73  // user wants to use a special delimiter
74  delimiter = nodes_[1]->evaluate (settings).to_string (delimiter);
75 
76  if (nodes_.size () > 2)
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  throw KarlException ("madara::expression::SystemCallToString: "
86  "KARL RUNTIME ERROR: "
87  "System call to_string"
88  " may have up to 2 arguments. First is a value to change to string."
89  " An optional second is a delimiter for array stringification\n");
90  }
91  }
92 
94  "madara::expression::SystemCallToString: "
95  "System call to_string is converting an argument\n");
96 
98  nodes_[0]->evaluate (settings).to_string (delimiter));
99  }
100  else
101  {
103  "madara::expression::SystemCallToString: "
104  "KARL RUNTIME ERROR:"
105  "System call to_string requires an argument\n");
106 
107  throw KarlException ("madara::expression::SystemCallToString: "
108  "KARL RUNTIME ERROR: "
109  "System call to_string requires an argument\n");
110 
111  result.set_value ("");
112  }
113 
114  return result;
115 }
116 
117 // accept a visitor
118 void
120  madara::expression::Visitor &visitor) const
121 {
122  visitor.visit (*this);
123 }
124 
125 #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
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 ~SystemCallToString(void)
Destructor.
void set_value(const KnowledgeRecord &new_value)
Sets the value from another KnowledgeRecord, does not copy clock and write_quality.
static struct madara::knowledge::tags::string_t string
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
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.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:91
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
Interface for a MADARA system call.
Settings for applying knowledge updates.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
SystemCallToString(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.