MADARA  3.4.1
CircularBufferConsumer.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_H_
3 #define _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_H_
4 
5 #include <vector>
6 #include <string>
7 #include "madara/LockType.h"
11 #include "Vector.h"
12 #include "Integer.h"
13 
21 namespace madara
22 {
23 namespace knowledge
24 {
25 namespace containers
26 {
35 {
36 public:
41 
49 
57 
61  virtual ~CircularBufferConsumer() = default;
62 
67  std::string get_name(void) const;
68 
75  void set_name(const std::string& name, KnowledgeBase& knowledge);
76 
83  void set_name(const std::string& name, Variables& knowledge);
84 
90  bool operator==(const CircularBufferConsumer& value) const;
91 
97  bool operator!=(const CircularBufferConsumer& value) const;
98 
105  KnowledgeRecord consume(void) const;
106 
117  KnowledgeRecord consume(size_t& dropped) const;
118 
124  template<typename T>
125  void consume(T& value) const;
126 
136  template<typename T>
137  void consume(T& value, size_t& dropped) const;
138 
145  std::vector<KnowledgeRecord> consume_latest(size_t count) const;
146 
158  std::vector<KnowledgeRecord> consume_latest(
159  size_t count, size_t& dropped) const;
160 
168  template<typename T>
169  void consume_latest(size_t count, std::vector<T>& values) const;
170 
182  template<typename T>
184  size_t count, std::vector<T>& values, size_t& dropped) const;
185 
192  std::vector<KnowledgeRecord> consume_earliest(size_t count) const;
193 
204  std::vector<KnowledgeRecord> consume_earliest(
205  size_t count, size_t& dropped) const;
206 
213  template<typename T>
214  void consume_earliest(size_t count, std::vector<T>& values) const;
215 
226  template<typename T>
228  size_t count, std::vector<T>& values, size_t& dropped) const;
229 
234  size_t get_dropped(void) const;
235 
246 
256  template<typename T>
257  void inspect(KnowledgeRecord::Integer position, T& value) const;
258 
269  std::vector<KnowledgeRecord> inspect(
270  KnowledgeRecord::Integer position, size_t count) const;
271 
282  template<typename T>
283  void inspect(KnowledgeRecord::Integer position, size_t count,
284  std::vector<T>& values) const;
285 
295 
304  template<typename T>
305  void peek_latest(T& value) const;
306 
315  std::vector<KnowledgeRecord> peek_latest(size_t count) const;
316 
325  template<typename T>
326  void peek_latest(size_t count, std::vector<T>& values) const;
327 
335  size_t remaining(void) const;
336 
343  size_t count(void) const;
344 
349  size_t size(void) const;
350 
354  void resize(void);
355 
361 
365  void resync(void);
366 
367 private:
376 
378 
383 
388 
393 
398 
403 
404  // Call to throw if preconditions aren't met
405  void check_name(const char* func) const;
406  void check_context(const char* func) const;
407  void check_all(const char* func) const;
408 };
409 }
410 }
411 }
412 
414 
415 #endif // _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFERCONSUMER_H_
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
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.
Definition: Variables.h:53
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,...
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.
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.
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.
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.
bool operator==(const CircularBufferConsumer &value) const
Checks for equality.
This class stores an integer within a variable context.
Definition: Integer.h:32
This class stores a vector of KaRL variables.
Definition: Vector.h:36
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
Copyright(c) 2020 Galois.