2 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_H_
3 #define _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_H_
7 #include "madara/LockType.h"
137 void consume(T& value,
size_t& dropped)
const;
159 size_t count,
size_t& dropped)
const;
184 size_t count, std::vector<T>& values,
size_t& dropped)
const;
205 size_t count,
size_t& dropped)
const;
228 size_t count, std::vector<T>& values,
size_t& dropped)
const;
269 std::vector<KnowledgeRecord>
inspect(
284 std::vector<T>& values)
const;
343 size_t count(
void)
const;
349 size_t size(
void)
const;
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
This class stores variables and their values for use by any entity needing state information in a thr...
Provides an interface for external functions into the MADARA KaRL variable settings.
This container stores a thread-safe, personalized consumer for CircularBuffer instances.
void consume(T &value) const
Consumes the record at the local index (not the producer index)
std::string get_name(void) const
Returns the name of the variable.
size_t count(void) const
Returns the number of records in the CircularBufferConsumer.
size_t remaining(void) const
Returns the number of records remaining that have not been consumed with get_latest,...
void check_context(const char *func) const
void check_name(const char *func) const
KnowledgeRecord consume(void) const
Consumes the record at the local index (not the producer index)
void consume_earliest(size_t count, std::vector< T > &values, size_t &dropped) const
Consumes earliest records from the local index in the buffer.
void set_name(const std::string &name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
void consume(T &value, size_t &dropped) const
Consumes the record at the local index (not the producer index)
std::vector< KnowledgeRecord > consume_latest(size_t count) const
Consumes the record at the local index (not the producer index)
knowledge::KnowledgeRecord inspect(KnowledgeRecord::Integer position) const
Retrieves a record at a position relative to local index.
CircularBufferConsumer()
Default constructor.
void consume_earliest(size_t count, std::vector< T > &values) const
Consumes earliest records from the local index in the buffer.
size_t get_dropped(void) const
Returns the number of known drops since last consume.
void resync(void)
Sets the local index to the current buffer index.
KnowledgeRecord::Integer increment(KnowledgeRecord::Integer base, KnowledgeRecord::Integer value) const
Increments the base by the value, using size as a boundary.
std::vector< KnowledgeRecord > consume_earliest(size_t count) const
Consumes earliest records from the local index in the buffer.
virtual ~CircularBufferConsumer()=default
Destructor.
Integer index_
Index for latest item in circular buffer.
std::string name_
Prefix of variable.
void peek_latest(size_t count, std::vector< T > &values) const
Peeks at the most recently added records.
bool operator!=(const CircularBufferConsumer &value) const
Checks for inequality.
void set_index(KnowledgeRecord::Integer index)
Sets the local index to an arbitrary position.
knowledge::KnowledgeRecord peek_latest(void) const
Peeks at the most recently added record.
ThreadSafeContext * context_
guard for access and changes
void peek_latest(T &value) const
Peeks at the most recently added value.
Vector buffer_
Underlying array of records.
void inspect(KnowledgeRecord::Integer position, T &value) const
Retrieves a record at a position relative to local index.
void consume_latest(size_t count, std::vector< T > &values, size_t &dropped) const
Consumes latest records added by the producer and updates the local index to the producer index.
void consume_latest(size_t count, std::vector< T > &values) const
Consumes latest records added by the producer and updates the local index to the producer index.
size_t size(void) const
Returns the maximum size of the CircularBufferConsumer.
KnowledgeRecord::Integer local_index_
Index for latest item read by.
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.
void resize(void)
Resizes the buffer size to the producer's buffer size.
void check_all(const char *func) const
bool operator==(const CircularBufferConsumer &value) const
Checks for equality.
This class stores an integer within a variable context.
This class stores a vector of KaRL variables.
Provides container classes for fast knowledge base access and mutation.
Provides functions and classes for the distributed knowledge base.
Copyright(c) 2020 Galois.