MADARA  3.1.8
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 
28  class VariableNode : public ComponentNode
29  {
30  public:
32  VariableNode (const std::string &key,
34 
36  virtual ~VariableNode (void);
37 
39  virtual madara::knowledge::KnowledgeRecord item (void) const;
40 
42  int set (const madara::knowledge::KnowledgeRecord::Integer & value,
45 
47  int set (double value,
50 
52  int set (const std::string & value,
55 
57  int set (const madara::knowledge::KnowledgeRecord & value,
60 
65 
70 
74  virtual madara::knowledge::KnowledgeRecord prune (bool & can_change);
75 
80 
84  std::string expand_key (void) const;
85 
87  const std::string & key (void) const;
88 
90  virtual void accept (Visitor &visitor) const;
91 
97  inline
99  {
100  if (record_)
101  return record_;
102  else
103  return context_.get_record (expand_key ());
104  }
105 
106  private:
107 
108  std::string expand_opener (size_t opener, size_t & closer) const;
109 
113 
115 
118 
119  std::vector<size_t> markers_;
120 
122  };
123  }
124 }
125 
126 #endif // _MADARA_NO_KARL_
127 
128 #endif /* _MADARA_VARIABLE_NODE_H_ */
This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord dec(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Atomically decrement the variable.
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:28
madara::knowledge::ThreadSafeContext & context_
Definition: VariableNode.h:114
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node and its children.
madara::knowledge::KnowledgeRecord * record_
Definition: VariableNode.h:112
virtual madara::knowledge::KnowledgeRecord prune(bool &can_change)
Prune the tree of unnecessary nodes.
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.
Definition: VariableNode.h:111
std::vector< size_t > markers_
Definition: VariableNode.h:119
madara::knowledge::KnowledgeRecord * get_record(void)
Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls)...
Definition: VariableNode.h:98
const std::string & key(void) const
Return the variable key.
virtual void accept(Visitor &visitor) const
Define the accept() operation used for the Visitor pattern.
An abstract base class defines a simple abstract implementation of an expression tree node...
Definition: ComponentNode.h:35
VariableNode(const std::string &key, madara::knowledge::ThreadSafeContext &context)
Ctor.
Abstract base class for all visitors to all classes that derive from ComponentNode.
Definition: Visitor.h:90
std::string expand_opener(size_t opener, size_t &closer) const
static constexpr struct madara::knowledge::tags::string_t string
madara::knowledge::KnowledgeRecord inc(const madara::knowledge::KnowledgeUpdateSettings &settings=knowledge::KnowledgeUpdateSettings())
Atomically increment the variable.
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.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
virtual ~VariableNode(void)
Dtor.
std::string expand_key(void) const
Expands the key (if necessary).
bool key_expansion_necessary_
Expansion necessary.
Definition: VariableNode.h:117