2 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_NATIVECIRCULARBUFFERCONSUMER_INL_
3 #define _MADARA_KNOWLEDGE_CONTAINERS_NATIVECIRCULARBUFFERCONSUMER_INL_
26 const char* func,
const char* name)
28 if (name ==
nullptr || name[0] ==
'\0')
31 std::string(
"NativeCircularBufferConsumer::") + func +
41 std::string(
"NativeCircularBufferConsumer::") + func +
42 ": context is not set.");
48 std::string(
"NativeCircularBufferConsumer::") + func +
49 ": underlying record is not set.");
91 value = knowledge_cast<T>(
consume(dropped));
96 size_t count, std::vector<T>& values)
const
102 if (record.is_valid())
104 values.push_back(knowledge_cast<T>(record));
124 std::reverse(ret_vec.begin(), ret_vec.end());
148 size_t count, std::vector<T>& values)
const
154 if (record.is_valid())
155 values.push_back(knowledge_cast<T>(record));
161 size_t count, std::vector<T>& values,
size_t& dropped)
const
169 if (record.is_valid())
170 values.push_back(knowledge_cast<T>(record));
174 inline std::vector<KnowledgeRecord>
183 std::vector<KnowledgeRecord> result;
194 std::reverse(ret_vec.begin(), ret_vec.end());
220 inline std::vector<KnowledgeRecord>
222 size_t count,
size_t& dropped)
const
251 size_t& dropped)
const
284 size_t count, std::vector<T>& values)
const
289 values.push_back(knowledge_cast<T>(record));
294 size_t count,
size_t& dropped)
const
302 std::vector<KnowledgeRecord> ret_vec;
303 for (
size_t consume_counter = 0; consume_counter <
count; ++consume_counter)
305 ret_vec.emplace_back(
consume());
318 std::vector<KnowledgeRecord> ret_vec;
319 for (
size_t consume_counter = 0; consume_counter <
count; ++consume_counter)
321 ret_vec.emplace_back(
consume());
332 value = knowledge_cast<T>(
inspect(position));
352 size_t count, std::vector<T>& values)
const
358 values.push_back(knowledge_cast<T>(record));
380 std::vector<KnowledgeRecord> ret_vec;
381 for (
size_t inspect_counter = 0; inspect_counter <
count; ++inspect_counter)
386 ret_vec.emplace_back(std::move(ret));
const ThreadSafeContext * context_
madara::knowledge::KnowledgeRecord KnowledgeRecord
An exception for attempting to access an invalid context1.
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.
size_t get_history_capacity() const
Return the maximum amount of history this record can hold.
size_t get_history_newest_index() const
Gets the absolute index of the newest element in stored history.
size_t get_history_oldest_index() const
Gets the absolute index of the oldest element in stored history.
size_t get_history_range(OutputIterator out, size_t index, size_t count) const
Copy the given absolute range of history to the output iterator given.
size_t get_history_size() const
Return the amount of history this record holds.
size_t get_newest(OutputIterator out, size_t count) const
Copy the count newest stored history entries of this record to the given output iterator,...
This class stores variables and their values for use by any entity needing state information in a thr...
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
const char * get_name(void) const
Returns the name of the variable.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
KnowledgeRecord * get_record_unsafe(void) const
Returns a pointer to the variable's KnowledgeRecord Do not use this pointer unless you've locked the ...
Provides an interface for external functions into the MADARA KaRL variable settings.
This class provides an interface similar to CircularBufferConsumer, which uses the internal history b...
static void check_name(const char *func, const char *name)
VariableReference ref_
Reference to underlying record we are reading.
void inspect(KnowledgeRecord::Integer position, T &value) const
Retrieves a record at a position relative to local index.
void consume_many(size_t count, std::vector< T > &values) const
Consumes (earliest) records from the local index.
void set_index(size_t index)
Sets the local index to an arbitrary position.
std::string get_name(void) const
Returns the name of the variable.
madara::knowledge::KnowledgeRecord consume(void) const
Consumes the record at the local index (not the producer index)
madara::knowledge::KnowledgeRecord consume_latest(void) const
Consumes the latest the record at the local index (not the producer index).
size_t local_index_
Index for latest item read by.
void set_name(const std::string &name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
KnowledgeRecord get_record() const
Get the KnowledgeRecord this container refers to.
ThreadSafeContext * context_
Variable context that we are modifying.
size_t get_dropped(void) const
Returns the number of known drops since last consume.
void check_context(const char *func) const
bool operator==(const NativeCircularBufferConsumer &value) const
Checks for equality.
size_t count(void) const
Returns the number of records in the NativeCircularBufferConsumer.
size_t remaining(void) const
Returns the number of records remaining that have not been consumed.
madara::knowledge::KnowledgeRecord peek_latest(void) const
Peeks, but does not consume, the latest the record at the local index (not the producer index).
NativeCircularBufferConsumer()
Default constructor.
size_t size(void) const
Returns the maximum size of the NativeCircularBufferConsumer.
bool operator!=(const NativeCircularBufferConsumer &value) const
Checks for inequality.
Provides container classes for fast knowledge base access and mutation.
Provides functions and classes for the distributed knowledge base.
Copyright(c) 2020 Galois.