MADARA  3.4.1
SystemCallRandDouble.cpp
Go to the documentation of this file.
1 
2 #ifndef _MADARA_NO_KARL_
3 
9 
12  : SystemCallNode(context, nodes)
13 {
14 }
15 
16 // Dtor
18 
21 {
22  return madara::knowledge::KnowledgeRecord(nodes_.size());
23 }
24 
30 {
31  can_change = true;
32 
34 
35  for (ComponentNodes::iterator i = nodes_.begin(); i != nodes_.end(); ++i)
36  {
37  bool arg_can_change = false;
38  result = (*i)->prune(arg_can_change);
39 
40  if (!arg_can_change && dynamic_cast<LeafNode*>(*i) == 0)
41  {
42  delete *i;
43  *i = new LeafNode(*(this->logger_), result);
44  }
45  }
46 
47  if (nodes_.size() > 3)
48  {
50  "madara::expression::SystemCallRandDouble: "
51  "KARL COMPILE ERROR:"
52  "System call rand_double"
53  " can have up to three arguments, 1) floor, "
54  "2) ceiling and 3) whether to set the random seed\n");
55 
57  "madara::expression::SystemCallRandDouble: "
58  "KARL COMPILE ERROR: "
59  "System call rand_double"
60  " can have up to three arguments, 1) floor, "
61  "2) ceiling and 3) whether to set the random seeds\n");
62  }
63 
64  return result;
65 }
66 
72 {
73  double floor(0.0), ceiling(1.0);
74  bool update_srand = true;
75 
76  if (nodes_.size() > 0)
77  {
78  floor = nodes_[0]->evaluate(settings).to_double();
79 
80  if (nodes_.size() > 1)
81  {
82  ceiling = nodes_[1]->evaluate(settings).to_double();
83 
84  if (nodes_.size() > 2)
85  {
86  update_srand = nodes_[2]->evaluate(settings).to_integer() != 0;
87  }
88  }
89  }
90 
92  "madara::expression::SystemCallRandDouble: "
93  "System call rand_double called with %f, %f, %d\n",
94  floor, ceiling, update_srand);
95 
97  utility::rand_double(floor, ceiling, update_srand));
98 }
99 
100 // accept a visitor
102  madara::expression::Visitor& visitor) const
103 {
104  visitor.visit(*this);
105 }
106 
107 #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 item(void) const
Returns the value of the node.
SystemCallRandDouble(madara::knowledge::ThreadSafeContext &context, const ComponentNodes &nodes)
Constructor.
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 madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
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
double rand_double(double floor, double ceiling, bool set_seed_to_time)
Returns a random double between floor and ceiling.
Definition: Utility.cpp:520