MADARA  3.4.1
madara::knowledge::containers::NativeCircularBufferConsumer Class Reference

This class provides an interface similar to CircularBufferConsumer, which uses the internal history buffer of KnowledgeRecord. More...

#include <NativeCircularBufferConsumer.h>

Public Member Functions

 NativeCircularBufferConsumer ()
 Default constructor. More...
 
 NativeCircularBufferConsumer (const std::string &name, KnowledgeBase &knowledge)
 Constructor. More...
 
 NativeCircularBufferConsumer (const std::string &name, Variables &knowledge)
 Constructor. More...
 
virtual ~NativeCircularBufferConsumer ()=default
 Destructor. More...
 
KnowledgeRecord consume (size_t &dropped) const
 Consumes the record at the local index (not the producer index) More...
 
template<typename T >
void consume (T &value, size_t &dropped) const
 Consumes the record at the local index (not the producer index) More...
 
madara::knowledge::KnowledgeRecord consume (void) const
 Consumes the record at the local index (not the producer index) More...
 
std::vector< KnowledgeRecordconsume_latest (size_t count) const
 Consumes the latest the record at the local index (not the producer index). More...
 
std::vector< KnowledgeRecordconsume_latest (size_t count, size_t &dropped) const
 Consumes the latest the record at the local index (not the producer index). More...
 
template<typename T >
void consume_latest (size_t count, std::vector< T > &values) const
 Consumes the latest the record at the local index (not the producer index). More...
 
template<typename T >
void consume_latest (size_t count, std::vector< T > &values, size_t &dropped) const
 Consumes the latest the record at the local index (not the producer index). More...
 
madara::knowledge::KnowledgeRecord consume_latest (void) const
 Consumes the latest the record at the local index (not the producer index). More...
 
std::vector< KnowledgeRecordconsume_many (size_t count) const
 Consumes (earliest) records from the local index. More...
 
std::vector< KnowledgeRecordconsume_many (size_t count, size_t &dropped) const
 Consumes (earliest) records from the local index. More...
 
template<typename T >
void consume_many (size_t count, std::vector< T > &values) const
 Consumes (earliest) records from the local index. More...
 
size_t count (void) const
 Returns the number of records in the NativeCircularBufferConsumer. More...
 
size_t get_dropped (void) const
 Returns the number of known drops since last consume. More...
 
size_t get_index ()
 Gets the local index. More...
 
std::string get_name (void) const
 Returns the name of the variable. More...
 
KnowledgeRecord get_record () const
 Get the KnowledgeRecord this container refers to. More...
 
madara::knowledge::KnowledgeRecord inspect (KnowledgeRecord::Integer position) const
 Retrieves a record at a position relative to local index. More...
 
std::vector< KnowledgeRecordinspect (KnowledgeRecord::Integer position, size_t count) const
 Retrieves a vector of records at a position relative to local index. More...
 
template<typename T >
void inspect (KnowledgeRecord::Integer position, size_t count, std::vector< T > &values) const
 Retrieves a vector of records at a position relative to local index. More...
 
template<typename T >
void inspect (KnowledgeRecord::Integer position, T &value) const
 Retrieves a record at a position relative to local index. More...
 
bool operator!= (const NativeCircularBufferConsumer &value) const
 Checks for inequality. More...
 
bool operator== (const NativeCircularBufferConsumer &value) const
 Checks for equality. More...
 
std::vector< KnowledgeRecordpeek_latest (size_t count) const
 Peeks, but does not consume, the latest the record at the local index (not the producer index). More...
 
template<typename T >
void peek_latest (size_t count, std::vector< T > &values) const
 Peeks, but does not consume, the latest the record at the local index (not the producer index). More...
 
madara::knowledge::KnowledgeRecord peek_latest (void) const
 Peeks, but does not consume, the latest the record at the local index (not the producer index). More...
 
size_t remaining (void) const
 Returns the number of records remaining that have not been consumed. More...
 
void set_index (size_t index)
 Sets the local index to an arbitrary position. More...
 
void set_name (const std::string &name, KnowledgeBase &knowledge)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &name, ThreadSafeContext &context)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &name, Variables &knowledge)
 Sets the variable name that this refers to. More...
 
size_t size (void) const
 Returns the maximum size of the NativeCircularBufferConsumer. More...
 

Private Member Functions

void check_context (const char *func) const
 

Static Private Member Functions

static void check_name (const char *func, const char *name)
 

Private Attributes

ThreadSafeContextcontext_
 Variable context that we are modifying. More...
 
size_t local_index_
 Index for latest item read by. More...
 
VariableReference ref_
 Reference to underlying record we are reading. More...
 

Detailed Description

This class provides an interface similar to CircularBufferConsumer, which uses the internal history buffer of KnowledgeRecord.

This allows threads sharing the same KnowledgeBase to view the same circular buffer, but this buffer is not visible to other KnowledgeBases across transports.

This class uses a local index into the underlying circular buffer, and is meant for one-time access of buffer elements.

This class provides a subset of the capabilities of CircularBufferConsumer, as KnowledgeRecord itself provides equivalents of the rest. Use get_record() to access the KnowledgeRecord backing a NativeCircularBufferConsumer.

This class should only be used with records which have history capacity of at least 1. Most methods will throw IndexException if not.

Definition at line 48 of file NativeCircularBufferConsumer.h.

Constructor & Destructor Documentation

◆ NativeCircularBufferConsumer() [1/3]

madara::knowledge::containers::NativeCircularBufferConsumer::NativeCircularBufferConsumer ( )
inline

Default constructor.

Definition at line 20 of file NativeCircularBufferConsumer.inl.

◆ NativeCircularBufferConsumer() [2/3]

madara::knowledge::containers::NativeCircularBufferConsumer::NativeCircularBufferConsumer ( const std::string &  name,
KnowledgeBase knowledge 
)
inline

Constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 53 of file NativeCircularBufferConsumer.inl.

◆ NativeCircularBufferConsumer() [3/3]

madara::knowledge::containers::NativeCircularBufferConsumer::NativeCircularBufferConsumer ( const std::string &  name,
Variables knowledge 
)
inline

Constructor.

Parameters
namethe name of the map within the variable context
knowledgethe variable contex
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 64 of file NativeCircularBufferConsumer.inl.

◆ ~NativeCircularBufferConsumer()

virtual madara::knowledge::containers::NativeCircularBufferConsumer::~NativeCircularBufferConsumer ( )
virtualdefault

Destructor.

Member Function Documentation

◆ check_context()

void madara::knowledge::containers::NativeCircularBufferConsumer::check_context ( const char *  func) const
inlineprivate

Definition at line 36 of file NativeCircularBufferConsumer.inl.

◆ check_name()

void madara::knowledge::containers::NativeCircularBufferConsumer::check_name ( const char *  func,
const char *  name 
)
inlinestaticprivate

Definition at line 25 of file NativeCircularBufferConsumer.inl.

◆ consume() [1/3]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::NativeCircularBufferConsumer::consume ( size_t &  dropped) const
inline

Consumes the record at the local index (not the producer index)

Returns
the last added record. exists() will return false if the record is invalid
Parameters
droppedthe number of dropped packets. Drops can occur when the producer produces faster than the consumer can consume. This value is essentially index_ - local_index - size ().
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 250 of file NativeCircularBufferConsumer.inl.

◆ consume() [2/3]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::consume ( T &  value,
size_t &  dropped 
) const

Consumes the record at the local index (not the producer index)

Parameters
valuethe last added value.
droppedthe number of dropped packets. Drops can occur when the producer produces faster than the consumer can consume. This value is essentially index_ - local_index - size ().
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 88 of file NativeCircularBufferConsumer.inl.

◆ consume() [3/3]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::NativeCircularBufferConsumer::consume ( void  ) const
inline

Consumes the record at the local index (not the producer index)

Returns
the last added record. exists() will return false if the record is invalid
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 242 of file NativeCircularBufferConsumer.inl.

◆ consume_latest() [1/5]

std::vector< KnowledgeRecord > madara::knowledge::containers::NativeCircularBufferConsumer::consume_latest ( size_t  count) const
inline

Consumes the latest the record at the local index (not the producer index).

Parameters
countthe maximum number of records to return
Returns
the latest count consumed elements
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 175 of file NativeCircularBufferConsumer.inl.

◆ consume_latest() [2/5]

std::vector< KnowledgeRecord > madara::knowledge::containers::NativeCircularBufferConsumer::consume_latest ( size_t  count,
size_t &  dropped 
) const
inline

Consumes the latest the record at the local index (not the producer index).

Parameters
countthe maximum number of records to return
droppedthe number of dropped records
Returns
the latest count elements and number of elements dropped.
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 221 of file NativeCircularBufferConsumer.inl.

◆ consume_latest() [3/5]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::consume_latest ( size_t  count,
std::vector< T > &  values 
) const

Consumes the latest the record at the local index (not the producer index).

Parameters
countthe maximum number of records to return
valuesthe latest records
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 147 of file NativeCircularBufferConsumer.inl.

◆ consume_latest() [4/5]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::consume_latest ( size_t  count,
std::vector< T > &  values,
size_t &  dropped 
) const

Consumes the latest the record at the local index (not the producer index).

Parameters
countthe maximum number of records to return
valuesthe latest records
droppedthe number of dropped records
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 160 of file NativeCircularBufferConsumer.inl.

◆ consume_latest() [5/5]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::NativeCircularBufferConsumer::consume_latest ( void  ) const
inline

Consumes the latest the record at the local index (not the producer index).

Returns
the latest element (singular)
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 200 of file NativeCircularBufferConsumer.inl.

◆ consume_many() [1/3]

std::vector< KnowledgeRecord > madara::knowledge::containers::NativeCircularBufferConsumer::consume_many ( size_t  count) const
inline

Consumes (earliest) records from the local index.

Parameters
countthe maximum number of records to return
Returns
the last added records
Exceptions
exceptions::ContextExceptionif name or context have not been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 311 of file NativeCircularBufferConsumer.inl.

◆ consume_many() [2/3]

std::vector< KnowledgeRecord > madara::knowledge::containers::NativeCircularBufferConsumer::consume_many ( size_t  count,
size_t &  dropped 
) const
inline

Consumes (earliest) records from the local index.

Parameters
countthe maximum number of records to return
droppedthe number of dropped packets. Drops can occur when the producer produces faster than the consumer can consume.
Returns
the last added records
Exceptions
exceptions::ContextExceptionif name or context have not been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 293 of file NativeCircularBufferConsumer.inl.

◆ consume_many() [3/3]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::consume_many ( size_t  count,
std::vector< T > &  values 
) const

Consumes (earliest) records from the local index.

Parameters
countthe maximum number of records to return
valuesthe last added records
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 283 of file NativeCircularBufferConsumer.inl.

◆ count()

size_t madara::knowledge::containers::NativeCircularBufferConsumer::count ( void  ) const
inline

Returns the number of records in the NativeCircularBufferConsumer.

Returns
the number of records in the NativeCircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 427 of file NativeCircularBufferConsumer.inl.

◆ get_dropped()

size_t madara::knowledge::containers::NativeCircularBufferConsumer::get_dropped ( void  ) const
inline

Returns the number of known drops since last consume.

Returns
the number of drops
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 470 of file NativeCircularBufferConsumer.inl.

◆ get_index()

size_t madara::knowledge::containers::NativeCircularBufferConsumer::get_index ( )
inline

Gets the local index.

Parameters
indexthe new index to use

Definition at line 267 of file NativeCircularBufferConsumer.h.

◆ get_name()

std::string madara::knowledge::containers::NativeCircularBufferConsumer::get_name ( void  ) const
inline

Returns the name of the variable.

Returns
name of the variable

Definition at line 393 of file NativeCircularBufferConsumer.inl.

◆ get_record()

KnowledgeRecord madara::knowledge::containers::NativeCircularBufferConsumer::get_record ( void  ) const
inline

Get the KnowledgeRecord this container refers to.

While this returns by copy, it will share the same circular buffer for read operations, but any modificatiosn will result in a copy and not be reflected in the original inside the KnowledgeBase.

Definition at line 488 of file NativeCircularBufferConsumer.inl.

◆ inspect() [1/4]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::NativeCircularBufferConsumer::inspect ( KnowledgeRecord::Integer  position) const
inline

Retrieves a record at a position relative to local index.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
Returns
the record at the position in the NativeCircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 335 of file NativeCircularBufferConsumer.inl.

◆ inspect() [2/4]

std::vector< KnowledgeRecord > madara::knowledge::containers::NativeCircularBufferConsumer::inspect ( KnowledgeRecord::Integer  position,
size_t  count 
) const
inline

Retrieves a vector of records at a position relative to local index.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
countthe maximum number of records to return
Returns
the values at the position in the NativeCircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 362 of file NativeCircularBufferConsumer.inl.

◆ inspect() [3/4]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::inspect ( KnowledgeRecord::Integer  position,
size_t  count,
std::vector< T > &  values 
) const

Retrieves a vector of records at a position relative to local index.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
countthe maximum number of records to return
valuesthe values at the position in the NativeCircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 351 of file NativeCircularBufferConsumer.inl.

◆ inspect() [4/4]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::inspect ( KnowledgeRecord::Integer  position,
T &  value 
) const

Retrieves a record at a position relative to local index.

Parameters
positionthe relative position of the requested record from the latest added record. Can be negative
valuethe record at the position in the NativeCircularBufferConsumer
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 328 of file NativeCircularBufferConsumer.inl.

◆ operator!=()

bool madara::knowledge::containers::NativeCircularBufferConsumer::operator!= ( const NativeCircularBufferConsumer value) const
inline

Checks for inequality.

Parameters
valuethe value to compare to
Returns
true if inequal, false otherwise

Definition at line 81 of file NativeCircularBufferConsumer.inl.

◆ operator==()

bool madara::knowledge::containers::NativeCircularBufferConsumer::operator== ( const NativeCircularBufferConsumer value) const
inline

Checks for equality.

Parameters
valuethe value to compare to
Returns
true if equal, false otherwise

Definition at line 75 of file NativeCircularBufferConsumer.inl.

◆ peek_latest() [1/3]

std::vector< KnowledgeRecord > madara::knowledge::containers::NativeCircularBufferConsumer::peek_latest ( size_t  count) const
inline

Peeks, but does not consume, the latest the record at the local index (not the producer index).

Parameters
countthe maximum number of records to return
Returns
the latest peeked (not consumed) count elements
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 108 of file NativeCircularBufferConsumer.inl.

◆ peek_latest() [2/3]

template<typename T >
void madara::knowledge::containers::NativeCircularBufferConsumer::peek_latest ( size_t  count,
std::vector< T > &  values 
) const

Peeks, but does not consume, the latest the record at the local index (not the producer index).

Parameters
countthe maximum number of records to return
valuesthe latest records
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 95 of file NativeCircularBufferConsumer.inl.

◆ peek_latest() [3/3]

madara::knowledge::KnowledgeRecord madara::knowledge::containers::NativeCircularBufferConsumer::peek_latest ( void  ) const
inline

Peeks, but does not consume, the latest the record at the local index (not the producer index).

Returns
the latest element
Exceptions
exceptions::IndexExceptionif target has no history capacity set

Definition at line 130 of file NativeCircularBufferConsumer.inl.

◆ remaining()

size_t madara::knowledge::containers::NativeCircularBufferConsumer::remaining ( void  ) const
inline

Returns the number of records remaining that have not been consumed.

This includes records which have been dropped.

Returns
the number of records remaining for consume
Exceptions
exceptions::ContextExceptionif name or context haven't been set appropriately
exceptions::IndexExceptionif target has no history capacity set

Definition at line 409 of file NativeCircularBufferConsumer.inl.

◆ set_index()

void madara::knowledge::containers::NativeCircularBufferConsumer::set_index ( size_t  index)
inline

Sets the local index to an arbitrary position.

Parameters
indexthe new index to use

Definition at line 461 of file NativeCircularBufferConsumer.inl.

◆ set_name() [1/3]

void madara::knowledge::containers::NativeCircularBufferConsumer::set_name ( const std::string &  name,
KnowledgeBase knowledge 
)
inline

Sets the variable name that this refers to.

Parameters
namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 449 of file NativeCircularBufferConsumer.inl.

◆ set_name() [2/3]

void madara::knowledge::containers::NativeCircularBufferConsumer::set_name ( const std::string &  name,
ThreadSafeContext context 
)
inline

Sets the variable name that this refers to.

Parameters
namethe name of the variable in the knowledge base
contextthe ThreadSafeContext the variable is housed in
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 437 of file NativeCircularBufferConsumer.inl.

◆ set_name() [3/3]

void madara::knowledge::containers::NativeCircularBufferConsumer::set_name ( const std::string &  name,
Variables knowledge 
)
inline

Sets the variable name that this refers to.

Parameters
namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
Exceptions
exceptions::NameExceptionbad name ("")

Definition at line 455 of file NativeCircularBufferConsumer.inl.

◆ size()

size_t madara::knowledge::containers::NativeCircularBufferConsumer::size ( void  ) const
inline

Returns the maximum size of the NativeCircularBufferConsumer.

Returns
the size of the NativeCircularBufferConsumer

Definition at line 398 of file NativeCircularBufferConsumer.inl.

Member Data Documentation

◆ context_

ThreadSafeContext* madara::knowledge::containers::NativeCircularBufferConsumer::context_
mutableprivate

Variable context that we are modifying.

Definition at line 378 of file NativeCircularBufferConsumer.h.

◆ local_index_

size_t madara::knowledge::containers::NativeCircularBufferConsumer::local_index_
mutableprivate

Index for latest item read by.

Definition at line 388 of file NativeCircularBufferConsumer.h.

◆ ref_

VariableReference madara::knowledge::containers::NativeCircularBufferConsumer::ref_
private

Reference to underlying record we are reading.

Definition at line 383 of file NativeCircularBufferConsumer.h.


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