RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
Loading...
Searching...
No Matches
rush::RangeCounter< T > Class Template Reference

A counter class that resets after reaching a specified limit. More...

#include <counter.hpp>

Inheritance diagram for rush::RangeCounter< T >:
rush::Counter< unsigned long >

Public Member Functions

 RangeCounter (const T init=0, const T reset=std::numeric_limits< T >::max(), const T step=1)
 Constructor.
 
operator() ()
 Increment the counter by the step value and return the previous value, modulo the reset value.
 
operator++ ()
 Pre-increment the counter by the step value, modulo the reset value.
 
operator++ (int)
 Post-increment the counter by the step value, modulo the reset value.
 
operator+= (const int n)
 Increment the counter by n steps, modulo the reset value.
 
- Public Member Functions inherited from rush::Counter< unsigned long >
 Counter (const unsigned long init=0, const unsigned long step=1)
 Constructor.
 
unsigned long operator() ()
 Increment the counter by the step value and return the previous value.
 
unsigned long operator++ ()
 Pre-increment the counter by the step value.
 
unsigned long operator++ (int)
 Post-increment the counter by the step value.
 
unsigned long operator+= (const int n)
 Increment the counter by n steps.
 
unsigned long operator-- ()
 Pre-decrement the counter by the step value.
 
unsigned long operator-- (int)
 Post-decrement the counter by the step value.
 
unsigned long operator-= (const int n)
 Decrement the counter by n steps.
 
void set (const unsigned long value)
 Set the counter to a specific value.
 
void reset ()
 Reset the counter to its initial value.
 

Detailed Description

template<typename T = unsigned long>
class rush::RangeCounter< T >

A counter class that resets after reaching a specified limit.

Template Parameters
TThe type of the counter, default is unsigned long.

Constructor & Destructor Documentation

◆ RangeCounter()

template<typename T = unsigned long>
rush::RangeCounter< T >::RangeCounter ( const T init = 0,
const T reset = std::numeric_limits<T>::max(),
const T step = 1 )
inlineexplicit

Constructor.

Parameters
initThe initial value of the counter.
resetThe value at which the counter resets to zero.
stepThe step value for each increment.

Member Function Documentation

◆ operator()()

template<typename T = unsigned long>
T rush::RangeCounter< T >::operator() ( )
inline

Increment the counter by the step value and return the previous value, modulo the reset value.

Returns
The value of the counter before incrementing, modulo the reset value.

◆ operator++() [1/2]

template<typename T = unsigned long>
T rush::RangeCounter< T >::operator++ ( )
inline

Pre-increment the counter by the step value, modulo the reset value.

Returns
The new value of the counter after incrementing, modulo the reset value.

◆ operator++() [2/2]

template<typename T = unsigned long>
T rush::RangeCounter< T >::operator++ ( int )
inline

Post-increment the counter by the step value, modulo the reset value.

Returns
The value of the counter before incrementing, modulo the reset value.

◆ operator+=()

template<typename T = unsigned long>
T rush::RangeCounter< T >::operator+= ( const int n)
inline

Increment the counter by n steps, modulo the reset value.

Parameters
nThe number of steps to increment.
Returns
The value of the counter after incrementing, modulo the reset value.

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