MADARA  3.4.1
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 
43 
52 
59  Counter(const std::string& name, Variables& knowledge,
61 
71  Counter(const std::string& name, KnowledgeBase& knowledge, int id,
72  int counters, type value = 0,
74 
84  Counter(const std::string& name, Variables& knowledge, int id, int counters,
85  type value = 0,
87 
91  Counter(const Counter& rhs);
92 
96  ~Counter();
97 
102  void operator=(const Counter& rhs);
103 
108  int get_id(void) const;
109 
114  int get_counters(void) const;
115 
121  void set_name(const std::string& var_name, KnowledgeBase& knowledge);
122 
128  void set_name(const std::string& var_name, Variables& knowledge);
129 
134  void modify(void);
135 
141  type operator=(type value);
142 
148  bool operator==(const Counter& value) const;
149 
155  bool operator!=(const Counter& value) const;
156 
162  bool operator==(type value) const;
163 
169  bool operator!=(type value) const;
170 
176  bool operator<(type value) const;
177 
183  bool operator<=(type value) const;
184 
190  bool operator>(type value) const;
191 
197  bool operator>=(type value) const;
198 
203  type operator*(void)const;
204 
210  void operator+=(type value);
211 
217  void operator-=(type value);
218 
224  void operator++(void);
225 
231  void operator--(void);
232 
238  knowledge::KnowledgeRecord to_record(void) const;
239 
244  double to_double(void) const;
245 
250  knowledge::KnowledgeRecord::Integer to_integer(void) const;
251 
256  std::string to_string(void) const;
257 
264  void set_quality(uint32_t quality,
266  false));
267 
273  void resize(int id = 0, int counters = 1);
274 
284  std::string get_debug_info(void);
285 
291  virtual BaseContainer* clone(void) const;
292 
297  bool is_true(void) const;
298 
303  bool is_false(void) const;
304 
305 private:
310  virtual bool is_true_(void) const;
311 
316  virtual bool is_false_(void) const;
317 
326  virtual void modify_(void);
327 
337  virtual std::string get_debug_info_(void);
338 
342  void build_aggregate_count(void);
343 
347  void build_var(void);
348 
352  void init_noharm(void);
353 
358  inline type get_count(void) const
359  {
360  return context_->evaluate(aggregate_count_, no_harm).to_integer();
361  }
362 
367  inline std::string get_count_string(void) const
368  {
369  return context_->evaluate(aggregate_count_, no_harm).to_string();
370  }
371 
376  inline double get_count_double(void) const
377  {
378  return context_->evaluate(aggregate_count_, no_harm).to_double();
379  }
380 
386  {
387  return context_->evaluate(aggregate_count_, no_harm);
388  }
389 
394 
399 
403  int id_;
404 
409 
414 
419 };
420 }
421 }
422 }
423 
424 #endif // _MADARA_NO_KARL_
425 
426 #endif // _MADARA_CONTAINERS_COUNTER_H_
const ThreadSafeContext * context_
Compiled, optimized KaRL logic.
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 class is an abstract base class for all containers.
Definition: BaseContainer.h:34
This class stores an integer within a variable context.
Definition: Counter.h:34
CompiledExpression aggregate_count_
Expression for aggregating count in one atomic operation.
Definition: Counter.h:413
VariableReference variable_
Variable reference.
Definition: Counter.h:398
double get_count_double(void) const
Counts all counter variables.
Definition: Counter.h:376
std::string get_count_string(void) const
Counts all counter variables.
Definition: Counter.h:367
type get_count(void) const
Counts all counter variables.
Definition: Counter.h:358
EvalSettings no_harm
Settings we'll use for all evaluations.
Definition: Counter.h:418
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
Definition: Counter.h:37
int counters_
the number of counters in the counter ring
Definition: Counter.h:408
int id_
id of this counter in the counter ring
Definition: Counter.h:403
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Counter.h:393
knowledge::KnowledgeRecord get_count_record(void) const
Counts all counter variables.
Definition: Counter.h:385
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-=(KnowledgeRecord &l, const T &r) -> decltype(l -=knowledge_cast(r))
auto operator*(const 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)
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)
Copyright(c) 2020 Galois.
Encapsulates settings for an evaluation statement.
Definition: EvalSettings.h:26