MADARA
3.1.8
|
This class stores an integer within a variable context. More...
#include <Counter.h>
Public Types | |
typedef knowledge::KnowledgeRecord::Integer | type |
trait that describes the value type More... | |
Public Member Functions | |
Counter (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) | |
Default constructor. More... | |
Counter (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) | |
Constructor. More... | |
Counter (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) | |
Constructor. More... | |
Counter (const std::string &name, KnowledgeBase &knowledge, int id, int counters, type value=0, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) | |
Default constructor. More... | |
Counter (const std::string &name, Variables &knowledge, int id, int counters, type value=0, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) | |
Default constructor. More... | |
Counter (const Counter &rhs) | |
Copy constructor. More... | |
~Counter () | |
Destructor. More... | |
virtual BaseContainer * | clone (void) const |
Clones this container. More... | |
int | get_counters (void) const |
Returns the number of counters in the counter ring. More... | |
std::string | get_debug_info (void) |
Returns the type of the container along with name and any other useful information. More... | |
int | get_id (void) const |
Returns the id of the counter in the counter ring. More... | |
std::string | get_name (void) const |
Returns the name of the container. More... | |
KnowledgeUpdateSettings | get_settings (void) |
Gets the update settings for the container. More... | |
bool | is_false (void) const |
Determines if the local count is zero. More... | |
bool | is_true (void) const |
Determines if the local count is not zero. More... | |
void | modify (void) |
Mark the value as modified. More... | |
virtual bool | modify_if_false (BaseContainer &conditional) |
Modifies the container if the argument is false. More... | |
virtual bool | modify_if_true (BaseContainer &conditional) |
Modifies the container if the argument is true. More... | |
bool | operator!= (const Counter &value) const |
Checks for inequality. More... | |
bool | operator!= (type value) const |
Checks for inequality. More... | |
type | operator* (void) const |
Returns the value of the variable. More... | |
void | operator++ (void) |
Increments the value of the variable and returns the result. More... | |
void | operator+= (type value) |
Increments by a value. More... | |
void | operator-- (void) |
Decrements the value of the variable and returns the result. More... | |
void | operator-= (type value) |
Decrements by a value. More... | |
bool | operator< (type value) const |
Checks for less than relationship. More... | |
bool | operator<= (type value) const |
Checks for less than or equal to relationship. More... | |
void | operator= (const Counter &rhs) |
Assignment operator. More... | |
type | operator= (type value) |
Sets the value of the variable. More... | |
bool | operator== (const Counter &value) const |
Checks for equality. More... | |
bool | operator== (type value) const |
Checks for equality. More... | |
bool | operator> (type value) const |
Checks for greater than relationship. More... | |
bool | operator>= (type value) const |
Checks for greater than or equal to relationship. More... | |
void | resize (int id=0, int counters=1) |
Resizes the counter, usually when number of counters change. More... | |
void | set_name (const std::string &var_name, KnowledgeBase &knowledge) |
Sets the variable name that this refers to. More... | |
void | set_name (const std::string &var_name, Variables &knowledge) |
Sets the variable name that this refers to. More... | |
void | set_quality (uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false)) |
Sets the quality of writing to the counter variables. More... | |
void | set_settings (const KnowledgeUpdateSettings &settings) |
Sets the update settings for the container. More... | |
double | to_double (void) const |
Returns the value as a double. More... | |
knowledge::KnowledgeRecord::Integer | to_integer (void) const |
Returns the value as an integer (same as *) More... | |
knowledge::KnowledgeRecord | to_record (void) const |
Returns the value as a knowledge::KnowledgeRecord. More... | |
std::string | to_string (void) const |
Returns the value as a string. More... | |
Protected Attributes | |
MADARA_LOCK_TYPE | mutex_ |
guard for access and changes More... | |
std::string | name_ |
Prefix of variable. More... | |
KnowledgeUpdateSettings | settings_ |
Settings for modifications. More... | |
Private Member Functions | |
void | build_aggregate_count (void) |
Builds the aggregate counter logic. More... | |
void | build_var (void) |
Builds the variable that is actually incremented. More... | |
type | get_count (void) const |
Counts all counter variables. More... | |
double | get_count_double (void) const |
Counts all counter variables. More... | |
knowledge::KnowledgeRecord | get_count_record (void) const |
Counts all counter variables. More... | |
std::string | get_count_string (void) const |
Counts all counter variables. More... | |
virtual std::string | get_debug_info_ (void) |
Returns the type of the container along with name and any other useful information. More... | |
void | init_noharm (void) |
Initialize the no harm eval settings. More... | |
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 false. More... | |
virtual bool | is_true_ (void) const |
Polymorphic is true method which can be used to determine if all values in the container are true. More... | |
virtual void | modify_ (void) |
Polymorphic modify method used by collection containers. More... | |
Private Attributes | |
CompiledExpression | aggregate_count_ |
Expression for aggregating count in one atomic operation. More... | |
ThreadSafeContext * | context_ |
Variable context that we are modifying. More... | |
int | counters_ |
the number of counters in the counter ring More... | |
int | id_ |
id of this counter in the counter ring More... | |
EvalSettings | no_harm |
Settings we'll use for all evaluations. More... | |
VariableReference | variable_ |
Variable reference. More... | |
madara::knowledge::containers::Counter::Counter | ( | const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () | ) |
Default constructor.
Definition at line 9 of file Counter.cpp.
madara::knowledge::containers::Counter::Counter | ( | const std::string & | name, |
KnowledgeBase & | knowledge, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () |
||
) |
Constructor.
name | name of the integer in the knowledge base |
knowledge | the knowledge base that will contain the vector |
settings | settings for evaluating the vector |
Definition at line 16 of file Counter.cpp.
madara::knowledge::containers::Counter::Counter | ( | const std::string & | name, |
Variables & | knowledge, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () |
||
) |
Constructor.
name | the name of the map within the variable context |
knowledge | the variable context |
settings | settings to apply by default |
Definition at line 28 of file Counter.cpp.
madara::knowledge::containers::Counter::Counter | ( | const std::string & | name, |
KnowledgeBase & | knowledge, | ||
int | id, | ||
int | counters, | ||
type | value = 0 , |
||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () |
||
) |
Default constructor.
name | name of the integer in the knowledge base |
knowledge | the knowledge base that will contain the vector |
id | the id of the counter in the counter ring |
counters | the number of counters in the counter ring |
value | new value of the variable in the knowledge base |
settings | settings for evaluating the vector |
Definition at line 40 of file Counter.cpp.
madara::knowledge::containers::Counter::Counter | ( | const std::string & | name, |
Variables & | knowledge, | ||
int | id, | ||
int | counters, | ||
type | value = 0 , |
||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () |
||
) |
Default constructor.
name | name of the integer in the knowledge base |
knowledge | the knowledge base that will contain the vector |
id | the id of the counter in the counter ring |
counters | the number of counters in the counter ring |
value | new value of the variable in the knowledge base |
settings | settings for evaluating the vector |
Definition at line 56 of file Counter.cpp.
madara::knowledge::containers::Counter::Counter | ( | const Counter & | rhs | ) |
Copy constructor.
Definition at line 73 of file Counter.cpp.
madara::knowledge::containers::Counter::~Counter | ( | ) |
Destructor.
Definition at line 84 of file Counter.cpp.
|
private |
Builds the aggregate counter logic.
Definition at line 107 of file Counter.cpp.
|
private |
Builds the variable that is actually incremented.
Definition at line 144 of file Counter.cpp.
|
virtual |
Clones this container.
Implements madara::knowledge::containers::BaseContainer.
Definition at line 223 of file Counter.cpp.
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
int madara::knowledge::containers::Counter::get_counters | ( | void | ) | const |
Returns the number of counters in the counter ring.
Definition at line 236 of file Counter.cpp.
std::string madara::knowledge::containers::Counter::get_debug_info | ( | void | ) |
Returns the type of the container along with name and any other useful information.
The provided information should be useful for developers wishing to debug container operations, especially as it pertains to pending network operations (i.e., when used in conjunction with modify)
Definition at line 191 of file Counter.cpp.
|
privatevirtual |
Returns the type of the container along with name and any other useful information.
The provided information should be useful for developers wishing to debug container operations, especially as it pertains to pending network operations (i.e., when used in conjunction with modify)
Implements madara::knowledge::containers::BaseContainer.
Definition at line 217 of file Counter.cpp.
int madara::knowledge::containers::Counter::get_id | ( | void | ) | const |
Returns the id of the counter in the counter ring.
Definition at line 229 of file Counter.cpp.
|
inlineinherited |
Returns the name of the container.
Definition at line 5 of file BaseContainer.inl.
|
inherited |
Gets the update settings for the container.
Definition at line 37 of file BaseContainer.cpp.
|
private |
Initialize the no harm eval settings.
Definition at line 170 of file Counter.cpp.
bool madara::knowledge::containers::Counter::is_false | ( | void | ) | const |
Determines if the local count is zero.
Definition at line 566 of file Counter.cpp.
|
privatevirtual |
Polymorphic is false method which can be used to determine if at least one value in the container is false.
Implements madara::knowledge::containers::BaseContainer.
Definition at line 579 of file Counter.cpp.
bool madara::knowledge::containers::Counter::is_true | ( | void | ) | const |
Determines if the local count is not zero.
Definition at line 545 of file Counter.cpp.
|
privatevirtual |
Polymorphic is true method which can be used to determine if all values in the container are true.
Implements madara::knowledge::containers::BaseContainer.
Definition at line 573 of file Counter.cpp.
void madara::knowledge::containers::Counter::modify | ( | void | ) |
Mark the value as modified.
The Counter retains the same value but will resend its value as if it had been modified.
Definition at line 181 of file Counter.cpp.
|
privatevirtual |
Polymorphic modify method used by collection containers.
This method calls the modify method for this class. We separate the faster version (modify) from this version (modify_) to allow users the opportunity to have a fastery version that does not use polymorphic functions (generally virtual functions are half as efficient as normal function calls)
Implements madara::knowledge::containers::BaseContainer.
Definition at line 211 of file Counter.cpp.
|
virtualinherited |
Modifies the container if the argument is false.
conditional | the container that must be false to modify |
Definition at line 64 of file BaseContainer.cpp.
|
virtualinherited |
Modifies the container if the argument is true.
conditional | the container that must be true to modify |
Definition at line 44 of file BaseContainer.cpp.
bool madara::knowledge::containers::Counter::operator!= | ( | const Counter & | value | ) | const |
Checks for inequality.
value | the value to compare to |
Definition at line 346 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator!= | ( | type | value | ) | const |
Checks for inequality.
value | the value to compare to |
Definition at line 319 of file Counter.cpp.
madara::knowledge::containers::Counter::type madara::knowledge::containers::Counter::operator* | ( | void | ) | const |
Returns the value of the variable.
Definition at line 412 of file Counter.cpp.
void madara::knowledge::containers::Counter::operator++ | ( | void | ) |
Increments the value of the variable and returns the result.
Definition at line 479 of file Counter.cpp.
void madara::knowledge::containers::Counter::operator+= | ( | type | value | ) |
Increments by a value.
value | the value to add |
Definition at line 448 of file Counter.cpp.
void madara::knowledge::containers::Counter::operator-- | ( | void | ) |
Decrements the value of the variable and returns the result.
Definition at line 490 of file Counter.cpp.
void madara::knowledge::containers::Counter::operator-= | ( | type | value | ) |
Decrements by a value.
value | the value to remove |
Definition at line 464 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator< | ( | type | value | ) | const |
Checks for less than relationship.
value | the value to compare to |
Definition at line 360 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator<= | ( | type | value | ) | const |
Checks for less than or equal to relationship.
value | the value to compare to |
Definition at line 373 of file Counter.cpp.
void madara::knowledge::containers::Counter::operator= | ( | const Counter & | rhs | ) |
madara::knowledge::containers::Counter::type madara::knowledge::containers::Counter::operator= | ( | type | value | ) |
Sets the value of the variable.
value | the new value of the variable |
Definition at line 293 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator== | ( | const Counter & | value | ) | const |
Checks for equality.
value | the value to compare to |
Definition at line 332 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator== | ( | type | value | ) | const |
Checks for equality.
value | the value to compare to |
Definition at line 306 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator> | ( | type | value | ) | const |
Checks for greater than relationship.
value | the value to compare to |
Definition at line 386 of file Counter.cpp.
bool madara::knowledge::containers::Counter::operator>= | ( | type | value | ) | const |
Checks for greater than or equal to relationship.
value | the value to compare to |
Definition at line 399 of file Counter.cpp.
void madara::knowledge::containers::Counter::resize | ( | int | id = 0 , |
int | counters = 1 |
||
) |
Resizes the counter, usually when number of counters change.
id | the id of this counter in the counter ring |
counters | the number of counters in counter ring |
Definition at line 277 of file Counter.cpp.
void madara::knowledge::containers::Counter::set_name | ( | const std::string & | var_name, |
KnowledgeBase & | knowledge | ||
) |
Sets the variable name that this refers to.
var_name | the name of the variable in the knowledge base |
knowledge | the knowledge base the variable is housed in |
Definition at line 243 of file Counter.cpp.
void madara::knowledge::containers::Counter::set_name | ( | const std::string & | var_name, |
Variables & | knowledge | ||
) |
Sets the variable name that this refers to.
var_name | the name of the variable in the knowledge base |
knowledge | the knowledge base the variable is housed in |
Definition at line 260 of file Counter.cpp.
void madara::knowledge::containers::Counter::set_quality | ( | uint32_t | quality, |
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings (false) |
||
) |
Sets the quality of writing to the counter variables.
quality | quality of writing to this location |
settings | settings for referring to knowledge variables |
Definition at line 531 of file Counter.cpp.
|
inherited |
Sets the update settings for the container.
settings | the new settings to use |
Definition at line 28 of file BaseContainer.cpp.
double madara::knowledge::containers::Counter::to_double | ( | void | ) | const |
Returns the value as a double.
Definition at line 501 of file Counter.cpp.
madara::knowledge::KnowledgeRecord::Integer madara::knowledge::containers::Counter::to_integer | ( | void | ) | const |
Returns the value as an integer (same as *)
Definition at line 433 of file Counter.cpp.
madara::knowledge::KnowledgeRecord madara::knowledge::containers::Counter::to_record | ( | void | ) | const |
Returns the value as a knowledge::KnowledgeRecord.
This is useful for referencing clock and other record info.
Definition at line 418 of file Counter.cpp.
std::string madara::knowledge::containers::Counter::to_string | ( | void | ) | const |
Returns the value as a string.
Definition at line 516 of file Counter.cpp.
|
private |
|
mutableprivate |
|
private |
|
private |
|
mutableprotectedinherited |
guard for access and changes
Mutex for local changes
Definition at line 141 of file BaseContainer.h.
|
protectedinherited |
Prefix of variable.
Definition at line 151 of file BaseContainer.h.
|
private |
|
protectedinherited |
Settings for modifications.
Definition at line 156 of file BaseContainer.h.
|
private |