2 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFER_INL_
3 #define _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFER_INL_
30 std::string(
"CircularBuffer::") + func +
": name is empty.");
40 std::string(
"CircularBuffer::") + 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 <<
"CircularBuffer::" << func <<
": ";
74 message <<
"Invalid access because " << reason <<
"\n";
161 std::stringstream message;
162 message <<
"CircularBuffer::increment: ";
163 message <<
"Result of " << base <<
"+" << value <<
" is " << result;
164 message <<
" which is impossible to access with size " <<
size() <<
".\n";
192 for (
auto record : records)
227 if ((position <= 0 && -position < inserted) ||
229 position < inserted))
238 std::stringstream message;
239 message <<
"CircularBuffer::inspect: ";
240 message <<
"Invalid access for " << position <<
" element when count is ";
241 message << inserted <<
"\n";
255 if ((position <= 0 && -position < inserted) ||
257 position < inserted))
262 std::vector<KnowledgeRecord> result;
266 result.push_back(
buffer_[(
size_t)index]);
273 std::stringstream message;
274 message <<
"CircularBuffer::inspect: ";
275 message <<
"Invalid access for " << position <<
" element when count is ";
276 message << inserted <<
"\n";
349 "CircularBuffer::set_name: empty name provided.");
372 "CircularBuffer::set_name: empty name provided.");
391 std::vector<KnowledgeRecord> result;
397 result.push_back(
buffer_[(
size_t)cur]);
409 std::vector<KnowledgeRecord> result;
419 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.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the current value of a variable.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
Provides an interface for external functions into the MADARA KaRL variable settings.
This container stores a thread-safe circular buffer with O(1) access times.
void set_name(const std::string &name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
std::vector< KnowledgeRecord > get_earliest(size_t count) const
Gets the oldest added records up to a specified count.
KnowledgeRecord::Integer increment(KnowledgeRecord::Integer base, KnowledgeRecord::Integer value) const
Increments the base by the value, using size as a boundary.
ThreadSafeContext * context_
guard for access and changes
size_t size(void) const
Returns the maximum size of the CircularBuffer.
std::string name_
Prefix of variable.
Vector buffer_
Underlying array of records.
void check_context(const char *func) const
VariableReference size_ref_
Reference to the size field of the vector space.
void check_all(const char *func) const
KnowledgeUpdateSettings settings_
Settings for modifications.
bool operator!=(const CircularBuffer &value) const
Checks for inequality.
void clear(void)
Clears the CircularBuffer.
std::vector< KnowledgeRecord > get_latest(size_t count) const
Gets the most recently added records up to a specified count.
void set_index(KnowledgeRecord::Integer index)
Sets the index into the circular buffer to an arbitrary position.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the counter variables.
void resize(int size=-1)
Resizes the CircularBuffer.
CircularBuffer(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
void check_name(const char *func) const
Integer index_
Index for latest item in circular buffer.
std::string get_name(void) const
Returns the name of the variable.
KnowledgeUpdateSettings set_settings(const KnowledgeUpdateSettings &settings)
Sets the update settings for the variable.
void add(const knowledge::KnowledgeRecord &record)
Adds a record to the end of the CircularBuffer.
knowledge::KnowledgeRecord get(void) const
Gets the most recently added record.
bool operator==(const CircularBuffer &value) const
Checks for equality.
knowledge::KnowledgeRecord inspect(KnowledgeRecord::Integer position) const
Retrieves a record at a position relative to last added.
size_t count(void) const
Returns the number of records in the CircularBuffer.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
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.