MADARA  3.2.3
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  "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 seed\n");
62 
63  throw KarlException ("madara::expression::SystemCallRandDouble: "
64  "KARL COMPILE ERROR: "
65  "System call rand_double"
66  " can have up to three arguments, 1) floor, "
67  "2) ceiling and 3) whether to set the random seeds\n");
68  }
69 
70  return result;
71 }
72 
78 {
79  double floor (0.0), ceiling (1.0);
80  bool update_srand = true;
81 
82  if (nodes_.size () > 0)
83  {
84  floor = nodes_[0]->evaluate (settings).to_double ();
85 
86  if (nodes_.size () > 1)
87  {
88  ceiling = nodes_[1]->evaluate (settings).to_double ();
89 
90  if (nodes_.size () > 2)
91  {
92  update_srand = nodes_[2]->evaluate (settings).to_integer () != 0;
93  }
94  }
95  }
96 
98  "madara::expression::SystemCallRandDouble: "
99  "System call rand_double called with %f, %f, %d\n",
100  floor, ceiling, update_srand);
101 
103  utility::rand_double (floor, ceiling, update_srand));
104 }
105 
106 // accept a visitor
107 void
109  madara::expression::Visitor &visitor) const
110 {
111  visitor.visit (*this);
112 }
113 
114 #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:97
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
#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:91
An exception for unrecoverable KaRL compilation issues.
Definition: KarlException.h:18
Interface for a MADARA system call.
double rand_double(double floor, double ceiling, bool set_seed_to_time)
Returns a random double between floor and ceiling.
Definition: Utility.cpp:580
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.