MADARA  3.4.1
madara::expression::VariableNode Class Reference

Defines a terminal node of that references the current value stored in a variable. More...

#include <VariableNode.h>

Inheritance diagram for madara::expression::VariableNode:
madara::expression::ComponentNode

Public Member Functions

 VariableNode (const std::string &key, madara::knowledge::ThreadSafeContext &context)
 Ctor. More...
 
virtual void accept (Visitor &visitor) const
 Define the accept() operation used for the Visitor pattern. More...
 
madara::knowledge::KnowledgeRecord dec (const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
 Atomically decrement the variable. More...
 
virtual madara::knowledge::KnowledgeRecord evaluate (const madara::knowledge::KnowledgeUpdateSettings &settings)
 Evaluates the node and its children. More...
 
std::string expand_key (void) const
 Expands the key (if necessary). More...
 
madara::knowledge::KnowledgeRecordget_record (void)
 Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls). More...
 
madara::knowledge::KnowledgeRecord inc (const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
 Atomically increment the variable. More...
 
virtual madara::knowledge::KnowledgeRecord item (void) const
 Return the item stored in the node. More...
 
const std::string & key (void) const
 Return the variable key. More...
 
virtual ComponentNodeleft (void) const
 Returns the left expression. More...
 
virtual madara::knowledge::KnowledgeRecord prune (bool &can_change)
 Prune the tree of unnecessary nodes. More...
 
virtual ComponentNoderight (void) const
 Returns the right expression. More...
 
int set (const madara::knowledge::KnowledgeRecord &value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
 Sets the value stored in the node. More...
 
int set (const madara::knowledge::KnowledgeRecord::Integer &value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
 Sets the value stored in the node. More...
 
int set (const std::string &value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
 Sets the value stored in the node. More...
 
int set (double value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
 Sets the value stored in the node. More...
 
void set_logger (logger::Logger &logger)
 Sets the logger for printing errors and debugging info. More...
 

Protected Attributes

logger::Loggerlogger_
 handle the context More...
 

Private Member Functions

std::string expand_opener (size_t opener, size_t &closer) const
 

Private Attributes

madara::knowledge::ThreadSafeContextcontext_
 
const std::string key_
 Key for retrieving value of this variable. More...
 
bool key_expansion_necessary_
 Expansion necessary. More...
 
std::vector< size_t > markers_
 
madara::knowledge::VariableReference ref_
 

Detailed Description

Defines a terminal node of that references the current value stored in a variable.

Definition at line 28 of file VariableNode.h.

Constructor & Destructor Documentation

◆ VariableNode()

madara::expression::VariableNode::VariableNode ( const std::string &  key,
madara::knowledge::ThreadSafeContext context 
)

Ctor.

Definition at line 12 of file VariableNode.cpp.

Member Function Documentation

◆ accept()

void madara::expression::VariableNode::accept ( Visitor visitor) const
virtual

Define the accept() operation used for the Visitor pattern.

Reimplemented from madara::expression::ComponentNode.

Definition at line 220 of file VariableNode.cpp.

◆ dec()

Atomically decrement the variable.

Definition at line 381 of file VariableNode.cpp.

◆ evaluate()

madara::knowledge::KnowledgeRecord madara::expression::VariableNode::evaluate ( const madara::knowledge::KnowledgeUpdateSettings settings)
virtual

Evaluates the node and its children.

This does not prune any of the expression tree, and is much faster than the prune function

Implements madara::expression::ComponentNode.

Definition at line 253 of file VariableNode.cpp.

◆ expand_key()

std::string madara::expression::VariableNode::expand_key ( void  ) const

Expands the key (if necessary).

This allow for keys to be defined with other variables inserted (e.g. var{.id} with .id = 2 expands to var2)

Definition at line 154 of file VariableNode.cpp.

◆ expand_opener()

std::string madara::expression::VariableNode::expand_opener ( size_t  opener,
size_t &  closer 
) const
private

Definition at line 90 of file VariableNode.cpp.

◆ get_record()

madara::knowledge::KnowledgeRecord* madara::expression::VariableNode::get_record ( void  )
inline

Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls).

Returns
the knowledge::KnowledgeRecord inside of the context

Definition at line 94 of file VariableNode.h.

◆ inc()

Atomically increment the variable.

Definition at line 409 of file VariableNode.cpp.

◆ item()

madara::knowledge::KnowledgeRecord madara::expression::VariableNode::item ( void  ) const
virtual

Return the item stored in the node.

Reimplemented from madara::expression::ComponentNode.

Definition at line 225 of file VariableNode.cpp.

◆ key()

const std::string & madara::expression::VariableNode::key ( void  ) const

Return the variable key.

Definition at line 293 of file VariableNode.cpp.

◆ left()

madara::expression::ComponentNode * madara::expression::ComponentNode::left ( void  ) const
virtualinherited

Returns the left expression.

Returns
a pointer to the left expression

Reimplemented in madara::expression::CompositeBinaryNode.

Definition at line 29 of file ComponentNode.cpp.

◆ prune()

madara::knowledge::KnowledgeRecord madara::expression::VariableNode::prune ( bool &  can_change)
virtual

Prune the tree of unnecessary nodes.

Returns evaluation of the node and sets can_change appropriately. if this node can be changed, that means it shouldn't be pruned.

Implements madara::expression::ComponentNode.

Definition at line 237 of file VariableNode.cpp.

◆ right()

madara::expression::ComponentNode * madara::expression::ComponentNode::right ( void  ) const
virtualinherited

Returns the right expression.

Returns
a pointer to the right expression

Reimplemented in madara::expression::CompositeUnaryNode.

Definition at line 36 of file ComponentNode.cpp.

◆ set() [1/4]

int madara::expression::VariableNode::set ( const madara::knowledge::KnowledgeRecord value,
const madara::knowledge::KnowledgeUpdateSettings settings = knowledge::KnowledgeUpdateSettings() 
)

Sets the value stored in the node.

Definition at line 298 of file VariableNode.cpp.

◆ set() [2/4]

int madara::expression::VariableNode::set ( const madara::knowledge::KnowledgeRecord::Integer value,
const madara::knowledge::KnowledgeUpdateSettings settings = knowledge::KnowledgeUpdateSettings() 
)

Sets the value stored in the node.

Definition at line 347 of file VariableNode.cpp.

◆ set() [3/4]

int madara::expression::VariableNode::set ( const std::string &  value,
const madara::knowledge::KnowledgeUpdateSettings settings = knowledge::KnowledgeUpdateSettings() 
)

Sets the value stored in the node.

Definition at line 370 of file VariableNode.cpp.

◆ set() [4/4]

int madara::expression::VariableNode::set ( double  value,
const madara::knowledge::KnowledgeUpdateSettings settings = knowledge::KnowledgeUpdateSettings() 
)

Sets the value stored in the node.

Definition at line 359 of file VariableNode.cpp.

◆ set_logger()

void madara::expression::ComponentNode::set_logger ( logger::Logger logger)
inherited

Sets the logger for printing errors and debugging info.

Parameters
loggerthe logger to use

Definition at line 48 of file ComponentNode.cpp.

Member Data Documentation

◆ context_

madara::knowledge::ThreadSafeContext& madara::expression::VariableNode::context_
private

Definition at line 109 of file VariableNode.h.

◆ key_

const std::string madara::expression::VariableNode::key_
private

Key for retrieving value of this variable.

Definition at line 106 of file VariableNode.h.

◆ key_expansion_necessary_

bool madara::expression::VariableNode::key_expansion_necessary_
private

Expansion necessary.

Definition at line 112 of file VariableNode.h.

◆ logger_

logger::Logger* madara::expression::ComponentNode::logger_
protectedinherited

handle the context

Definition at line 96 of file ComponentNode.h.

◆ markers_

std::vector<size_t> madara::expression::VariableNode::markers_
private

Definition at line 114 of file VariableNode.h.

◆ ref_

madara::knowledge::VariableReference madara::expression::VariableNode::ref_
private

Definition at line 107 of file VariableNode.h.


The documentation for this class was generated from the following files: