2 #ifndef _MADARA_NO_KARL_ 16 key_ (key), record_ (0),
17 context_ (context), key_expansion_necessary_ (false)
22 if (key.find (
"{") != key.npos)
25 "Variable %s requires variable expansion.\n",
37 "KARL COMPILE ERROR: matching braces not found in %s\n",
44 std::vector<std::string>::const_iterator pivot =
pivot_list_.begin ();
45 unsigned int num_opens = 0;
46 unsigned int num_closes = 0;
54 else if (*pivot ==
"}")
60 if (num_opens > num_closes)
63 "KARL COMPILE ERROR: Array name has " 64 "more opening braces than closing in %s\n",
69 else if (num_closes > num_opens)
72 "KARL COMPILE ERROR: Array name has " 73 "more closing braces than opening in %s\n",
99 "Variable %s requires variable expansion\n",
102 unsigned int count = 0;
105 std::stringstream builder;
106 std::vector< std::string>::const_iterator token =
tokens_.begin ();
110 for (++token, ++count; token !=
tokens_.end (); ++token, ++count)
127 return builder.str ();
139 visitor.
visit (*
this);
280 int return_value = 0;
283 return_value =
set (value.
to_integer (), settings);
285 return_value =
set (value.
to_double (), settings);
346 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
std::vector< std::string > splitters_
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prune the tree of unnecessary nodes.
const std::string key_
Key for retrieving value of this variable.
KnowledgeRecord retrieve_index(const std::string &key, size_t index, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a value at a specified index within a knowledge array.
int32_t type(void) const
returns the size of the value
int set(const madara::knowledge::KnowledgeRecord::Integer &value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Sets the value stored in the node.
ComponentNode * right_
Right expression.
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::KnowledgeRecord KnowledgeRecord
double to_double(void) const
converts the value to a float/double
KnowledgeRecord inc_index(size_t index)
increments the value at the index to the specified value.
knowledge::KnowledgeRecord inc(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Sets the value stored in the node.
virtual madara::knowledge::KnowledgeRecord item(void) const
Returns the value of the node.
logger::Logger * logger_
handle the context
const std::string & key(void) const
Return the variable key.
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)=0
Evaluates the expression tree.
int set_index(const std::string &key, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of an array index to a value.
virtual void accept(Visitor &visitor) const
Define the accept() operation used for the Visitor pattern.
std::vector< std::string > pivot_list_
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
bool key_expansion_necessary_
Expansion necessary.
madara::knowledge::KnowledgeRecord * record_
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
An abstract base class defines a simple abstract implementation of an expression tree node...
Abstract base class for all visitors to all classes that derive from ComponentNode.
void set_index(size_t index, T value)
sets the value at the index to the specified value.
Integer to_integer(void) const
converts the value to an integer
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node and its children.
CompositeArrayReference(const std::string &key, ComponentNode *index, madara::knowledge::ThreadSafeContext &context)
Constructor.
knowledge::KnowledgeRecord dec(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Sets the value stored in the node.
bool always_overwrite
Toggle for always overwriting records, regardless of quality, clock values, etc.
std::vector< std::string > tokens_
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
uint32_t write_quality
write priority for any local updates
madara::knowledge::ThreadSafeContext & context_
virtual ~CompositeArrayReference(void)
Dtor.
KnowledgeRecord dec_index(size_t index)
decrements the value at the index to the specified value.
Settings for applying knowledge updates.
Encapsulates a single expression tree.
virtual void visit(const LeafNode &node)=0
Visit a LeafNode.
KnowledgeRecord retrieve_index(size_t index) const
retrieves the value at an array index.
MADARA_Export void tokenizer(const std::string &input, const ::std::vector< std::string > &splitters,::std::vector< std::string > &tokens,::std::vector< std::string > &pivot_list)
Splits an input string into tokens.
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).