MADARA  3.4.1
SystemCallTan.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 #include <math.h>
5 
10 
13  : SystemCallNode(context, nodes)
14 {
15 }
16 
17 // Dtor
19 
21  void) const
22 {
23  return madara::knowledge::KnowledgeRecord(nodes_.size());
24 }
25 
30  bool& can_change)
31 {
33 
34  if (nodes_.size() == 1)
35  {
36  bool arg_can_change = false;
38  tan(nodes_[0]->prune(arg_can_change).to_double()));
39 
40  if (!arg_can_change && dynamic_cast<LeafNode*>(nodes_[0]) == 0)
41  {
42  delete nodes_[0];
43  nodes_[0] = new LeafNode(*(this->logger_), result);
44  }
45 
46  can_change = can_change || arg_can_change;
47  }
48  else
49  {
50  std::stringstream args;
51 
52  for (unsigned int i = 0; i < nodes_.size(); ++i)
53  {
54  if (nodes_[i])
55  {
56  bool unused = false;
57  args << nodes_[i]->prune(unused).to_double();
58 
59  if (i != nodes_.size() - 1)
60  args << ",";
61  }
62  else
63  {
65  "madara::expression::SystemCallTan: "
66  "KARL COMPILE ERROR: System call tan encountered a null arg at "
67  "%d\n",
68  i);
69  }
70  }
71 
73  "madara::expression::SystemCallTan: "
74  "KARL COMPILE ERROR:"
75  "System call tan requires 1 argument,"
76  " e.g., #tan (1.5), where 1.5 is radians. Args currently are: %s\n",
77  args.str().c_str());
78 
80  "madara::expression::SystemCallTan: "
81  "KARL COMPILE ERROR: "
82  "System call tan requires 1 argument,"
83  " e.g., #tan (1.5), where 1.5 is radians. Args currently are: " +
84  args.str());
85  }
86 
87  return result;
88 }
89 
94 {
95  knowledge::KnowledgeRecord return_value;
96 
97  if (nodes_.size() == 1)
98  {
100  "madara::expression::SystemCallTan: "
101  "System call tan is returning the tangent "
102  "of its first argument\n");
103 
104  return_value = knowledge::KnowledgeRecord(
105  tan(nodes_[0]->evaluate(settings).to_double()));
106  }
107  else
108  {
110  "madara::expression::SystemCallTan: "
111  "KARL RUNTIME ERROR:"
112  "System call tan requires 1 argument,"
113  " e.g., #tan (1.5), where 1.5 is radians\n");
114 
116  "madara::expression::SystemCallTan: "
117  "KARL RUNTIME ERROR: "
118  "System call tan requires 1 argument,"
119  " e.g., #tan (1.5), where 1.5 is radians\n");
120  }
121 
122  return return_value;
123 }
124 
125 // accept a visitor
127  madara::expression::Visitor& visitor) const
128 {
129  visitor.visit(*this);
130 }
131 
132 #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 madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual ~SystemCallTan(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
SystemCallTan(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
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