MADARA  3.4.1
Queue.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_CONTAINERS_QUEUE_H_
3 #define _MADARA_CONTAINERS_QUEUE_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 {
34 class MADARA_EXPORT Queue
35 {
36 public:
41 
50 
57  Queue(const std::string& name, Variables& knowledge,
59 
67  Queue(const std::string& name, KnowledgeBase& knowledge, int size,
69 
77  Queue(const std::string& name, Variables& knowledge, int size,
79 
83  Queue(const Queue& rhs);
84 
88  virtual ~Queue() = default;
89 
94  void operator=(const Queue& rhs);
95 
100  std::string get_name(void) const;
101 
107  void set_name(const std::string& var_name, KnowledgeBase& knowledge);
108 
114  void set_name(const std::string& var_name, Variables& knowledge);
115 
121  bool operator==(const Queue& value) const;
122 
128  bool operator!=(const Queue& value) const;
129 
135  bool enqueue(const knowledge::KnowledgeRecord& record);
136 
142  template<typename... Args>
143  bool emplace(Args&&... args);
144 
159  knowledge::KnowledgeRecord dequeue(bool wait = true);
160 
166  knowledge::KnowledgeRecord inspect(size_t position);
167 
171  void clear(void);
172 
177  size_t count(void);
178 
183  size_t size(void);
184 
190  KnowledgeUpdateSettings set_settings(const KnowledgeUpdateSettings& settings);
191 
198  void set_quality(uint32_t quality,
200  false));
201 
207  void resize(int size = -1);
208 
209 private:
219  {
220  return (base + value) % queue_.size();
221  }
222 
224 
228  mutable MADARA_LOCK_TYPE mutex_;
229 
234 
239 
244 
249 
254 
259 
264 };
265 }
266 }
267 }
268 
269 #include "Queue.inl"
270 
271 #endif // _MADARA_CONTAINERS_QUEUE_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...
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
This class stores an integer within a variable context.
Definition: Integer.h:32
This class stores thread-safe queue within the knowledge base.
Definition: Queue.h:35
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Queue.h:233
Integer count_
Count of elements in queue.
Definition: Queue.h:243
virtual ~Queue()=default
Destructor.
Integer tail_
Tail of the queue.
Definition: Queue.h:253
knowledge::KnowledgeRecord::Integer increment(knowledge::KnowledgeRecord::Integer base, knowledge::KnowledgeRecord::Integer value)
Increments the base by the value, using size as a boundary.
Definition: Queue.h:216
std::string name_
Prefix of variable.
Definition: Queue.h:238
MADARA_LOCK_TYPE mutex_
guard for access and changes
Definition: Queue.h:228
KnowledgeUpdateSettings settings_
Settings for modifications.
Definition: Queue.h:263
Integer head_
Head of the queue.
Definition: Queue.h:248
Vector queue_
Underlying array of records.
Definition: Queue.h:258
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.
auto operator==(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)==r)
auto operator!=(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l) !=r)
Copyright(c) 2020 Galois.