MADARA  3.2.3
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:
40  Queue (const KnowledgeUpdateSettings & settings =
42 
49  Queue (const std::string & name,
51  const KnowledgeUpdateSettings & settings =
53 
60  Queue (const std::string & name,
61  Variables & knowledge,
62  const KnowledgeUpdateSettings & settings =
64 
72  Queue (const std::string & name,
73  KnowledgeBase & knowledge,
74  int size,
75  const KnowledgeUpdateSettings & settings =
77 
85  Queue (const std::string & name,
86  Variables & knowledge,
87  int size,
88  const KnowledgeUpdateSettings & settings =
90 
94  Queue (const Queue & rhs);
95 
99  virtual ~Queue () = default;
100 
105  void operator= (const Queue & rhs);
106 
111  std::string get_name (void) const;
112 
118  void set_name (const std::string & var_name,
119  KnowledgeBase & knowledge);
120 
126  void set_name (const std::string & var_name,
127  Variables & knowledge);
128 
134  bool operator== (const Queue & value) const;
135 
141  bool operator!= (const Queue & value) const;
142 
148  bool enqueue (const knowledge::KnowledgeRecord & record);
149 
155  template<typename... Args>
156  bool emplace (Args&&... args);
157 
172  knowledge::KnowledgeRecord dequeue (bool wait = true);
173 
179  knowledge::KnowledgeRecord inspect (size_t position);
180 
184  void clear (void);
185 
190  size_t count (void);
191 
196  size_t size (void);
197 
203  KnowledgeUpdateSettings set_settings (
204  const KnowledgeUpdateSettings & settings);
205 
212  void set_quality (uint32_t quality,
213  const KnowledgeReferenceSettings & settings =
215 
221  void resize (int size = -1);
222 
223  private:
233  {
234  return (base + value) % queue_.size ();
235  }
236 
237 
239 
240 
244  mutable MADARA_LOCK_TYPE mutex_;
245 
250 
255 
260 
265 
270 
275 
280  };
281  }
282  }
283 }
284 
285 
286 #include "Queue.inl"
287 
288 #endif // _MADARA_CONTAINERS_QUEUE_H_
This class encapsulates an entry in a KnowledgeBase.
auto operator==(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)==r)
Integer tail_
Tail of the queue.
Definition: Queue.h:269
This class stores variables and their values for use by any entity needing state information in a thr...
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
Integer count_
Count of elements in queue.
Definition: Queue.h:259
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:230
std::string name_
Prefix of variable.
Definition: Queue.h:254
This class stores a vector of KaRL variables.
Definition: Vector.h:35
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Queue.h:249
static struct madara::knowledge::tags::string_t string
Vector queue_
Underlying array of records.
Definition: Queue.h:274
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class stores an integer within a variable context.
Definition: Integer.h:31
Integer head_
Head of the queue.
Definition: Queue.h:264
KnowledgeUpdateSettings settings_
Settings for modifications.
Definition: Queue.h:279
This class stores thread-safe queue within the knowledge base.
Definition: Queue.h:34
auto operator!=(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)!=r)
Provides functions and classes for the distributed knowledge base.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
Settings for applying knowledge updates.
MADARA_LOCK_TYPE mutex_
guard for access and changes
Definition: Queue.h:244
Provides an interface for external functions into the MADARA KaRL variable settings.