2 #ifndef _MADARA_NO_KARL_
36 for (ComponentNodes::iterator i = nodes_.begin(); i != nodes_.end(); ++i)
38 bool arg_can_change =
false;
39 result = (*i)->prune(arg_can_change);
41 if (!arg_can_change &&
dynamic_cast<LeafNode*
>(*i) == 0)
44 *i =
new LeafNode(*(this->logger_), result);
48 if (nodes_.size() > 3)
51 "madara::expression::SystemCallRandInt: "
53 "System call rand_int"
54 " can have up to three arguments, 1) floor, "
55 "2) ceiling and 3) whether to set the random seed\n");
58 "madara::expression::SystemCallRandInt: "
59 "KARL COMPILE ERROR: "
60 "System call rand_int"
61 " can have up to three arguments, 1) floor, "
62 "2) ceiling and 3) whether to set the random seed\n");
74 int64_t floor(0), ceiling(1);
75 bool update_srand =
true;
77 if (nodes_.size() > 0)
79 floor = nodes_[0]->evaluate(settings).to_integer();
81 if (nodes_.size() > 1)
83 ceiling = nodes_[1]->evaluate(settings).to_integer();
85 if (nodes_.size() > 2)
87 update_srand = nodes_[2]->evaluate(settings).to_integer() != 0;
93 "madara::expression::SystemCallRandInt: "
94 "System call rand_int called with %" PRId64
", %" PRId64
", %d.\n",
95 floor, ceiling, update_srand);
105 visitor.
visit(*
this);
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for unrecoverable KaRL compilation issues.
Defines a node that contains a madara::knowledge::KnowledgeRecord::Integer value.
Interface for a MADARA system call.
virtual void accept(Visitor &visitor) const
Accepts a visitor subclassed from the Visitor class.
SystemCallRandInt(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 evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the expression tree.
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prunes the expression tree of unnecessary nodes.
virtual ~SystemCallRandInt(void)
Destructor.
Abstract base class for all visitors to all classes that derive from ComponentNode.
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
int64_t rand_int(int64_t floor, int64_t ceiling, bool set_seed_to_time)
Returns a random integer between a floor and ceiling.