MADARA  3.1.8
SystemCallTan.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 #include <math.h>
5 
10 
11 
14  const ComponentNodes & nodes)
15  : SystemCallNode (context, nodes)
16 {
17 
18 }
19 
20 // Dtor
22 {
23 }
24 
27 {
29 }
30 
36 {
38 
39  if (nodes_.size () == 1)
40  {
41  bool arg_can_change = false;
43  tan (nodes_[0]->prune (arg_can_change).to_double ()));
44 
45  if (!arg_can_change && dynamic_cast <LeafNode *> (nodes_[0]) == 0)
46  {
47  delete nodes_[0];
48  nodes_[0] = new LeafNode (*(this->logger_), result);
49  }
50 
51  can_change = can_change || arg_can_change;
52  }
53  else
54  {
55  std::stringstream args;
56 
57  for (unsigned int i = 0; i < nodes_.size (); ++i)
58  {
59  if (nodes_[i])
60  {
61  bool unused = false;
62  args << nodes_[i]->prune (unused).to_double ();
63 
64  if (i != nodes_.size () - 1)
65  args << ",";
66  }
67  else
68  {
70  "KARL COMPILE ERROR: System call tan encountered a null arg at %d\n",
71  i);
72  }
73  }
74 
76  "KARL COMPILE ERROR: System call tan requires 1 argument,"
77  "e.g., #tan (1.5), where 1.5 is radians. Args currently are: %s\n",
78  args.str ().c_str ());
79  }
80 
81  return result;
82 }
83 
89 {
90  knowledge::KnowledgeRecord return_value;
91 
92  if (nodes_.size () == 1)
93  {
95  "System call tan is returning the tangent "
96  "of its first argument\n");
97 
98  return_value = knowledge::KnowledgeRecord (
99  tan (nodes_[0]->evaluate (settings).to_double ()));
100  }
101  else
102  {
104  "KARL RUNTIME ERROR: System call tan requires 1 argument,"
105  " e.g., #tan (1.5), where 1.5 is radians\n");
106  }
107 
108  return return_value;
109 }
110 
111 // accept a visitor
112 void
114 madara::expression::Visitor &visitor) const
115 {
116  visitor.visit (*this);
117 }
118 
119 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
SystemCallTan(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::deque< ComponentNode * > ComponentNodes
a vector of Component Nodes
logger::Logger * logger_
handle the context
Definition: ComponentNode.h:96
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 madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual ~SystemCallTan(void)
Destructor.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:90
Interface for a MADARA system call.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.