2 #ifndef _MADARA_NO_KARL_ 11 :
BaseContainer (
"", settings), context_ (0), id_ (0), counters_ (1)
112 MADARA_GUARD_TYPE guard (
mutex_);
114 std::stringstream buffer;
133 else if (
name_ ==
"")
135 context_->
print (
"ERROR: Container::Counter needs a name.\n", 0);
139 context_->
print (
"ERROR: Container::Counter needs a context.\n", 0);
149 MADARA_GUARD_TYPE guard (
mutex_);
151 std::stringstream buffer;
159 else if (
name_ ==
"")
161 context_->
print (
"ERROR: Container::Counter needs a name.\n", 0);
165 context_->
print (
"ERROR: Container::Counter needs a context.\n", 0);
193 std::stringstream result;
195 result <<
"Counter: ";
200 MADARA_GUARD_TYPE guard (
mutex_);
202 result << this->
name_;
204 result <<
" (total: " <<
get_count () <<
")";
207 return result.str ();
231 MADARA_GUARD_TYPE guard (
mutex_);
238 MADARA_GUARD_TYPE guard (
mutex_);
251 MADARA_GUARD_TYPE guard (
mutex_);
268 MADARA_GUARD_TYPE guard (
mutex_);
282 MADARA_GUARD_TYPE guard (
mutex_);
298 MADARA_GUARD_TYPE guard (
mutex_);
311 MADARA_GUARD_TYPE guard (
mutex_);
324 MADARA_GUARD_TYPE guard (
mutex_);
338 MADARA_GUARD_TYPE guard (
mutex_);
352 MADARA_GUARD_TYPE guard (
mutex_);
365 MADARA_GUARD_TYPE guard (
mutex_);
378 MADARA_GUARD_TYPE guard (
mutex_);
391 MADARA_GUARD_TYPE guard (
mutex_);
404 MADARA_GUARD_TYPE guard (
mutex_);
425 MADARA_GUARD_TYPE guard (
mutex_);
440 MADARA_GUARD_TYPE guard (
mutex_);
455 MADARA_GUARD_TYPE guard (
mutex_);
470 MADARA_GUARD_TYPE guard (
mutex_);
484 MADARA_GUARD_TYPE guard (
mutex_);
495 MADARA_GUARD_TYPE guard (
mutex_);
508 MADARA_GUARD_TYPE guard (
mutex_);
523 MADARA_GUARD_TYPE guard (
mutex_);
538 MADARA_GUARD_TYPE guard (
mutex_);
550 "Counter::is_true: checking local counter for non-zero\n");
555 MADARA_GUARD_TYPE guard (
mutex_);
560 "Counter::is_true: final result is %d\n", (int)result);
585 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
bool expand_variables
Toggle for always attempting to expand variables (true) or never expanding variables (false) ...
madara::knowledge::KnowledgeRecord dec(const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically decrements the value of the variable.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
bool is_true(void) const
Checks to see if the record is true.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the value as an integer (same as *)
void operator=(const Counter &rhs)
Assignment operator.
void build_var(void)
Builds the variable that is actually incremented.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
int counters_
the number of counters in the counter ring
ThreadSafeContext * context_
Variable context that we are modifying.
bool operator<=(type value) const
Checks for less than or equal to relationship.
int get_id(void) const
Returns the id of the counter in the counter ring.
std::string name_
Prefix of variable.
int id_
id of this counter in the counter ring
bool signal_changes
Toggle whether to signal changes have happened.
void print(unsigned int level) const
Atomically prints all variables and values in the context.
void resize(int id=0, int counters=1)
Resizes the counter, usually when number of counters change.
VariableReference variable_
Variable reference.
int get_counters(void) const
Returns the number of counters in the counter ring.
MADARA_LOCK_TYPE mutex_
guard for access and changes
CompiledExpression aggregate_count_
Expression for aggregating count in one atomic operation.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
void operator-=(type value)
Decrements by a value.
bool operator==(const Counter &value) const
Checks for equality.
double to_double(void) const
Returns the value as a double.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
bool operator>(type value) const
Checks for greater than relationship.
A thread-safe guard for a context or knowledge base.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true...
void operator++(void)
Increments the value of the variable and returns the result.
Counter(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
void operator+=(type value)
Increments by a value.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
This class provides a distributed knowledge base to users.
knowledge::KnowledgeRecord get_count_record(void) const
Counts all counter variables.
bool operator<(type value) const
Checks for less than relationship.
void modify(void)
Mark the value as modified.
madara::knowledge::KnowledgeRecord inc(const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically increments the value of the variable.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
bool is_true(void) const
Determines if the local count is not zero.
bool operator!=(const Counter &value) const
Checks for inequality.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
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 ...
Integer to_integer(void) const
converts the value to an integer
bool always_overwrite
Toggle for always overwriting records, regardless of quality, clock values, etc.
void build_aggregate_count(void)
Builds the aggregate counter logic.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
Provides functions and classes for the distributed knowledge base.
KnowledgeUpdateSettings settings_
Settings for modifications.
void operator--(void)
Decrements the value of the variable and returns the result.
virtual BaseContainer * clone(void) const
Clones this container.
knowledge::KnowledgeRecord to_record(void) const
Returns the value as a knowledge::KnowledgeRecord.
bool is_false(void) const
Determines if the local count is zero.
void init_noharm(void)
Initialize the no harm eval settings.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
bool treat_globals_as_locals
Toggle whether updates to global variables are treated as local variables and not marked as modified ...
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
bool delay_sending_modifieds
Toggle for sending modifieds in a single update event after each evaluation.
This class stores an integer within a variable context.
bool track_local_changes
Toggle for checkpointing support.
std::string get_count_string(void) const
Counts all counter variables.
type operator*(void) const
Returns the value of the variable.
Settings for applying knowledge updates.
EvalSettings no_harm
Settings we'll use for all evaluations.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
double get_count_double(void) const
Counts all counter variables.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the counter variables.
type get_count(void) const
Counts all counter variables.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.
bool operator>=(type value) const
Checks for greater than or equal to relationship.
std::string to_string(void) const
Returns the value as a string.