MADARA  3.2.3
Barrier.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_CONTAINERS_BARRIER_H_
3 #define _MADARA_CONTAINERS_BARRIER_H_
4 
5 #ifndef _MADARA_NO_KARL_
6 
7 #include <vector>
8 #include <string>
9 #include "madara/LockType.h"
13 #include "BaseContainer.h"
14 
23 namespace madara
24 {
25  namespace knowledge
26  {
27  namespace containers
28  {
33  class MADARA_EXPORT Barrier : public BaseContainer
34  {
35  public:
38 
42  Barrier (const KnowledgeUpdateSettings & settings =
44 
51  Barrier (const std::string & name,
53  const KnowledgeUpdateSettings & settings =
55 
62  Barrier (const std::string & name,
63  Variables & knowledge,
64  const KnowledgeUpdateSettings & settings =
66 
75  Barrier (const std::string & name,
76  KnowledgeBase & knowledge,
77  int id,
78  int participants,
79  const KnowledgeUpdateSettings & settings =
81 
90  Barrier (const std::string & name,
91  Variables & knowledge,
92  int id,
93  int participants,
94  const KnowledgeUpdateSettings & settings =
96 
100  Barrier (const Barrier & rhs);
101 
105  ~Barrier ();
106 
111  void operator= (const Barrier & rhs);
112 
117  size_t get_id (void) const;
118 
123  size_t get_participants (void) const;
124 
129  inline type get_round (void) const
130  {
131  return to_integer ();
132  }
133 
138  void set (type value);
139 
147  void set_name (const std::string & var_name,
148  KnowledgeBase & knowledge,
149  int id,
150  int participants);
151 
159  void set_name (const std::string & var_name,
160  Variables & knowledge,
161  int id,
162  int participants);
163 
171  void set_name (const std::string & var_name,
172  ThreadSafeContext & knowledge,
173  int id,
174  int participants);
175 
181  type operator= (type value);
182 
186  void next (void);
187 
192  bool is_done (void);
193 
198  void modify (void);
199 
205  knowledge::KnowledgeRecord to_record (void) const;
206 
211  double to_double (void) const;
212 
217  knowledge::KnowledgeRecord::Integer to_integer (void) const;
218 
223  std::string to_string (void) const;
224 
230  bool operator== (const Barrier & value) const;
231 
237  bool operator!= (const Barrier & value) const;
238 
245  void set_quality (uint32_t quality,
246  const KnowledgeReferenceSettings & settings =
248 
254  void resize (size_t id = 0, size_t participants = 1);
255 
265  std::string get_debug_info (void);
266 
272  virtual BaseContainer * clone (void) const;
273 
278  bool is_true (void) const;
279 
284  bool is_false (void) const;
285 
286  private:
287 
292  virtual bool is_true_ (void) const;
293 
298  virtual bool is_false_ (void) const;
299 
308  virtual void modify_ (void);
309 
319  virtual std::string get_debug_info_ (void);
320 
324  void build_aggregate_barrier (void);
325 
330  inline type barrier_result (void) const
331  {
332  return context_->evaluate (aggregate_barrier_, no_harm).to_integer ();
333  }
334 
338  void build_var (void);
339 
343  void init_noharm (void);
344 
349 
354 
358  size_t id_;
359 
364 
369 
374 
379  };
380  }
381  }
382 }
383 
384 
385 
386 #endif // _MADARA_NO_KARL_
387 
388 
389 #endif // _MADARA_CONTAINERS_BARRIER_H_
This class encapsulates an entry in a KnowledgeBase.
auto operator==(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)==r)
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
Definition: Barrier.h:37
This class stores variables and their values for use by any entity needing state information in a thr...
size_t id_
id of this barrier in the barrier ring
Definition: Barrier.h:358
Optimized reference to a variable within the knowledge base.
Compiled, optimized KaRL logic.
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Barrier.h:348
CompiledExpression aggregate_barrier_
Expression for aggregating barrier in one atomic operation.
Definition: Barrier.h:368
static struct madara::knowledge::tags::string_t string
VariableReference variable_
Variable reference.
Definition: Barrier.h:353
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
type barrier_result(void) const
Checks if current barrier is successful.
Definition: Barrier.h:330
type get_round(void) const
Returns the current barrier round.
Definition: Barrier.h:129
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:27
size_t participants_
the number of participants in the barrier ring
Definition: Barrier.h:363
std::string variable_name_
Holder for variable name to quickly refresh modified status.
Definition: Barrier.h:378
auto operator!=(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)!=r)
Provides functions and classes for the distributed knowledge base.
EvalSettings no_harm
Settings we&#39;ll use for all evaluations.
Definition: Barrier.h:373
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
This class stores an integer within a variable context.
Definition: Barrier.h:33
Settings for applying knowledge updates.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
Definition: BaseContainer.h:33