2 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_INL_
3 #define _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_INL_
30 std::string(
"CircularBufferConsumer::") + func +
": name is empty.");
40 func +
": context is not set.");
49 reason =
"context has not been set";
54 if (reason.size() > 0)
58 reason =
"name has not been set";
63 if (reason.size() > 0)
72 std::stringstream message;
73 message <<
"CircularBufferConsumer::" << func <<
": ";
74 message <<
"Invalid access because " << reason <<
"\n";
126 std::stringstream message;
127 message <<
"CircularBufferConsumer::increment: ";
128 message <<
"Result of " << base <<
"+" << value <<
" is " << result;
129 message <<
" which is impossible to access with size " <<
size() <<
".\n";
160 size_t& dropped)
const
202 if (0 <= requested_index &&
204 requested_index <= *
index_)
213 std::stringstream message;
214 message <<
"CircularBufferConsumer::inspect: ";
215 message <<
"Invalid access for relative position " << position
216 <<
" when buffer index is ";
218 <<
" and size is : " <<
size() <<
"\n";
239 if (0 <= requested_index &&
241 requested_index <= *
index_)
246 std::vector<KnowledgeRecord> result;
250 result.push_back(
buffer_[(
size_t)index]);
257 std::stringstream message;
258 message <<
"CircularBufferConsumer::inspect: ";
259 message <<
"Invalid access for relative position " << position
260 <<
" when buffer index is ";
262 <<
" and size is : " <<
size() <<
"\n";
315 "CircularBufferConsumer::resync: "
316 " context is null or name hasn't been set.");
335 "CircularBufferConsumer::set_name: empty name provided.");
354 "CircularBufferConsumer::set_name: empty name provided.");
372 std::vector<KnowledgeRecord> result;
380 result.push_back(
buffer_[(
size_t)cur]);
390 size_t count,
size_t& dropped)
const
396 std::vector<KnowledgeRecord> result;
406 result.push_back(
buffer_[(
size_t)cur]);
421 std::vector<KnowledgeRecord> result;
442 result.push_back(
buffer_[(
size_t)cur]);
451 size_t count,
size_t& dropped)
const
456 std::vector<KnowledgeRecord> result;
472 result.push_back(
buffer_[(
size_t)cur]);
487 size_t buffer_size =
size();
489 if (difference > buffer_size)
491 return difference - buffer_size;
508 std::vector<KnowledgeRecord> result;
514 result.push_back(
buffer_[(
size_t)cur]);
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for attempting to access an invalid context1.
An exception for out-of-bounds accessing in arrays/vectors.
An exception for setting an invalid name in MADARA.
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the current value of a variable.
Provides an interface for external functions into the MADARA KaRL variable settings.
This container stores a thread-safe, personalized consumer for CircularBuffer instances.
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 set_name(const std::string &name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
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.
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.
Integer index_
Index for latest item in circular buffer.
std::string name_
Prefix of variable.
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
Vector buffer_
Underlying array of records.
size_t size(void) const
Returns the maximum size of the CircularBufferConsumer.
KnowledgeRecord::Integer local_index_
Index for latest item read by.
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.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
std::vector< VariableReference > vector_
Values of the array.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
size_t size(void) const
Returns the size of the local vector.
Provides container classes for fast knowledge base access and mutation.
Provides functions and classes for the distributed knowledge base.
Copyright(c) 2020 Galois.