MADARA  3.4.1
VariableNode.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _MADARA_VARIABLE_NODE_H_
3 #define _MADARA_VARIABLE_NODE_H_
4 
5 #ifndef _MADARA_NO_KARL_
6 
7 #include <string>
8 #include <vector>
9 
14 
15 namespace madara
16 {
17 namespace expression
18 {
19 // Forward declarations.
20 class Visitor;
21 
29 {
30 public:
34 
36  virtual madara::knowledge::KnowledgeRecord item(void) const;
37 
42 
44  int set(
45  double value, const madara::knowledge::KnowledgeUpdateSettings& settings =
47 
49  int set(const std::string& value,
52 
54  int set(const madara::knowledge::KnowledgeRecord& value,
57 
62 
67 
71  virtual madara::knowledge::KnowledgeRecord prune(bool& can_change);
72 
77 
81  std::string expand_key(void) const;
82 
84  const std::string& key(void) const;
85 
87  virtual void accept(Visitor& visitor) const;
88 
95  {
96  if (ref_.is_valid())
97  return ref_.get_record_unsafe();
98  else
99  return context_.get_record(expand_key());
100  }
101 
102 private:
103  std::string expand_opener(size_t opener, size_t& closer) const;
104 
108 
110 
113 
114  std::vector<size_t> markers_;
115 
117 };
118 }
119 }
120 
121 #endif // _MADARA_NO_KARL_
122 
123 #endif /* _MADARA_VARIABLE_NODE_H_ */
An abstract base class defines a simple abstract implementation of an expression tree node.
Definition: ComponentNode.h:37
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:29
std::string expand_opener(size_t opener, size_t &closer) const
madara::knowledge::ThreadSafeContext & context_
Definition: VariableNode.h:109
const std::string & key(void) const
Return the variable key.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node and its children.
VariableNode(const std::string &key, madara::knowledge::ThreadSafeContext &context)
Ctor.
const std::string key_
Key for retrieving value of this variable.
Definition: VariableNode.h:106
virtual void accept(Visitor &visitor) const
Define the accept() operation used for the Visitor pattern.
madara::knowledge::KnowledgeRecord * get_record(void)
Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls).
Definition: VariableNode.h:94
bool key_expansion_necessary_
Expansion necessary.
Definition: VariableNode.h:112
std::vector< size_t > markers_
Definition: VariableNode.h:114
madara::knowledge::VariableReference ref_
Definition: VariableNode.h:107
int set(const madara::knowledge::KnowledgeRecord::Integer &value, const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Sets the value stored in the node.
madara::knowledge::KnowledgeRecord dec(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Atomically decrement the variable.
madara::knowledge::KnowledgeRecord inc(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Atomically increment the variable.
std::string expand_key(void) const
Expands the key (if necessary).
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prune the tree of unnecessary nodes.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:93
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...
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
Optimized reference to a variable within the knowledge base.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
KnowledgeRecord * get_record_unsafe(void) const
Returns a pointer to the variable's KnowledgeRecord Do not use this pointer unless you've locked the ...
constexpr string_t string
Copyright(c) 2020 Galois.