3 #ifndef INCL_MADARA_RCW_PREFIX_TRACKER_H 4 #define INCL_MADARA_RCW_PREFIX_TRACKER_H 17 #include <type_traits> 18 #include <initializer_list> 22 #include "madara/MADARA_export.h" 34 template<
class T,
class R,
bool RD = true,
bool WR = true,
class dummy =
void>
37 static_assert(
sizeof(T) < 0,
"Type unsupported for adding to Transaction with prefix");
41 template<
class T,
class R>
46 static_assert(
sizeof(T) < 0,
"Cannot create prefix tracker that can neither read nor write");
52 template<
class T,
bool RD,
bool WR>
54 supports_get_value<T>::value &&
55 supports_indexed_get_value<T>::value &&
56 supports_size<T>::value &&
57 supports_is_dirty<T>::value &&
58 supports_is_all_dirty<T>::value &&
59 supports_is_size_dirty<T>::value &&
60 supports_indexed_is_dirty<T>::value>::type >
69 std::vector<VariableReference>
elems_;
71 typedef typename std::decay<decltype(get_value(std::declval<T>()[0]))>::type
V;
73 static const bool can_read = RD;
74 static const bool can_write = WR;
78 tracked_(tracked), prefix_(prefix), kb_(kb), elems_()
86 const size_t n = tracked_->size();
87 if (elems_.size() == n)
89 if (elems_.size() > n) {
90 for (
size_t i = n; i < elems_.size(); ++i) {
91 get_mut(elems_[i]).clear_value();
96 std::ostringstream name;
98 name << prefix_ <<
".";
99 const auto pos = name.tellp();
100 for (
size_t i = elems_.size(); i < n; ++i) {
102 elems_.push_back(kb_.get_ref(name.str()));
109 const size_t n =
get().to_integer();
112 for (
size_t i = 0; i < n; ++i) {
126 const size_t n = tracked_->size();
128 return force_push(kb);
136 for (
size_t i = 0; i < n; ++i) {
139 post_set(kb, elems_[i]);
148 const size_t n = tracked_->size();
153 for (
size_t i = 0; i < n; ++i) {
155 post_set(kb, elems_[i]);
162 return prefix_.c_str();
167 return (
void*)tracked_;
174 #endif // INCL_MADARA_RCW_PREFIX_TRACKER_H
std::string prefix_
Tracked std::vector.
bool is_size_dirty(const Tracked< std::vector< T >> &t)
Return size changed dirty flag of Tracked vector.
virtual void push(KnowledgeBase &kb)
Override to implement pushing logic (into ref_)
Manages a Read-Compute-Write cycle for registered variables.
std::decay< decltype(get_value(std::declval< T >)[0]))>::type V
void update_elems()
Update knowledge base array so it matches dimensions of the tracked object.
Optimized reference to a variable within the knowledge base.
bool is_dirty(const Tracked< T > &t)
Returns dirty flag of Tracked types.
O knowledge_cast(const KnowledgeRecord &in)
By default, call constructor of target class; for other semantics, define specializations.
virtual const void * get_tracked() const
Get pointer to tracked object.
std::vector< VariableReference > elems_
The knowledge base to reference.
bool is_all_dirty(const Tracked< std::vector< T >> &t)
Return global dirty flag of Tracked vector.
void clear_dirty(Tracked< T > &t)
Clears dirty flag of Tracked types.
This class provides a distributed knowledge base to users.
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
Tracker that puts values into a multiple prefixed KnowledgeRecords.
const T & get_value(const T &t)
Fallback definition of get_value; simply passes through the value.
virtual void pull()
Override to implement pulling logic (from ref_)
Provides functions and classes for the distributed knowledge base.
void set_value(T &t, const T &v)
Fallback definition of set_value; simply passes through the value.
Copyright (c) 2015 Carnegie Mellon University.
virtual const char * get_name() const
Get name of MADARA variable.
KnowledgeBase kb_
prefix string to use
PrefixTracker(T *tracked, const std::string &prefix, KnowledgeBase &kb)