MADARA  3.4.1
NativeCircularBufferConsumer.h
Go to the documentation of this file.
1 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_NATIVECIRCULARBUFFERCONSUMER_H_
2 #define _MADARA_KNOWLEDGE_CONTAINERS_NATIVECIRCULARBUFFERCONSUMER_H_
3 
4 #include <vector>
5 #include <string>
6 #include "madara/LockType.h"
10 #include "Vector.h"
11 #include "Integer.h"
12 
24 namespace madara
25 {
26 namespace knowledge
27 {
28 namespace containers
29 {
49 {
50 public:
55 
63  const std::string& name, KnowledgeBase& knowledge);
64 
72 
76  virtual ~NativeCircularBufferConsumer() = default;
77 
82  std::string get_name(void) const;
83 
90  void set_name(const std::string& name, KnowledgeBase& knowledge);
91 
98  void set_name(const std::string& name, Variables& knowledge);
99 
106  void set_name(const std::string& name, ThreadSafeContext& context);
107 
113  bool operator==(const NativeCircularBufferConsumer& value) const;
114 
120  bool operator!=(const NativeCircularBufferConsumer& value) const;
121 
128  inline madara::knowledge::KnowledgeRecord consume(void) const;
129 
140  KnowledgeRecord consume(size_t& dropped) const;
141 
151  template<typename T>
152  void consume(T& value, size_t& dropped) const;
153 
161  template<typename T>
162  void peek_latest(size_t count, std::vector<T>& values) const;
163 
171  inline std::vector<KnowledgeRecord> peek_latest(size_t count) const;
172 
180 
188  inline std::vector<KnowledgeRecord> consume_latest(size_t count) const;
189 
197 
206  std::vector<KnowledgeRecord> consume_latest(
207  size_t count, size_t& dropped) const;
208 
216  template<typename T>
217  void consume_latest(size_t count, std::vector<T>& values) const;
218 
227  template<typename T>
228  void consume_latest(
229  size_t count, std::vector<T>& values, size_t& dropped) const;
230 
236  size_t get_dropped(void) const;
237 
246  size_t remaining(void) const;
247 
255  size_t count(void) const;
256 
261  size_t size(void) const;
262 
267  size_t get_index()
268  {
269  return local_index_;
270  }
271 
276  void set_index(size_t index);
277 
284  KnowledgeRecord get_record() const;
285 
292  template<typename T>
293  void consume_many(size_t count, std::vector<T>& values) const;
294 
303  std::vector<KnowledgeRecord> consume_many(size_t count) const;
304 
316  std::vector<KnowledgeRecord> consume_many(
317  size_t count, size_t& dropped) const;
318 
329  template<typename T>
330  void inspect(KnowledgeRecord::Integer position, T& value) const;
331 
342  std::vector<KnowledgeRecord> inspect(
343  KnowledgeRecord::Integer position, size_t count) const;
344 
356  template<typename T>
357  void inspect(KnowledgeRecord::Integer position, size_t count,
358  std::vector<T>& values) const;
359 
372  KnowledgeRecord::Integer position) const;
373 
374 private:
379 
384 
388  mutable size_t local_index_;
389 
390  // Call to throw if preconditions aren't met
391  static void check_name(const char* func, const char* name);
392  void check_context(const char* func) const;
393 };
394 } // containers
395 } // knowledge
396 } // madara
397 
399 
400 #endif // _MADARA_KNOWLEDGE_CONTAINERS_NATIVECIRCULARBUFFERCONSUMER_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...
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
This class provides an interface similar to CircularBufferConsumer, which uses the internal history b...
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).
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.
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).
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.
Definition: Barrier.h:27
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
Copyright(c) 2020 Galois.