2 #ifndef _MADARA_NO_KARL_ 14 :
ComponentNode (context.get_logger ()), key_ (key), record_ (0),
15 context_ (context), key_expansion_necessary_ (false)
20 if (key.find (
"{") != key.npos)
23 "Variable %s requires variable expansion.\n",
29 for (
size_t i = 0; i < key.size (); ++i)
36 else if (key[i] ==
'}')
46 "KARL COMPILE ERROR: " \
47 "Expanded variable name has a leading closing brace " 48 "instead of opening closing brace at %d\n",
59 "KARL COMPILE ERROR: " \
60 "Variable name has more opening braces than closing in %s\n",
65 else if (num_opens < 0)
68 "KARL COMPILE ERROR: " \
69 "Variable name has more closing braces than opening in %s\n",
89 size_t opener,
size_t & closer)
const 91 size_t i = opener + 1;
94 std::stringstream builder;
97 "VariableNode:expand_opener: key=%s, opener_index=%d, start=%d.\n",
98 key_.c_str (), (int)opener);
109 "VariableNode:expand_opener: %d-%d{: added %d chars.\n",
113 size_t sub_opener = i;
116 "VariableNode:expand_opener: get_record(expand_opener()) " 117 "expand_opener(%d, %d).\n",
118 (
int)sub_opener, (
int)i);
132 "VariableNode:expand_opener(%d,%d): {%d-%d}: added %d chars.\n",
133 (
int)opener, (
int)closer, (
int)start, (
int)end, (
int)(end-start));
141 "VariableNode:expand_opener(%d,%d): return %s\n",
142 (
int)opener, (
int)closer, result.c_str ());
153 "VariableNode:expand_key: Variable %s requires variable expansion" 161 std::stringstream builder;
172 "VariableNode:expand_key: %d-%d{: added %d chars.\n",
179 "VariableNode:expand_key: adding results of " 180 "expand_opener(%d, %d).\n",
181 (
int)opener, (
int)i);
188 if (start <
key_.size () &&
key_.size () - start > 0)
191 "VariableNode:expand_key: substr add from index %d, %d chars.\n",
192 (
int)start, (
int)
key_.size () - start);
193 builder <<
key_.substr (start,
key_.size () - start);
199 "VariableNode:expand_key: return %s\n",
214 visitor.
visit (*
this);
274 "VariableNode::set: " 275 "Attempting to set variable %s to a KnowledgeRecord parameter (%s).\n",
299 "VariableNode::set: " 300 "Setting variable %s with KnowledgeRecord assignment operator.\n",
318 "VariableNode::set: " 319 "Attempting to set variable %s to an Integer parameter (%d).\n",
320 key_.c_str (), (int)value);
350 "VariableNode::set: " 351 "Attempting to set variable %s to a double parameter (%f).\n",
352 key_.c_str (), value);
382 "VariableNode::set: " 383 "Attempting to set variable %s to a string parameter (%s).\n",
384 key_.c_str (), value.c_str ());
463 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord dec(const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically decrements the value of the variable.
madara::knowledge::KnowledgeRecord dec(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Atomically decrement the variable.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
uint32_t quality
priority of the update
madara::knowledge::ThreadSafeContext & context_
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node and its children.
madara::knowledge::KnowledgeRecord * record_
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prune the tree of unnecessary nodes.
logger::Logger * logger_
handle the context
This class stores variables and their values for use by any entity needing state information in a thr...
const std::string key_
Key for retrieving value of this variable.
std::vector< size_t > markers_
void set_value(const KnowledgeRecord &new_value)
Sets the value from another KnowledgeRecord, does not copy clock and write_quality.
const std::string & key(void) const
Return the variable key.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
int set(const madara::knowledge::KnowledgeRecord::Integer &value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Sets the value stored in the node.
virtual void accept(Visitor &visitor) const
Define the accept() operation used for the Visitor pattern.
madara::knowledge::KnowledgeRecord inc(const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically increments the value of the variable.
An abstract base class defines a simple abstract implementation of an expression tree node...
VariableNode(const std::string &key, madara::knowledge::ThreadSafeContext &context)
Ctor.
Abstract base class for all visitors to all classes that derive from ComponentNode.
std::string expand_opener(size_t opener, size_t &closer) const
madara::knowledge::KnowledgeRecord inc(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Atomically increment the variable.
bool always_overwrite
Toggle for always overwriting records, regardless of quality, clock values, etc.
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
uint32_t write_quality
write priority for any local updates
Settings for applying knowledge updates.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
virtual ~VariableNode(void)
Dtor.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
void mark_and_signal(const char *name, knowledge::KnowledgeRecord *record, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
method for marking a record modified and signaling changes
std::string expand_key(void) const
Expands the key (if necessary).
bool key_expansion_necessary_
Expansion necessary.