ProgressCounter Class Reference

Maintain ProgressData received e.g. via callback. More...

#include <ProgressCounter.h>

Inheritance diagram for ProgressCounter:

ProgressData

List of all members.

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)
ProgressCounteroperator= (const ProgressData &pd_r)
virtual ~ProgressCounter ()
virtual ProgressDatamin (int min_r)
virtual ProgressDatamax (int max_r)
virtual ProgressDatarange (int min_r, int max_r)
virtual ProgressDataset (int val_r)
virtual ProgressDatainit (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)


Detailed Description

Maintain ProgressData received e.g. via callback.

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.


Member Typedef Documentation

typedef unsigned ProgressCounter::Bits


Member Enumeration Documentation

enum ProgressCounter::ChangedBit

Bits and bitmasks

Enumerator:
VC_NONE 
VC_MIN 
VC_MAX 
VC_VAL 
VC_PERCENT 
VC_RANGE 
VC_COUNT 
VC_ALL 


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

Returns:
Whether VC_PERCENT bit is now set.

virtual Bits ProgressCounter::onUpdate (  )  [inline, protected, virtual]

Derived classes may want to overload this to trigger whatever action.

Returns:
Bits to be returned from update.

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::newPercent (  )  const [inline]

Whether percent 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'.

Returns:
The changes discarded.

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.

Returns:
Whether update was called.

void ProgressCounter::reset (  )  [inline]

Reset all values to 0 and tag all values dirty.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  str,
const ProgressCounter obj 
) [friend]


Member Data Documentation

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]

Remember percent on call to update.


The documentation for this class was generated from the following file:
Generated on Fri Sep 21 22:35:03 2007 for liby2util by  doxygen 1.5.3