3 #ifndef INCL_MADARA_RCW_TRACKER_H 4 #define INCL_MADARA_RCW_TRACKER_H 17 #include <type_traits> 18 #include <initializer_list> 22 #include "madara/MADARA_export.h" 33 template<
class T,
class R,
bool RD = true,
bool WR = true,
class dummy =
void>
36 static_assert(
sizeof(T) < 0,
"Type unsupported for adding to Transaction");
40 template<
class T,
class R>
45 static_assert(
sizeof(T) < 0,
"Cannot create tracker that can neither read nor write");
52 supports_get_value<T>::value &&
53 supports_knowledge_cast<T>::value &&
54 supports_self_eq<T>::value &&
55 !supports_is_dirty<T>::value>::type>
59 typedef typename std::decay<decltype(get_value(std::declval<T>()))>::type
V;
64 static const bool can_read =
true;
65 static const bool can_write =
true;
79 Tracker::force_push(kb);
91 return ref_.get_name();
96 return (
void*)tracked_;
105 supports_get_value<T>::value &&
106 supports_knowledge_cast<T>::value>::type>
110 typedef typename std::decay<decltype(get_value(std::declval<T>()))>::type
V;
114 static const bool can_read =
true;
115 static const bool can_write =
false;
122 set_value(*tracked_, knowledge_cast<V>(
get()));
131 return ref_.get_name();
136 return (
void*)tracked_;
146 supports_get_value<T>::value &&
147 supports_knowledge_cast<T>::value &&
148 supports_self_eq<T>::value &&
149 !supports_is_dirty<T>::value>::type>
153 typedef typename std::decay<decltype(get_value(std::declval<T>()))>::type
V;
159 static const bool can_read =
false;
160 static const bool can_write =
true;
173 Tracker::force_push(kb);
185 return ref_.get_name();
190 return (
void*)tracked_;
200 supports_get_value<T>::value &&
201 supports_knowledge_cast<T>::value &&
202 supports_is_dirty<T>::value &&
203 !supports_indexed_is_dirty<T>::value>::type >
209 static const bool can_read =
true;
210 static const bool can_write =
true;
212 typedef typename std::decay<decltype(get_value(std::declval<T>()))>::type
V;
227 Tracker::force_push(kb);
239 return ref_.get_name();
244 return (
void*)tracked_;
254 supports_get_value<T>::value &&
255 supports_knowledge_cast<T>::value &&
256 supports_is_dirty<T>::value &&
257 !supports_indexed_is_dirty<T>::value>::type >
263 typedef typename std::decay<decltype(get_value(std::declval<T>()))>::type
V;
265 static const bool can_read =
false;
266 static const bool can_write =
true;
280 Tracker::force_push(kb);
292 return ref_.get_name();
297 return (
void*)tracked_;
305 template<
class T,
bool RD,
bool WR>
307 supports_indexed_get_value<T>::value &&
308 supports_size<T>::value &&
309 !supports_is_all_dirty<T>::value &&
310 !supports_is_size_dirty<T>::value &&
311 supports_indexed_is_dirty<T>::value>::type >
315 static_assert(RD ==
true,
"Write-only not supported for containers of tracked items");
320 typedef typename std::decay<decltype(get_value(std::declval<T>(), 0))>::type
V;
322 static const bool can_read = RD;
323 static const bool can_write = WR;
326 :
BaseTracker(ref), tracked_(tracked), orig_size_() {}
330 std::vector<double> val =
get().to_doubles();
331 orig_size_ = val.size();
332 size_t n = orig_size_;
334 for (
size_t i = 0; i < n; ++i) {
343 size_t n = tracked_->size();
344 if (tracked_->size() != orig_size_) {
347 for (
size_t i = 0; i < n; ++i) {
349 set_index(kb, i,
get_value(*tracked_, i));
359 size_t n = tracked_->size();
360 if (tracked_->size() != orig_size_) {
363 for (
size_t i = 0; i < n; ++i) {
364 set_index(kb, i,
get_value(*tracked_, i));
372 return ref_.get_name();
377 return (
void*)tracked_;
385 template<
class T,
bool RD,
bool WR>
387 supports_get_value<T>::value &&
388 supports_indexed_get_value<T>::value &&
389 supports_size<T>::value &&
390 supports_knowledge_cast<T>::value &&
391 supports_is_dirty<T>::value &&
392 supports_is_all_dirty<T>::value &&
393 supports_is_size_dirty<T>::value &&
394 supports_indexed_is_dirty<T>::value>::type >
400 typedef typename std::decay<decltype(get_value(std::declval<T>()))>::type
V;
402 static const bool can_read = RD;
403 static const bool can_write = WR;
423 return Tracker::force_push(kb);
425 size_t n = tracked_->size();
429 for (
size_t i = 0; i < n; ++i) {
431 set_index(kb, i,
get_value(*tracked_, i));
448 return ref_.get_name();
453 return (
void*)tracked_;
460 #endif // INCL_MADARA_RCW_TRACKER_H std::decay< decltype(get_value(std::declval< T >)))>::type V
Tracker(T *tracked, VariableReference ref)
virtual void push(KnowledgeBase &)
Override to implement pushing logic (into ref_)
virtual void pull()
Override to implement pulling logic (from ref_)
virtual const char * get_name() const
Get name of MADARA variable.
virtual void push(KnowledgeBase &kb)
Override to implement pushing logic (into ref_)
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_)
Tracker(T *tracked, VariableReference ref)
Manages a Read-Compute-Write cycle for registered variables.
std::decay< decltype(get_value(std::declval< T >)))>::type V
Pointer to tracked object.
virtual const char * get_name() const
Get name of MADARA variable.
virtual void pull()
Override to implement pulling logic (from ref_)
Optimized reference to a variable within the knowledge base.
virtual const void * get_tracked() const
Get pointer to tracked object.
V orig_
Pointer to tracked object.
virtual const void * get_tracked() const
Get pointer to tracked object.
Tracker(T *tracked, VariableReference ref)
bool is_dirty(const Tracked< T > &t)
Returns dirty flag of Tracked types.
virtual const void * get_tracked() const
Get pointer to tracked object.
std::decay< decltype(get_value(std::declval< T >)))>::type V
virtual const char * get_name() const
Get name of MADARA variable.
virtual void push(KnowledgeBase &kb)
Override to implement pushing logic (into ref_)
O knowledge_cast(const KnowledgeRecord &in)
By default, call constructor of target class; for other semantics, define specializations.
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
virtual const char * get_name() const
Get name of MADARA variable.
virtual void pull()
Override to implement pulling logic (from ref_)
virtual void pull()
Override to implement pulling logic (from ref_)
virtual void push(KnowledgeBase &kb)
Override to implement pushing logic (into ref_)
virtual const void * get_tracked() const
Get pointer to tracked object.
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.
virtual void push(KnowledgeBase &kb)
Override to implement pushing logic (into ref_)
Tracker(T *tracked, VariableReference ref)
This class provides a distributed knowledge base to users.
Tracker(T *tracked, VariableReference ref)
size_t orig_size_
Pointer to tracked.
std::decay< decltype(get_value(std::declval< T >)))>::type V
Pointer to tracked object.
Tracker which puts variable values into a single KnowledgeRecord.
std::decay< decltype(get_value(std::declval< T >)))>::type V
std::decay< decltype(get_value(std::declval< T >), 0))>::type V
Size as pulled to compare to on push.
virtual const void * get_tracked() const
Get pointer to tracked object.
virtual void pull()
Override to implement pulling logic (from ref_)
const T & get_value(const T &t)
Fallback definition of get_value; simply passes through the value.
Tracker(T *tracked, VariableReference ref)
virtual const char * get_name() const
Get name of MADARA variable.
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
Provides functions and classes for the distributed knowledge base.
virtual const char * get_name() const
Get name of MADARA variable.
Tracker(T *tracked, VariableReference ref)
virtual void pull()
Override to implement pulling logic (from ref_)
void set_value(T &t, const T &v)
Fallback definition of set_value; simply passes through the value.
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
virtual void pull()
Override to implement pulling logic (from ref_)
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
Copyright (c) 2015 Carnegie Mellon University.
virtual void push(KnowledgeBase &kb)
Override to implement pushing logic (into ref_)
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
std::decay< decltype(get_value(std::declval< T >)))>::type V
virtual const void * get_tracked() const
Get pointer to tracked object.
virtual void force_push(KnowledgeBase &kb)
As push, but ignore any modification status tracking.
virtual const void * get_tracked() const
Get pointer to tracked object.
virtual const char * get_name() const
Get name of MADARA variable.
virtual void force_push(KnowledgeBase &)
As push, but ignore any modification status tracking.