Public Member Functions | Protected Attributes

RepeatGuard Class Reference

Guard class against code repetitions. More...

#include <RepeatGuard.h>

Inheritance diagram for RepeatGuard:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 RepeatGuard (ACS::TimeInterval interval, unsigned int maxRepetitions, bool or_or_and=true)
 ~RepeatGuard ()
bool check ()
bool checkAndIncrement ()
void increment ()
unsigned int count ()
void reset ()
void reset (ACS::TimeInterval interval, unsigned int maxRepetitions, bool or_or_and=true)

Protected Attributes

unsigned int counter
unsigned int counterAtLastCheck
unsigned int maxRepetitions
unsigned int method
bool firstTime
ACS::TimeInterval interval
ACS::Time lastTime
ACE_Recursive_Thread_Mutex mutex

Detailed Description

Guard class against code repetitions.

This class intends to be a generic class to avoid repetition of code blocks. It is also intended as a base class for other specific uses, such as RepetGuardLogger.


Constructor & Destructor Documentation

RepeatGuard::RepeatGuard ( ACS::TimeInterval  interval,
unsigned int  maxRepetitions,
bool  or_or_and = true 
)

Constructor

Parameters:
interval minimum interval between allowing an action(i.e. check returns true)(in 100ns)(condition 1)
maxRepetitions maxRepetitions between logs.(condition 2)
OR true: conditions 1 or 2 must be met, false: conditions 1 and 2 must be met. Ignored if interval or maxRepetitions is zero.
RepeatGuard::~RepeatGuard (  ) 

Member Function Documentation

bool RepeatGuard::check (  ) 

This method returns true or false if the next block of code is allowed to be executed or not.

Returns:
true if the conditions to allow an action have been met(conditions depend on the constructor used)

Referenced by Logging::RepeatGuardLogger< ALogger >::log().

bool RepeatGuard::checkAndIncrement (  ) 

This method returns true or false if the next block of code is allowed to be executed or not. Also it increments the counter.

Returns:
true if the conditions to allow an action have been met(conditions depend on the constructor used)

Referenced by Logging::RepeatGuardLogger< ALogger >::logAndIncrement().

unsigned int RepeatGuard::count (  ) 

To see how many attempts have been made.

Returns:
the counter at the moment of the last call to check() or checkAndIncrement()

Referenced by Logging::RepeatGuardLogger< ALogger >::log(), and Logging::RepeatGuardLogger< ALogger >::logAndIncrement().

void RepeatGuard::increment (  ) 

Increments the repetition counter.

void RepeatGuard::reset ( ACS::TimeInterval  interval,
unsigned int  maxRepetitions,
bool  or_or_and = true 
)

Resets counter and time of the last time check() returned true.

Parameters:
interval minimum interval between allowing an action(i.e. check returns true)(in 100ns)(condition 1)
maxRepetitions maxRepetitions between logs.(condition 2)
OR true: conditions 1 or 2 must be met, false: conditions 1 and 2 must be met. Ignored if interval or maxRepetitions is zero.
void RepeatGuard::reset (  ) 

Resets counter and time of the last time check() returned true.


Member Data Documentation

unsigned int RepeatGuard::counter [protected]
unsigned int RepeatGuard::counterAtLastCheck [protected]
bool RepeatGuard::firstTime [protected]
ACS::TimeInterval RepeatGuard::interval [protected]
ACS::Time RepeatGuard::lastTime [protected]
unsigned int RepeatGuard::maxRepetitions [protected]
unsigned int RepeatGuard::method [protected]
ACE_Recursive_Thread_Mutex RepeatGuard::mutex [protected]

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