MADARA  3.4.1
CircularBuffer.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFER_H_
3 #define _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFER_H_
4 
5 #include <vector>
6 #include <string>
7 #include "madara/MadaraExport.h"
8 #include "madara/LockType.h"
12 #include "Vector.h"
13 #include "Integer.h"
14 
22 namespace madara
23 {
24 namespace knowledge
25 {
26 namespace containers
27 {
34 {
35 public:
41 
51 
61 
72 
83 
87  virtual ~CircularBuffer() = default;
88 
93  std::string get_name(void) const;
94 
101  void set_name(const std::string& name, KnowledgeBase& knowledge);
102 
109  void set_name(const std::string& name, Variables& knowledge);
110 
116  bool operator==(const CircularBuffer& value) const;
117 
123  bool operator!=(const CircularBuffer& value) const;
124 
130  void add(const knowledge::KnowledgeRecord& record);
131 
137  template<typename T>
138  void add(const T& value);
139 
145  void add(const std::vector<KnowledgeRecord>& records);
146 
152  template<typename T>
153  void add(const std::vector<T>& values);
154 
160  knowledge::KnowledgeRecord get(void) const;
161 
167  template<typename T>
168  void get(T& value) const;
169 
176  std::vector<KnowledgeRecord> get_latest(size_t count) const;
177 
184  template<typename T>
185  void get_latest(size_t count, std::vector<T>& values) const;
186 
193  std::vector<KnowledgeRecord> get_earliest(size_t count) const;
194 
201  template<typename T>
202  void get_earliest(size_t count, std::vector<T>& values) const;
203 
214 
224  template<typename T>
225  void inspect(KnowledgeRecord::Integer position, T& value) const;
226 
237  std::vector<KnowledgeRecord> inspect(
238  KnowledgeRecord::Integer position, size_t count) const;
239 
250  template<typename T>
251  void inspect(KnowledgeRecord::Integer position, size_t count,
252  std::vector<T>& values) const;
253 
259  void clear(void);
260 
267  size_t count(void) const;
268 
273  size_t size(void) const;
274 
281 
288  void set_quality(uint32_t quality,
290  false));
291 
297  void resize(int size = -1);
298 
304 
305 private:
314 
316 
321 
326 
331 
336 
341 
346 
347  // Call to throw if preconditions aren't met
348  void check_name(const char* func) const;
349  void check_context(const char* func) const;
350  void check_all(const char* func) const;
351 };
352 }
353 }
354 }
355 
356 #include "CircularBuffer.inl"
357 
358 #endif // _MADARA_KNOWLEDGE_CONTAINERS_CIRCULARBUFFER_H_
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
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 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
void add(const T &value)
Adds a value to the end of the CircularBuffer.
VariableReference size_ref_
Reference to the size field of the vector space.
void add(const std::vector< T > &values)
Adds a list of user values to the end of the CircularBuffer.
void inspect(KnowledgeRecord::Integer position, size_t count, std::vector< T > &values) const
Retrieves a vector of records at a position relative to last added.
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 inspect(KnowledgeRecord::Integer position, T &value) const
Retrieves a record at a position relative to last added.
virtual ~CircularBuffer()=default
Destructor.
void set_index(KnowledgeRecord::Integer index)
Sets the index into the circular buffer to an arbitrary position.
void get_earliest(size_t count, std::vector< T > &values) const
Gets the oldest added values up to a specified count.
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 get_latest(size_t count, std::vector< T > &values) const
Gets the most recently added values up to a specified count.
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 get(T &value) const
Gets the most recently added user value.
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.