MADARA  3.2.3
Counter.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_CONTAINERS_COUNTER_H_
3 #define _MADARA_CONTAINERS_COUNTER_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 Counter : public BaseContainer
34  {
35  public:
38 
42  Counter (const KnowledgeUpdateSettings & settings =
44 
51  Counter (const std::string & name,
53  const KnowledgeUpdateSettings & settings =
55 
62  Counter (const std::string & name,
63  Variables & knowledge,
64  const KnowledgeUpdateSettings & settings =
66 
76  Counter (const std::string & name,
77  KnowledgeBase & knowledge,
78  int id,
79  int counters,
80  type value = 0,
81  const KnowledgeUpdateSettings & settings =
83 
93  Counter (const std::string & name,
94  Variables & knowledge,
95  int id,
96  int counters,
97  type value = 0,
98  const KnowledgeUpdateSettings & settings =
100 
104  Counter (const Counter & rhs);
105 
109  ~Counter ();
110 
115  void operator= (const Counter & rhs);
116 
121  int get_id (void) const;
122 
127  int get_counters (void) const;
128 
134  void set_name (const std::string & var_name,
135  KnowledgeBase & knowledge);
136 
142  void set_name (const std::string & var_name,
143  Variables & knowledge);
144 
149  void modify (void);
150 
156  type operator= (type value);
157 
163  bool operator== (const Counter & value) const;
164 
170  bool operator!= (const Counter & value) const;
171 
177  bool operator== (type value) const;
178 
184  bool operator!= (type value) const;
185 
191  bool operator< (type value) const;
192 
198  bool operator<= (type value) const;
199 
205  bool operator> (type value) const;
206 
212  bool operator>= (type value) const;
213 
218  type operator* (void) const;
219 
225  void operator+= (type value);
226 
232  void operator-= (type value);
233 
239  void operator++ (void);
240 
246  void operator-- (void);
247 
253  knowledge::KnowledgeRecord to_record (void) const;
254 
259  double to_double (void) const;
260 
265  knowledge::KnowledgeRecord::Integer to_integer (void) const;
266 
271  std::string to_string (void) const;
272 
279  void set_quality (uint32_t quality,
280  const KnowledgeReferenceSettings & settings =
282 
288  void resize (int id = 0, int counters = 1);
289 
299  std::string get_debug_info (void);
300 
306  virtual BaseContainer * clone (void) const;
307 
312  bool is_true (void) const;
313 
318  bool is_false (void) const;
319 
320  private:
321 
326  virtual bool is_true_ (void) const;
327 
332  virtual bool is_false_ (void) const;
333 
342  virtual void modify_ (void);
343 
353  virtual std::string get_debug_info_ (void);
354 
358  void build_aggregate_count (void);
359 
363  void build_var (void);
364 
368  void init_noharm (void);
369 
374  inline type get_count (void) const
375  {
376  return context_->evaluate (aggregate_count_, no_harm).to_integer ();
377  }
378 
383  inline std::string get_count_string (void) const
384  {
385  return context_->evaluate (aggregate_count_, no_harm).to_string ();
386  }
387 
392  inline double get_count_double (void) const
393  {
394  return context_->evaluate (aggregate_count_, no_harm).to_double ();
395  }
396 
402  {
403  return context_->evaluate (aggregate_count_, no_harm);
404  }
405 
410 
415 
419  int id_;
420 
425 
430 
435  };
436  }
437  }
438 }
439 
440 #endif // _MADARA_NO_KARL_
441 
442 #endif // _MADARA_CONTAINERS_COUNTER_H_
This class encapsulates an entry in a KnowledgeBase.
auto operator+=(KnowledgeRecord &l, const T &r) -> decltype(l+=knowledge_cast(r))
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)
auto operator==(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)==r)
int counters_
the number of counters in the counter ring
Definition: Counter.h:424
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Counter.h:409
auto operator--(Tracked< T > &lhs) -> decltype(--lhs.get_mut())
Definition: Tracked.h:302
int id_
id of this counter in the counter ring
Definition: Counter.h:419
This class stores variables and their values for use by any entity needing state information in a thr...
VariableReference variable_
Variable reference.
Definition: Counter.h:414
Optimized reference to a variable within the knowledge base.
CompiledExpression aggregate_count_
Expression for aggregating count in one atomic operation.
Definition: Counter.h:429
Compiled, optimized KaRL logic.
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
static struct madara::knowledge::tags::string_t string
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: Counter.h:37
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
knowledge::KnowledgeRecord get_count_record(void) const
Counts all counter variables.
Definition: Counter.h:401
auto operator*(const KnowledgeRecord &l, const T &r) -> decltype(l *knowledge_cast(r))
auto operator-=(KnowledgeRecord &l, const T &r) -> decltype(l-=knowledge_cast(r))
auto operator<=(const KnowledgeRecord &l, const T &r) -> decltype(knowledge_cast< T >(l)<=r)
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:27
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.
This class stores an integer within a variable context.
Definition: Counter.h:33
std::string get_count_string(void) const
Counts all counter variables.
Definition: Counter.h:383
Settings for applying knowledge updates.
EvalSettings no_harm
Settings we&#39;ll use for all evaluations.
Definition: Counter.h:434
double get_count_double(void) const
Counts all counter variables.
Definition: Counter.h:392
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
type get_count(void) const
Counts all counter variables.
Definition: Counter.h:374
auto operator++(Tracked< T > &lhs) -> decltype(++lhs.get_mut())
Definition: Tracked.h:301