MADARA
3.4.1
|
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< KnowledgeRecord > | consume_latest (size_t count) const |
Consumes the latest the record at the local index (not the producer index). More... | |
std::vector< KnowledgeRecord > | consume_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< KnowledgeRecord > | consume_many (size_t count) const |
Consumes (earliest) records from the local index. More... | |
std::vector< KnowledgeRecord > | consume_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< KnowledgeRecord > | inspect (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< KnowledgeRecord > | peek_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 | |
ThreadSafeContext * | context_ |
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... | |
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.
|
inline |
Default constructor.
Definition at line 20 of file NativeCircularBufferConsumer.inl.
|
inline |
Constructor.
name | name of the integer in the knowledge base |
knowledge | the knowledge base that will contain the vector |
exceptions::NameException | bad name ("") |
Definition at line 53 of file NativeCircularBufferConsumer.inl.
|
inline |
Constructor.
name | the name of the map within the variable context |
knowledge | the variable contex |
exceptions::NameException | bad name ("") |
Definition at line 64 of file NativeCircularBufferConsumer.inl.
|
virtualdefault |
Destructor.
|
inlineprivate |
Definition at line 36 of file NativeCircularBufferConsumer.inl.
|
inlinestaticprivate |
Definition at line 25 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes the record at the local index (not the producer index)
dropped | the 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::IndexException | if target has no history capacity set |
Definition at line 250 of file NativeCircularBufferConsumer.inl.
void madara::knowledge::containers::NativeCircularBufferConsumer::consume | ( | T & | value, |
size_t & | dropped | ||
) | const |
Consumes the record at the local index (not the producer index)
value | the last added value. |
dropped | the 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::IndexException | if target has no history capacity set |
Definition at line 88 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes the record at the local index (not the producer index)
exceptions::IndexException | if target has no history capacity set |
Definition at line 242 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes the latest the record at the local index (not the producer index).
count | the maximum number of records to return |
exceptions::IndexException | if target has no history capacity set |
Definition at line 175 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes the latest the record at the local index (not the producer index).
count | the maximum number of records to return |
dropped | the number of dropped records |
exceptions::IndexException | if target has no history capacity set |
Definition at line 221 of file NativeCircularBufferConsumer.inl.
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).
count | the maximum number of records to return |
values | the latest records |
exceptions::IndexException | if target has no history capacity set |
Definition at line 147 of file NativeCircularBufferConsumer.inl.
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).
count | the maximum number of records to return |
values | the latest records |
dropped | the number of dropped records |
exceptions::IndexException | if target has no history capacity set |
Definition at line 160 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes the latest the record at the local index (not the producer index).
exceptions::IndexException | if target has no history capacity set |
Definition at line 200 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes (earliest) records from the local index.
count | the maximum number of records to return |
exceptions::ContextException | if name or context have not been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 311 of file NativeCircularBufferConsumer.inl.
|
inline |
Consumes (earliest) records from the local index.
count | the maximum number of records to return |
dropped | the number of dropped packets. Drops can occur when the producer produces faster than the consumer can consume. |
exceptions::ContextException | if name or context have not been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 293 of file NativeCircularBufferConsumer.inl.
void madara::knowledge::containers::NativeCircularBufferConsumer::consume_many | ( | size_t | count, |
std::vector< T > & | values | ||
) | const |
Consumes (earliest) records from the local index.
count | the maximum number of records to return |
values | the last added records |
exceptions::IndexException | if target has no history capacity set |
Definition at line 283 of file NativeCircularBufferConsumer.inl.
|
inline |
Returns the number of records in the NativeCircularBufferConsumer.
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 427 of file NativeCircularBufferConsumer.inl.
|
inline |
Returns the number of known drops since last consume.
exceptions::IndexException | if target has no history capacity set |
Definition at line 470 of file NativeCircularBufferConsumer.inl.
|
inline |
Gets the local index.
index | the new index to use |
Definition at line 267 of file NativeCircularBufferConsumer.h.
|
inline |
Returns the name of the variable.
Definition at line 393 of file NativeCircularBufferConsumer.inl.
|
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.
|
inline |
Retrieves a record at a position relative to local index.
position | the relative position of the requested record from the latest added record. Can be negative |
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 335 of file NativeCircularBufferConsumer.inl.
|
inline |
Retrieves a vector of records at a position relative to local index.
position | the relative position of the requested record from the latest added record. Can be negative |
count | the maximum number of records to return |
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 362 of file NativeCircularBufferConsumer.inl.
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.
position | the relative position of the requested record from the latest added record. Can be negative |
count | the maximum number of records to return |
values | the values at the position in the NativeCircularBufferConsumer |
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 351 of file NativeCircularBufferConsumer.inl.
void madara::knowledge::containers::NativeCircularBufferConsumer::inspect | ( | KnowledgeRecord::Integer | position, |
T & | value | ||
) | const |
Retrieves a record at a position relative to local index.
position | the relative position of the requested record from the latest added record. Can be negative |
value | the record at the position in the NativeCircularBufferConsumer |
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 328 of file NativeCircularBufferConsumer.inl.
|
inline |
Checks for inequality.
value | the value to compare to |
Definition at line 81 of file NativeCircularBufferConsumer.inl.
|
inline |
Checks for equality.
value | the value to compare to |
Definition at line 75 of file NativeCircularBufferConsumer.inl.
|
inline |
Peeks, but does not consume, the latest the record at the local index (not the producer index).
count | the maximum number of records to return |
exceptions::IndexException | if target has no history capacity set |
Definition at line 108 of file NativeCircularBufferConsumer.inl.
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).
count | the maximum number of records to return |
values | the latest records |
exceptions::IndexException | if target has no history capacity set |
Definition at line 95 of file NativeCircularBufferConsumer.inl.
|
inline |
Peeks, but does not consume, the latest the record at the local index (not the producer index).
exceptions::IndexException | if target has no history capacity set |
Definition at line 130 of file NativeCircularBufferConsumer.inl.
|
inline |
Returns the number of records remaining that have not been consumed.
This includes records which have been dropped.
exceptions::ContextException | if name or context haven't been set appropriately |
exceptions::IndexException | if target has no history capacity set |
Definition at line 409 of file NativeCircularBufferConsumer.inl.
|
inline |
Sets the local index to an arbitrary position.
index | the new index to use |
Definition at line 461 of file NativeCircularBufferConsumer.inl.
|
inline |
Sets the variable name that this refers to.
name | the name of the variable in the knowledge base |
knowledge | the knowledge base the variable is housed in |
exceptions::NameException | bad name ("") |
Definition at line 449 of file NativeCircularBufferConsumer.inl.
|
inline |
Sets the variable name that this refers to.
name | the name of the variable in the knowledge base |
context | the ThreadSafeContext the variable is housed in |
exceptions::NameException | bad name ("") |
Definition at line 437 of file NativeCircularBufferConsumer.inl.
|
inline |
Sets the variable name that this refers to.
name | the name of the variable in the knowledge base |
knowledge | the knowledge base the variable is housed in |
exceptions::NameException | bad name ("") |
Definition at line 455 of file NativeCircularBufferConsumer.inl.
|
inline |
Returns the maximum size of the NativeCircularBufferConsumer.
Definition at line 398 of file NativeCircularBufferConsumer.inl.
|
mutableprivate |
Variable context that we are modifying.
Definition at line 378 of file NativeCircularBufferConsumer.h.
|
mutableprivate |
Index for latest item read by.
Definition at line 388 of file NativeCircularBufferConsumer.h.
|
private |
Reference to underlying record we are reading.
Definition at line 383 of file NativeCircularBufferConsumer.h.