#include <ProgressCounter.h>

Public Types | |
| enum | ChangedBit { VC_NONE = 0x00, VC_MIN = 0x01, VC_MAX = 0x02, VC_VAL = 0x04, VC_PERCENT = 0x10, VC_RANGE = (VC_MIN|VC_MAX), VC_COUNT = (VC_RANGE|VC_VAL), VC_ALL = (VC_COUNT|VC_PERCENT) } |
| typedef unsigned | Bits |
Public Member Functions | |
| ProgressCounter (Bits initial_r=VC_NONE) | |
| ProgressCounter (const ProgressData &pd_r, Bits initial_r=VC_NONE) | |
| ProgressCounter & | operator= (const ProgressData &pd_r) |
| virtual | ~ProgressCounter () |
| virtual ProgressData & | min (int min_r) |
| virtual ProgressData & | max (int max_r) |
| virtual ProgressData & | range (int min_r, int max_r) |
| virtual ProgressData & | set (int val_r) |
| virtual ProgressData & | init (int min_r, int max_r, int val_r) |
| bool | newMin () const |
| bool | newMax () const |
| bool | newVal () const |
| bool | newRange () const |
| bool | newPercent () const |
| bool | needsUpdate () const |
| double | fPercent (double ifepmty_r=0.0) const |
| int | percent (int ifepmty_r=0) const |
| void | tagDirty (Bits bits_r=VC_ALL) |
| void | setDirty (Bits bits_r=VC_ALL) |
| Bits | update () |
| bool | updateIfNewPercent (unsigned limit_r=0) |
| void | reset () |
Protected Member Functions | |
| virtual Bits | onUpdate () |
Private Member Functions | |
| void | check (int lhs, int rhs, ChangedBit which) |
| bool | checkPercent () const |
Private Attributes | |
| Bits | _changed |
| int | _oldPercent |
Friends | |
| std::ostream & | operator<< (std::ostream &str, const ProgressCounter &obj) |
ProgressCounter overloads all value manipulating methods ot the inherited and remembers changing values in a bitmask.
A call to update discards previously remembered changes. onUpdate is what derived classes may want to overload, to perform whatever action on a call to update and set the bits returned to the caller.
| typedef unsigned ProgressCounter::Bits |
| ProgressCounter::ProgressCounter | ( | Bits | initial_r = VC_NONE |
) | [inline] |
Constructor.
| ProgressCounter::ProgressCounter | ( | const ProgressData & | pd_r, | |
| Bits | initial_r = VC_NONE | |||
| ) | [inline] |
Constructor.
| virtual ProgressCounter::~ProgressCounter | ( | ) | [inline, virtual] |
Destructor.
| void ProgressCounter::check | ( | int | lhs, | |
| int | rhs, | |||
| ChangedBit | which | |||
| ) | [inline, private] |
Test before value assignment. Set ChangedBit if current an new value differ.
| bool ProgressCounter::checkPercent | ( | ) | const [inline, private] |
Test for changed percent value.
| virtual Bits ProgressCounter::onUpdate | ( | ) | [inline, protected, virtual] |
Derived classes may want to overload this to trigger whatever action.
| ProgressCounter& ProgressCounter::operator= | ( | const ProgressData & | pd_r | ) | [inline] |
Assign new ProgressData.
Reimplemented from ProgressData.
| virtual ProgressData& ProgressCounter::min | ( | int | min_r | ) | [inline, virtual] |
Overloaded ProgressData::min to check for changed value.
Reimplemented from ProgressData.
| virtual ProgressData& ProgressCounter::max | ( | int | max_r | ) | [inline, virtual] |
Overloaded ProgressData::max to check for changed value.
Reimplemented from ProgressData.
| virtual ProgressData& ProgressCounter::range | ( | int | min_r, | |
| int | max_r | |||
| ) | [inline, virtual] |
Overloaded ProgressData::range to check for changed value.
Reimplemented from ProgressData.
| virtual ProgressData& ProgressCounter::set | ( | int | val_r | ) | [inline, virtual] |
Overloaded ProgressData::set to check for changed value.
Reimplemented from ProgressData.
| virtual ProgressData& ProgressCounter::init | ( | int | min_r, | |
| int | max_r, | |||
| int | val_r | |||
| ) | [inline, virtual] |
Overloaded ProgressData::init to check for changed value.
Reimplemented from ProgressData.
| bool ProgressCounter::newMin | ( | ) | const [inline] |
Whether min value changed since last update.
| bool ProgressCounter::newMax | ( | ) | const [inline] |
Whether max value changed since last update.
| bool ProgressCounter::newVal | ( | ) | const [inline] |
Whether counter value changed since last update.
| bool ProgressCounter::newRange | ( | ) | const [inline] |
Whether min or max value changed since last update.
| bool ProgressCounter::needsUpdate | ( | ) | const [inline] |
Whether any value changed since last update.
| double ProgressCounter::fPercent | ( | double | ifepmty_r = 0.0 |
) | const [inline] |
Calculate percentage (as double). If (max == min), division by zero is avoided and the provided ifepmty_r (defaults to 0.0) is returned.
| int ProgressCounter::percent | ( | int | ifepmty_r = 0 |
) | const [inline] |
Calculate percentage (as int). If (max == min), division by zero is avoided and the provided ifepmty_r (defaults to 0) ifepmty_r (defaults to 0) is returned.
| void ProgressCounter::tagDirty | ( | Bits | bits_r = VC_ALL |
) | [inline] |
Add bits to remembered changes.
| void ProgressCounter::setDirty | ( | Bits | bits_r = VC_ALL |
) | [inline] |
Set remembered changes to bits.
| Bits ProgressCounter::update | ( | ) | [inline] |
Discard all previously remembered changes. Derived classes want to overload onUpdate. The caller may interpret the bits returned as 'unprocessed changes'.
| bool ProgressCounter::updateIfNewPercent | ( | unsigned | limit_r = 0 |
) | [inline] |
Call update, if newPercent or if all flags are set dirty (e.g. after reset).
If a nonzero limit_r is provided, and old and new percentage differ less than limit_r, a call to update is omitted. Thus updateIfNewPercent( 5 ) will perform at most every 5%.
However, if the old percentage was at min or max, or if the new percentage hits min or max, update is called regardless to the limit_r.
| void ProgressCounter::reset | ( | ) | [inline] |
Reset all values to 0 and tag all values dirty.
| std::ostream& operator<< | ( | std::ostream & | str, | |
| const ProgressCounter & | obj | |||
| ) | [friend] |
Bits ProgressCounter::_changed [mutable, private] |
Changed values in ProgressData since last update. Mutable because some bits like VC_PERCENT may be set when needed, and not on every value change.
int ProgressCounter::_oldPercent [private] |
1.5.3