MADARA  3.4.1
madara::knowledge::containers::Counter Class Reference

This class stores an integer within a variable context. More...

#include <Counter.h>

Inheritance diagram for madara::knowledge::containers::Counter:
madara::knowledge::containers::BaseContainer

Public Types

typedef knowledge::KnowledgeRecord::Integer type
 trait that describes the value type More...
 

Public Member Functions

 Counter (const Counter &rhs)
 Copy constructor. More...
 
 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, KnowledgeBase &knowledge, int id, int counters, type value=0, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Counter (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 Counter (const std::string &name, Variables &knowledge, int id, int counters, type value=0, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 ~Counter ()
 Destructor. More...
 
virtual BaseContainerclone (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...
 
ThreadSafeContextcontext_
 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...
 

Detailed Description

This class stores an integer within a variable context.

Definition at line 33 of file Counter.h.

Member Typedef Documentation

◆ type

trait that describes the value type

Definition at line 37 of file Counter.h.

Constructor & Destructor Documentation

◆ Counter() [1/6]

madara::knowledge::containers::Counter::Counter ( const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings())

Default constructor.

Definition at line 9 of file Counter.cpp.

◆ Counter() [2/6]

madara::knowledge::containers::Counter::Counter ( const std::string &  name,
KnowledgeBase knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)

Constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
settingssettings for evaluating the vector

Definition at line 16 of file Counter.cpp.

◆ Counter() [3/6]

madara::knowledge::containers::Counter::Counter ( const std::string &  name,
Variables knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)

Constructor.

Parameters
namethe name of the map within the variable context
knowledgethe variable context
settingssettings to apply by default

Definition at line 28 of file Counter.cpp.

◆ Counter() [4/6]

madara::knowledge::containers::Counter::Counter ( const std::string &  name,
KnowledgeBase knowledge,
int  id,
int  counters,
type  value = 0,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)

Default constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
idthe id of the counter in the counter ring
countersthe number of counters in the counter ring
valuenew value of the variable in the knowledge base
settingssettings for evaluating the vector

Definition at line 40 of file Counter.cpp.

◆ Counter() [5/6]

madara::knowledge::containers::Counter::Counter ( const std::string &  name,
Variables knowledge,
int  id,
int  counters,
type  value = 0,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings() 
)

Default constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
idthe id of the counter in the counter ring
countersthe number of counters in the counter ring
valuenew value of the variable in the knowledge base
settingssettings for evaluating the vector

Definition at line 54 of file Counter.cpp.

◆ Counter() [6/6]

madara::knowledge::containers::Counter::Counter ( const Counter rhs)

Copy constructor.

Definition at line 68 of file Counter.cpp.

◆ ~Counter()

madara::knowledge::containers::Counter::~Counter ( )

Destructor.

Definition at line 78 of file Counter.cpp.

Member Function Documentation

◆ build_aggregate_count()

void madara::knowledge::containers::Counter::build_aggregate_count ( void  )
private

Builds the aggregate counter logic.

Definition at line 96 of file Counter.cpp.

◆ build_var()

void madara::knowledge::containers::Counter::build_var ( void  )
private

Builds the variable that is actually incremented.

Definition at line 133 of file Counter.cpp.

◆ clone()

madara::knowledge::containers::BaseContainer * madara::knowledge::containers::Counter::clone ( void  ) const
virtual

Clones this container.

Returns
a deep copy of the container that must be managed by the user (i.e., you have to delete the return value)

Implements madara::knowledge::containers::BaseContainer.

Definition at line 208 of file Counter.cpp.

◆ get_count()

type madara::knowledge::containers::Counter::get_count ( void  ) const
inlineprivate

Counts all counter variables.

Returns
total count

Definition at line 358 of file Counter.h.

◆ get_count_double()

double madara::knowledge::containers::Counter::get_count_double ( void  ) const
inlineprivate

Counts all counter variables.

Returns
total count

Definition at line 376 of file Counter.h.

◆ get_count_record()

knowledge::KnowledgeRecord madara::knowledge::containers::Counter::get_count_record ( void  ) const
inlineprivate

Counts all counter variables.

Returns
total count

Definition at line 385 of file Counter.h.

◆ get_count_string()

std::string madara::knowledge::containers::Counter::get_count_string ( void  ) const
inlineprivate

Counts all counter variables.

Returns
total count

Definition at line 367 of file Counter.h.

◆ get_counters()

int madara::knowledge::containers::Counter::get_counters ( void  ) const

Returns the number of counters in the counter ring.

Returns
the number of counters counting

Definition at line 219 of file Counter.cpp.

◆ get_debug_info()

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)

Returns
info in format {container}: {name}{ = value, if appropriate}

Definition at line 178 of file Counter.cpp.

◆ get_debug_info_()

std::string madara::knowledge::containers::Counter::get_debug_info_ ( void  )
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)

Returns
info in format {container}: {name}{ = value, if appropriate}

Implements madara::knowledge::containers::BaseContainer.

Definition at line 202 of file Counter.cpp.

◆ get_id()

int madara::knowledge::containers::Counter::get_id ( void  ) const

Returns the id of the counter in the counter ring.

Returns
the id of the counter

Definition at line 213 of file Counter.cpp.

◆ get_name()

std::string madara::knowledge::containers::BaseContainer::get_name ( void  ) const
inlineinherited

Returns the name of the container.

Returns
name of the container

Definition at line 4 of file BaseContainer.inl.

◆ get_settings()

madara::knowledge::KnowledgeUpdateSettings madara::knowledge::containers::BaseContainer::get_settings ( void  )
inherited

Gets the update settings for the container.

Returns
the current settings

Definition at line 29 of file BaseContainer.cpp.

◆ init_noharm()

void madara::knowledge::containers::Counter::init_noharm ( void  )
private

Initialize the no harm eval settings.

Definition at line 159 of file Counter.cpp.

◆ is_false()

bool madara::knowledge::containers::Counter::is_false ( void  ) const

Determines if the local count is zero.

Returns
true if the local count is zero

Definition at line 524 of file Counter.cpp.

◆ is_false_()

bool madara::knowledge::containers::Counter::is_false_ ( void  ) const
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 534 of file Counter.cpp.

◆ is_true()

bool madara::knowledge::containers::Counter::is_true ( void  ) const

Determines if the local count is not zero.

Returns
true if the local count is not zero

Definition at line 504 of file Counter.cpp.

◆ is_true_()

bool madara::knowledge::containers::Counter::is_true_ ( void  ) const
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 529 of file Counter.cpp.

◆ modify()

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 169 of file Counter.cpp.

◆ modify_()

void madara::knowledge::containers::Counter::modify_ ( void  )
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 197 of file Counter.cpp.

◆ modify_if_false()

bool madara::knowledge::containers::BaseContainer::modify_if_false ( BaseContainer conditional)
virtualinherited

Modifies the container if the argument is false.

Parameters
conditionalthe container that must be false to modify
Returns
true if the container was modified

Definition at line 56 of file BaseContainer.cpp.

◆ modify_if_true()

bool madara::knowledge::containers::BaseContainer::modify_if_true ( BaseContainer conditional)
virtualinherited

Modifies the container if the argument is true.

Parameters
conditionalthe container that must be true to modify
Returns
true if the container was modified

Definition at line 36 of file BaseContainer.cpp.

◆ operator!=() [1/2]

bool madara::knowledge::containers::Counter::operator!= ( const Counter value) const

Checks for inequality.

Parameters
valuethe value to compare to
Returns
true if inequal, false otherwise

Definition at line 320 of file Counter.cpp.

◆ operator!=() [2/2]

bool madara::knowledge::containers::Counter::operator!= ( type  value) const

Checks for inequality.

Parameters
valuethe value to compare to
Returns
true if inequal, false otherwise

Definition at line 295 of file Counter.cpp.

◆ operator*()

madara::knowledge::containers::Counter::type madara::knowledge::containers::Counter::operator* ( void  ) const

Returns the value of the variable.

Returns
the value of the variable

Definition at line 382 of file Counter.cpp.

◆ operator++()

void madara::knowledge::containers::Counter::operator++ ( void  )

Increments the value of the variable and returns the result.

Returns
the new value of the variable

Definition at line 445 of file Counter.cpp.

◆ operator+=()

void madara::knowledge::containers::Counter::operator+= ( type  value)

Increments by a value.

Parameters
valuethe value to add
Returns
the new value

Definition at line 417 of file Counter.cpp.

◆ operator--()

void madara::knowledge::containers::Counter::operator-- ( void  )

Decrements the value of the variable and returns the result.

Returns
the new value of the variable

Definition at line 455 of file Counter.cpp.

◆ operator-=()

void madara::knowledge::containers::Counter::operator-= ( type  value)

Decrements by a value.

Parameters
valuethe value to remove
Returns
the new value

Definition at line 431 of file Counter.cpp.

◆ operator<()

bool madara::knowledge::containers::Counter::operator< ( type  value) const

Checks for less than relationship.

Parameters
valuethe value to compare to
Returns
true if less than

Definition at line 333 of file Counter.cpp.

◆ operator<=()

bool madara::knowledge::containers::Counter::operator<= ( type  value) const

Checks for less than or equal to relationship.

Parameters
valuethe value to compare to
Returns
true if less than or equal to

Definition at line 345 of file Counter.cpp.

◆ operator=() [1/2]

void madara::knowledge::containers::Counter::operator= ( const Counter rhs)

Assignment operator.

Parameters
rhsvalue to copy

Definition at line 80 of file Counter.cpp.

◆ operator=() [2/2]

madara::knowledge::containers::Counter::type madara::knowledge::containers::Counter::operator= ( type  value)

Sets the value of the variable.

Parameters
valuethe new value of the variable
Returns
the updated value (should be same as value param)

Definition at line 271 of file Counter.cpp.

◆ operator==() [1/2]

bool madara::knowledge::containers::Counter::operator== ( const Counter value) const

Checks for equality.

Parameters
valuethe value to compare to
Returns
true if equal, false otherwise

Definition at line 307 of file Counter.cpp.

◆ operator==() [2/2]

bool madara::knowledge::containers::Counter::operator== ( type  value) const

Checks for equality.

Parameters
valuethe value to compare to
Returns
true if equal, false otherwise

Definition at line 283 of file Counter.cpp.

◆ operator>()

bool madara::knowledge::containers::Counter::operator> ( type  value) const

Checks for greater than relationship.

Parameters
valuethe value to compare to
Returns
true if greater than

Definition at line 357 of file Counter.cpp.

◆ operator>=()

bool madara::knowledge::containers::Counter::operator>= ( type  value) const

Checks for greater than or equal to relationship.

Parameters
valuethe value to compare to
Returns
true if greater than or equal to

Definition at line 369 of file Counter.cpp.

◆ resize()

void madara::knowledge::containers::Counter::resize ( int  id = 0,
int  counters = 1 
)

Resizes the counter, usually when number of counters change.

Parameters
idthe id of this counter in the counter ring
countersthe number of counters in counter ring

Definition at line 255 of file Counter.cpp.

◆ set_name() [1/2]

void madara::knowledge::containers::Counter::set_name ( const std::string &  var_name,
KnowledgeBase knowledge 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in

Definition at line 225 of file Counter.cpp.

◆ set_name() [2/2]

void madara::knowledge::containers::Counter::set_name ( const std::string &  var_name,
Variables knowledge 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in

Definition at line 240 of file Counter.cpp.

◆ set_quality()

void madara::knowledge::containers::Counter::set_quality ( uint32_t  quality,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)

Sets the quality of writing to the counter variables.

Parameters
qualityquality of writing to this location
settingssettings for referring to knowledge variables

Definition at line 493 of file Counter.cpp.

◆ set_settings()

void madara::knowledge::containers::BaseContainer::set_settings ( const KnowledgeUpdateSettings settings)
inherited

Sets the update settings for the container.

Parameters
settingsthe new settings to use

Definition at line 20 of file BaseContainer.cpp.

◆ to_double()

double madara::knowledge::containers::Counter::to_double ( void  ) const

Returns the value as a double.

Returns
the value as a double

Definition at line 465 of file Counter.cpp.

◆ to_integer()

madara::knowledge::KnowledgeRecord::Integer madara::knowledge::containers::Counter::to_integer ( void  ) const

Returns the value as an integer (same as *)

Returns
the value as an integer

Definition at line 403 of file Counter.cpp.

◆ to_record()

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.

Returns
the value as a knowledge::KnowledgeRecord

Definition at line 388 of file Counter.cpp.

◆ to_string()

std::string madara::knowledge::containers::Counter::to_string ( void  ) const

Returns the value as a string.

Returns
the value as a string

Definition at line 479 of file Counter.cpp.

Member Data Documentation

◆ aggregate_count_

CompiledExpression madara::knowledge::containers::Counter::aggregate_count_
private

Expression for aggregating count in one atomic operation.

Definition at line 413 of file Counter.h.

◆ context_

ThreadSafeContext* madara::knowledge::containers::Counter::context_
mutableprivate

Variable context that we are modifying.

Definition at line 393 of file Counter.h.

◆ counters_

int madara::knowledge::containers::Counter::counters_
private

the number of counters in the counter ring

Definition at line 408 of file Counter.h.

◆ id_

int madara::knowledge::containers::Counter::id_
private

id of this counter in the counter ring

Definition at line 403 of file Counter.h.

◆ mutex_

MADARA_LOCK_TYPE madara::knowledge::containers::BaseContainer::mutex_
mutableprotectedinherited

guard for access and changes

Mutex for local changes

Definition at line 136 of file BaseContainer.h.

◆ name_

std::string madara::knowledge::containers::BaseContainer::name_
protectedinherited

Prefix of variable.

Definition at line 146 of file BaseContainer.h.

◆ no_harm

EvalSettings madara::knowledge::containers::Counter::no_harm
private

Settings we'll use for all evaluations.

Definition at line 418 of file Counter.h.

◆ settings_

KnowledgeUpdateSettings madara::knowledge::containers::BaseContainer::settings_
protectedinherited

Settings for modifications.

Definition at line 151 of file BaseContainer.h.

◆ variable_

VariableReference madara::knowledge::containers::Counter::variable_
private

Variable reference.

Definition at line 398 of file Counter.h.


The documentation for this class was generated from the following files: