MADARA  3.2.3
madara::knowledge::rcw::Transaction Class Reference

Manages a Read-Compute-Write cycle for registered variables. More...

#include <Transaction.h>

Classes

class  Builder
 Builder object returned by build() More...
 
class  InitHandler
 Helper type to enable initialization using initializer_list Fallback implementation for types which do not support initializer_list. More...
 
class  InitHandler< B, I, T, typename std::enable_if< supports_get_value< T >::value &&supports_indexed_get_value< T >::value &&supports_size< T >::value >::type >
 Helper type to enable initialization using initializer_list Specialization for types which do support initializer_list. More...
 

Public Types

typedef std::unique_ptr< BaseTrackertracker_ptr
 

Public Member Functions

 Transaction (KnowledgeBase kb)
 The constructor. More...
 
template<class T >
void add (const Builder< T, const char * > &b)
 Add a mapping from a Builder object. More...
 
template<class T , class K >
void add (K &&key, T &val) const
 Add a new default mapping for MADARA variable and reference . More...
 
template<class T , class K >
void add_init (K &&key, T &val)
 Add a new mapping for MADARA variable and reference . More...
 
template<class T , class K >
void add_prefix (K &&prefix, T &val) const
 Add a new prefix-based mapping for MADARA variable and ref . More...
 
template<class T , class K >
void add_prefix_init (K &&prefix, T &val)
 Add a new prefix-based mapping for MADARA variable and ref . More...
 
void add_tracker (tracker_ptr t) const
 Add a tracker object directly. More...
 
template<class T , class K >
Builder< T, const char * > build (K &&key, T &val)
 Create a new mapping, using the Builder interface. More...
 
void pull (void)
 Call to update values of registered variables from the knowledge base. More...
 
void push (void)
 Call to push all values of registered variables into the knowledge base. More...
 
bool remove (const char *name) const
 Remove a mapping by name. More...
 
bool remove (const std::string &name) const
 Remove a mapping by name. More...
 
template<class T >
bool remove (const T *var) const
 Remove a mapping by pointer to the mapped object. More...
 

Private Types

typedef trackers_vec::iterator iter_type
 
typedef std::vector< tracker_ptrtrackers_vec
 Type of a vector which stores trackers. More...
 

Private Member Functions

void swap_remove (iter_type i) const
 

Private Attributes

KnowledgeBase kb_
 The knowledge base to push to and pull from. More...
 
trackers_vec trackers_
 Stores all registered trackers. More...
 

Friends

template<class T , class K , bool Const, bool RD, bool WR, bool Prefix, bool Init>
class Builder
 

Detailed Description

Manages a Read-Compute-Write cycle for registered variables.

See https://sourceforge.net/p/madara/wiki/ReadComputeWrite/ for details.

Definition at line 43 of file Transaction.h.

Member Typedef Documentation

typedef trackers_vec::iterator madara::knowledge::rcw::Transaction::iter_type
private

Definition at line 366 of file Transaction.h.

Definition at line 46 of file Transaction.h.

Type of a vector which stores trackers.

Definition at line 52 of file Transaction.h.

Constructor & Destructor Documentation

madara::knowledge::rcw::Transaction::Transaction ( KnowledgeBase  kb)
inline

The constructor.

Note that this keeps a copy of the KnowledgeBase given, thus extending the lifetime of the underlying knowledge base.

Parameters
kbthe knowledge base to read and modify

Definition at line 96 of file Transaction.h.

Member Function Documentation

template<class T >
void madara::knowledge::rcw::Transaction::add ( const Builder< T, const char * > &  b)

Add a mapping from a Builder object.

Parameters
bthe Builder object to use
template<class T , class K >
void madara::knowledge::rcw::Transaction::add ( K &&  key,
T &  val 
) const
inline

Add a new default mapping for MADARA variable and reference .

Parameters
keythe MADARA variable name to use. If it doesn't exist, it will be created.
valreference to the object to push/pull to/from

Definition at line 281 of file Transaction.h.

template<class T , class K >
void madara::knowledge::rcw::Transaction::add_init ( K &&  key,
T &  val 
)
inline

Add a new mapping for MADARA variable and reference .

This will immediately update with the value of

Parameters
keythe MADARA variable name to use. If it doesn't exist, it will be created.
valreference to the object to push/pull to/from

Definition at line 292 of file Transaction.h.

template<class T , class K >
void madara::knowledge::rcw::Transaction::add_prefix ( K &&  prefix,
T &  val 
) const
inline

Add a new prefix-based mapping for MADARA variable and ref .

Parameters
keythe MADARA variable name to use. If it doesn't exist, it will be created.
valreference to the object to push/pull to/from

Definition at line 302 of file Transaction.h.

template<class T , class K >
void madara::knowledge::rcw::Transaction::add_prefix_init ( K &&  prefix,
T &  val 
)
inline

Add a new prefix-based mapping for MADARA variable and ref .

This will immediately update with the value of

Parameters
keythe MADARA variable name to use. If it doesn't exist, it will be created.
valreference to the object to push/pull to/from

Definition at line 313 of file Transaction.h.

void madara::knowledge::rcw::Transaction::add_tracker ( tracker_ptr  t) const
inline

Add a tracker object directly.

For advanced users only.

Parameters
tthe tracker to add

Definition at line 224 of file Transaction.h.

template<class T , class K >
Builder<T, const char*> madara::knowledge::rcw::Transaction::build ( K &&  key,
T &  val 
)
inline

Create a new mapping, using the Builder interface.

IMPORTANT: the variable given must not outlive the Transaction.

Parameters
keythe name of the underlying MADARA variable
vala reference to the variable to manage

Definition at line 209 of file Transaction.h.

void madara::knowledge::rcw::Transaction::pull ( void  )
inline

Call to update values of registered variables from the knowledge base.

Definition at line 108 of file Transaction.h.

void madara::knowledge::rcw::Transaction::push ( void  )
inline

Call to push all values of registered variables into the knowledge base.

Definition at line 99 of file Transaction.h.

bool madara::knowledge::rcw::Transaction::remove ( const char *  name) const
inline

Remove a mapping by name.

If multiple exist for the given name, only one will be removed. Which one is arbitrary.

Parameters
namename of the MADARA variable in the mapping
Returns
true if the mapping was found; false otherwise

Definition at line 323 of file Transaction.h.

bool madara::knowledge::rcw::Transaction::remove ( const std::string &  name) const
inline

Remove a mapping by name.

If multiple exist for the given name, only one will be removed. Which one is arbitrary.

Parameters
namename of the MADARA variable in the mapping
Returns
true if the mapping was found; false otherwise

Definition at line 341 of file Transaction.h.

template<class T >
bool madara::knowledge::rcw::Transaction::remove ( const T *  var) const
inline

Remove a mapping by pointer to the mapped object.

If multiple exist for the given variable, only one will be removed. Which one is arbitrary.

Parameters
varpointer to the variable mapped
Returns
true if the mapping was found; false otherwise

Definition at line 352 of file Transaction.h.

void madara::knowledge::rcw::Transaction::swap_remove ( iter_type  i) const
inlineprivate

Definition at line 367 of file Transaction.h.

Friends And Related Function Documentation

template<class T , class K , bool Const, bool RD, bool WR, bool Prefix, bool Init>
friend class Builder
friend

Definition at line 199 of file Transaction.h.

Member Data Documentation

KnowledgeBase madara::knowledge::rcw::Transaction::kb_
mutableprivate

The knowledge base to push to and pull from.

Definition at line 59 of file Transaction.h.

trackers_vec madara::knowledge::rcw::Transaction::trackers_
mutableprivate

Stores all registered trackers.

Definition at line 62 of file Transaction.h.


The documentation for this class was generated from the following file: