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