MADARA  3.2.3
SystemCallCos.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  cos (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  {
56  "madara::expression::SystemCallCos: "
57  "KARL COMPILE ERROR:"
58  "System call cos requires 1 argument,"
59  " e.g., #cos (1.5), where 1.5 is radians\n");
60 
61  throw KarlException ("madara::expression::SystemCallCos: "
62  "KARL COMPILE ERROR: "
63  "System call cos requires 1 argument,"
64  " e.g., #cos (1.5), where 1.5 is radians\n");
65  }
66 
67  return result;
68 }
69 
75 {
76  knowledge::KnowledgeRecord return_value;
77 
78  if (nodes_.size () == 1)
79  {
81  "madara::expression::SystemCallCos: "
82  "System call cos is returning the cosine "
83  "of its first argument\n");
84 
85  return_value = knowledge::KnowledgeRecord (
86  cos (nodes_[0]->evaluate (settings).to_double ()));
87  }
88  else
89  {
91  "madara::expression::SystemCallCos: "
92  "KARL RUNTIME ERROR:"
93  "System call cos requires 1 argument,"
94  " e.g., #cos (1.5), where 1.5 is radians\n");
95 
96  throw KarlException ("madara::expression::SystemCallCos: "
97  "KARL RUNTIME ERROR: "
98  "System call cos requires 1 argument,"
99  " e.g., #cos (1.5), where 1.5 is radians\n");
100  }
101 
102  return return_value;
103 }
104 
105 // accept a visitor
106 void
108 madara::expression::Visitor &visitor) const
109 {
110  visitor.visit (*this);
111 }
112 
113 #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
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
SystemCallCos(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:91
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
Interface for a MADARA system call.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual ~SystemCallCos(void)
Destructor.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.