MADARA  3.2.3
VariableReference.inl
Go to the documentation of this file.
1 #ifndef _MADARA_VARIABLE_REFERENCE_INL_
2 #define _MADARA_VARIABLE_REFERENCE_INL_
3 
4 
12 namespace madara { namespace knowledge {
13 
15  : entry_ (entry) {}
16 
17 inline bool
19 {
20  return this->entry_ == rhs.entry_;
21 }
22 
23 inline bool
25 {
26  return !(*this == rhs);
27 }
28 
29 inline const char *
31 {
32  if (!is_valid()) {
33  return nullptr;
34  }
35  return entry_->first.c_str();
36 }
37 
38 inline bool
40 {
41  return entry_ != nullptr;
42 }
43 
44 inline KnowledgeRecord *
46 {
47  if (!is_valid()) {
48  return nullptr;
49  }
50  return &entry_->second;
51 }
52 
53 inline void
55 {
56  entry_ = entry;
57 }
58 
59 inline uint32_t
61 {
62  uint32_t max = 0;
63 
64  // iterate over the list and return the max
65  for (const auto &pair : records)
66  {
67  KnowledgeRecord *rec = pair.second.get_record_unsafe();
68  if (!rec) {
69  continue;
70  }
71  max = std::max <uint32_t> (rec->quality, max);
72  }
73  return max;
74 }
75 
76 } }
77 
78 #endif // _MADARA_VARIABLE_REFERENCE_INL_
This class encapsulates an entry in a KnowledgeBase.
uint32_t max_quality(const KnowledgeRecords &records)
Returns the maximum quality within the records.
bool operator!=(const VariableReference &rhs) const
Inequality operator.
uint32_t quality
priority of the update
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 ...
Optimized reference to a variable within the knowledge base.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
VariableReference()=default
Default constructor.
std::map< const char *, VariableReference, VariableReferenceMapCompare > VariableReferenceMap
a map of variable references
KnowledgeMap::value_type * pair_ptr
bool operator==(const VariableReference &rhs) const
Equality operator.
const char * get_name(void) const
Returns the name of the variable.
Provides functions and classes for the distributed knowledge base.
void assign(pair_ptr entry)
Refer to a different variable.
Copyright (c) 2015 Carnegie Mellon University.