2 #ifndef _MADARA_NO_KARL_
71 variable_(rhs.variable_),
73 counters_(rhs.counters_),
74 aggregate_count_(rhs.aggregate_count_)
84 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
87 this->name_ = rhs.
name_;
101 MADARA_GUARD_TYPE guard(mutex_);
103 std::stringstream buffer;
111 for (
int i = 1; i < counters_; ++i)
120 aggregate_count_ =
context_->compile(buffer.str());
122 else if (name_ ==
"")
124 context_->print(
"ERROR: containers::Counter needs a name.\n", 0);
138 MADARA_GUARD_TYPE guard(mutex_);
140 std::stringstream buffer;
146 variable_ =
context_->get_ref(buffer.str(), no_harm);
148 else if (name_ ==
"")
150 context_->print(
"ERROR: Container::Counter needs a name.\n", 0);
161 no_harm.always_overwrite =
false;
162 no_harm.delay_sending_modifieds =
true;
163 no_harm.expand_variables =
false;
164 no_harm.signal_changes =
false;
165 no_harm.track_local_changes =
false;
166 no_harm.treat_globals_as_locals =
true;
180 std::stringstream result;
182 result <<
"Counter: ";
187 MADARA_GUARD_TYPE guard(mutex_);
189 result << this->name_;
190 result <<
" = " <<
context_->get(variable_).to_string();
191 result <<
" (total: " << get_count() <<
")";
204 return get_debug_info();
215 MADARA_GUARD_TYPE guard(mutex_);
221 MADARA_GUARD_TYPE guard(mutex_);
232 MADARA_GUARD_TYPE guard(mutex_);
237 this->build_aggregate_count();
247 MADARA_GUARD_TYPE guard(mutex_);
252 this->build_aggregate_count();
260 MADARA_GUARD_TYPE guard(mutex_);
263 counters_ = counters;
266 this->build_aggregate_count();
276 MADARA_GUARD_TYPE guard(mutex_);
277 context_->set(variable_, value, settings_);
288 MADARA_GUARD_TYPE guard(mutex_);
289 return get_count() == value;
300 MADARA_GUARD_TYPE guard(mutex_);
301 return get_count() != value;
313 MADARA_GUARD_TYPE guard(mutex_);
326 MADARA_GUARD_TYPE guard(mutex_);
338 MADARA_GUARD_TYPE guard(mutex_);
339 return get_count() < value;
350 MADARA_GUARD_TYPE guard(mutex_);
351 return get_count() <= value;
362 MADARA_GUARD_TYPE guard(mutex_);
363 return get_count() > value;
374 MADARA_GUARD_TYPE guard(mutex_);
375 return get_count() >= value;
395 MADARA_GUARD_TYPE guard(mutex_);
396 result = get_count_record();
410 MADARA_GUARD_TYPE guard(mutex_);
411 result = get_count();
423 MADARA_GUARD_TYPE guard(mutex_);
425 current =
context_->get(variable_, settings_).to_integer();
427 context_->set(variable_, current, settings_);
437 MADARA_GUARD_TYPE guard(mutex_);
439 current =
context_->get(variable_, settings_).to_integer();
441 context_->set(variable_, current, settings_);
450 MADARA_GUARD_TYPE guard(mutex_);
451 context_->inc(variable_, settings_);
460 MADARA_GUARD_TYPE guard(mutex_);
461 context_->dec(variable_, settings_);
472 MADARA_GUARD_TYPE guard(mutex_);
473 result = get_count_double();
486 MADARA_GUARD_TYPE guard(mutex_);
487 result = get_count_string();
499 MADARA_GUARD_TYPE guard(mutex_);
500 context_->set_quality(name_, quality,
true, settings);
509 "Counter::is_true: checking local counter for non-zero\n");
514 MADARA_GUARD_TYPE guard(mutex_);
515 result =
context_->get(variable_, settings_).is_true();
519 "Counter::is_true: final result is %d\n", (
int)result);
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
This class stores an integer within a variable context.
void operator+=(type value)
Increments by a value.
CompiledExpression aggregate_count_
Expression for aggregating count in one atomic operation.
double to_double(void) const
Returns the value as a double.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the counter variables.
void operator--(void)
Decrements the value of the variable and returns the result.
bool operator>=(type value) const
Checks for greater than or equal to relationship.
void build_aggregate_count(void)
Builds the aggregate counter logic.
int get_id(void) const
Returns the id of the counter in the counter ring.
bool operator<(type value) const
Checks for less than relationship.
void init_noharm(void)
Initialize the no harm eval settings.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
std::string to_string(void) const
Returns the value as a string.
VariableReference variable_
Variable reference.
bool operator!=(const Counter &value) const
Checks for inequality.
void resize(int id=0, int counters=1)
Resizes the counter, usually when number of counters change.
virtual BaseContainer * clone(void) const
Clones this container.
void operator-=(type value)
Decrements by a value.
virtual bool is_false_(void) const
Polymorphic is false method which can be used to determine if at least one value in the container is ...
void operator++(void)
Increments the value of the variable and returns the result.
bool is_true(void) const
Determines if the local count is not zero.
int get_counters(void) const
Returns the number of counters in the counter ring.
void modify(void)
Mark the value as modified.
Counter(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
type get_count(void) const
Counts all counter variables.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
type operator*(void) const
Returns the value of the variable.
knowledge::KnowledgeRecord to_record(void) const
Returns the value as a knowledge::KnowledgeRecord.
bool operator==(const Counter &value) const
Checks for equality.
int counters_
the number of counters in the counter ring
void operator=(const Counter &rhs)
Assignment operator.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
int id_
id of this counter in the counter ring
void build_var(void)
Builds the variable that is actually incremented.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the value as an integer (same as *)
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
bool is_false(void) const
Determines if the local count is zero.
ThreadSafeContext * context_
Variable context that we are modifying.
bool operator<=(type value) const
Checks for less than or equal to relationship.
bool operator>(type value) const
Checks for greater than relationship.
Provides functions and classes for the distributed knowledge base.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger