MADARA  3.4.1
SystemCallSin.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  sin(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  {
51  "madara::expression::SystemCallSin: "
52  "KARL COMPILE ERROR:"
53  "System call sin requires 1 argument,"
54  " e.g., #sin (1.5), where 1.5 is radians\n");
55 
57  "madara::expression::SystemCallSin: "
58  "KARL COMPILE ERROR: "
59  "System call sin requires 1 argument,"
60  " e.g., #sin (1.5), where 1.5 is radians\n");
61  }
62 
63  return result;
64 }
65 
70 {
71  knowledge::KnowledgeRecord return_value;
72 
73  if (nodes_.size() == 1)
74  {
76  "madara::expression::SystemCallSin: "
77  "System call sin is returning the sin "
78  "of its first argument\n");
79 
81  sin(nodes_[0]->evaluate(settings).to_double()));
82  }
83  else
84  {
86  "madara::expression::SystemCallSin: "
87  "KARL RUNTIME ERROR:"
88  "System call sin requires 1 argument,"
89  " e.g., #sin (1.5), where 1.5 is radians\n");
90 
92  "madara::expression::SystemCallSin: "
93  "KARL RUNTIME ERROR: "
94  "System call sin requires 1 argument,"
95  " e.g., #sin (1.5), where 1.5 is radians\n");
96  }
97 
98  return return_value;
99 }
100 
101 // accept a visitor
103  madara::expression::Visitor& visitor) const
104 {
105  visitor.visit(*this);
106 }
107 
108 #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 void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
SystemCallSin(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
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 ~SystemCallSin(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
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