MADARA  3.2.3
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 madara::knowledge::KnowledgeRecord item (void) const;
37 
39  int set (const madara::knowledge::KnowledgeRecord::Integer & value,
42 
44  int set (double value,
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 
94  inline
96  {
97  if (ref_.is_valid())
98  return ref_.get_record_unsafe();
99  else
100  return context_.get_record (expand_key ());
101  }
102 
103  private:
104 
105  std::string expand_opener (size_t opener, size_t & closer) const;
106 
110 
112 
115 
116  std::vector<size_t> markers_;
117 
119  };
120  }
121 }
122 
123 #endif // _MADARA_NO_KARL_
124 
125 #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:111
virtual madara::knowledge::KnowledgeRecord evaluate(const madara::knowledge::KnowledgeUpdateSettings &settings)
Evaluates the node and its children.
madara::knowledge::VariableReference ref_
Definition: VariableNode.h:109
KnowledgeRecord * get_record_unsafe(void) const
Returns a pointer to the variable&#39;s KnowledgeRecord Do not use this pointer unless you&#39;ve locked the ...
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...
Optimized reference to a variable within the knowledge base.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
const std::string key_
Key for retrieving value of this variable.
Definition: VariableNode.h:108
std::vector< size_t > markers_
Definition: VariableNode.h:116
madara::knowledge::KnowledgeRecord * get_record(void)
Retrieves the underlying knowledge::KnowledgeRecord in the context (useful for system calls)...
Definition: VariableNode.h:95
static struct madara::knowledge::tags::string_t string
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:36
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:91
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.
virtual madara::knowledge::KnowledgeRecord item(void) const
Return the item stored in the node.
KnowledgeRecord * get_record(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Retrieves a knowledge record from the key.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
std::string expand_key(void) const
Expands the key (if necessary).
bool key_expansion_necessary_
Expansion necessary.
Definition: VariableNode.h:114