MADARA  3.1.8
SystemCallRandDouble.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
4 
10 
11 
14  const ComponentNodes & nodes)
15  : SystemCallNode (context, nodes)
16 {
17 
18 }
19 
20 // Dtor
22 {
23 }
24 
27 {
29 }
30 
36 {
37  can_change = true;
38 
40 
41  for (ComponentNodes::iterator i = nodes_.begin (); i != nodes_.end ();
42  ++i)
43  {
44  bool arg_can_change = false;
45  result = (*i)->prune (arg_can_change);
46 
47  if (!arg_can_change && dynamic_cast <LeafNode *> (*i) == 0)
48  {
49  delete *i;
50  *i = new LeafNode (*(this->logger_), result);
51  }
52  }
53 
54  if (nodes_.size () > 3)
55  {
57  "KARL COMPILE ERROR: System call rand_double"
58  " can have up to three arguments, 1) floor, "
59  "2) ceiling and 3) whether to set the random seed\n");
60  }
61 
62  return result;
63 }
64 
70 {
71  double floor (0.0), ceiling (1.0);
72  bool update_srand = true;
73 
74  if (nodes_.size () > 0)
75  {
76  floor = nodes_[0]->evaluate (settings).to_double ();
77 
78  if (nodes_.size () > 1)
79  {
80  ceiling = nodes_[1]->evaluate (settings).to_double ();
81 
82  if (nodes_.size () > 2)
83  {
84  update_srand = bool (nodes_[2]->evaluate (settings).to_integer ());
85  }
86  }
87  }
88 
90  "System call rand_double called with %f, %f, %d\n",
91  floor, ceiling, update_srand);
92 
94  utility::rand_double (floor, ceiling, update_srand));
95 }
96 
97 // accept a visitor
98 void
100  madara::expression::Visitor &visitor) const
101 {
102  visitor.visit (*this);
103 }
104 
105 #endif // _MADARA_NO_KARL_
This class encapsulates an entry in a KnowledgeBase.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
SystemCallRandDouble(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
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...
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value. ...
Definition: LeafNode.h:23
MADARA_Export double rand_double(double floor=0.0, double ceiling=1.0, bool set_seed_to_time=true)
Returns a random double between floor and ceiling.
Definition: Utility.cpp:815
#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 prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.