Represents a node in a hierarchy of progress scopes. More...
#include <cadex/Base_ProgressScope.hxx>
Public Types | |
typedef Base_ProgressStatus::ValueType | ValueType |
Defines a type of the progress status value and ranges. | |
typedef ValueType | value_type |
Defines a type of the progress status value and ranges. | |
Public Member Functions | |
Base_ProgressScope (const Base_ProgressStatus &theStatus, ValueType theScaleInParent=-1) | |
Constructor. | |
Base_ProgressScope (const Base_ProgressScope &theStatus, ValueType theScaleInParent) | |
Constructor. | |
~Base_ProgressScope () | |
Destructor. | |
value_type | Value () const |
Returns a current value. | |
void | SetRange (value_type theMin, value_type theMax) |
Set the scope range. | |
template<typename T1 , typename T2 > | |
void | SetRange (T1 theMin, T2 theMax) |
Set the scope range. | |
template<typename T > | |
void | SetRange (T theMax) |
Set the scope range. | |
value_type | MinValue () const |
Returns a minimum value. | |
value_type | MaxValue () const |
Returns a maximum value. | |
Base_ProgressStatus | Owner () const |
Returns an owning progress status object. | |
Represents a node in a hierarchy of progress scopes.
Scopes can be used to recursively split the range of Base_ProgressStatus object. Scopes can only be created on stack (i.e. they cannot be dynamically allocated on heap). Base_ProgressStatus internally maintains a stack of created scopes. Whenever a scope is destroyed it notifies its parent by incrementing its value, the parent notifies its own parent and so on up to the Base_ProgressStatus object itself.
Each scope has a range which is by default [0, 100]. A child scope is created as a portion of the parent scope (specified in the constructor). This weight information is used to compute increment in the parent range when the child scope's value changes.
The scope can be created either specifying a Base_ProgressStatus object (in this case a parent scope will be automatically found) or with explicitly defined parent. The latter approach is required to support multi-threaded mode.
Example of usage:
As there can be only one current scope in the current thread, then the scope must be destroyed before its sibling can be created. Otherwise the sibling will interpret the previous scope as its parent resulting in wrong updated value. To do so, the explicit C++ scope constructions can be used as demonstrated in the example above.
cadex::Base_ProgressScope::Base_ProgressScope | ( | const Base_ProgressStatus & | theStatus, |
ValueType | theScaleInParent = -1 |
||
) |
Constructor.
Creates a scope as a portion of the latest created scope in theStatus in the current thread.
theScaleInParent specifies a portion of the parent scope's remaining range, which this scope corresponds to. theScaleInParent is specified in parent's range units. If it is negative then the entire parent's range will be used by this child scope.
Before creating a child scope a parent scope must already be set up with SetRange().
To create a child scope for a parent scope created in another thread use another constructor which explcitly accepts a parent scope.
cadex::Base_ProgressScope::Base_ProgressScope | ( | const Base_ProgressScope & | theParent, |
ValueType | theScaleInParent | ||
) |
Constructor.
Creates a scope as a portion of the explicitly specified parent scope.
This constructor must be used in multi-threaded mode if the parent scope has been created in another thread.
theScaleInParent specifies a portion of the parent scope's remaining range, which this scope corresponds to. theScaleInParent is specified in parent's range units. If it is negative then the entire parent's range will be used by this child scope.
Before creating a child scope a parent scope must already be set up with SetRange().
cadex::Base_ProgressScope::~Base_ProgressScope | ( | ) |
Destructor.
During destruction the parent scope will be notified and parent value will be incremented.
Base_ProgressScope::value_type cadex::Base_ProgressScope::MaxValue | ( | ) | const |
Returns a maximum value.
Returns a value set with SetRange() or 100 by default.
Base_ProgressScope::value_type cadex::Base_ProgressScope::MinValue | ( | ) | const |
Returns a minimum value.
Returns a value set with SetRange() or 0 by default.
Base_ProgressStatus cadex::Base_ProgressScope::Owner | ( | ) | const |
Returns an owning progress status object.
Returns the value specified in the constructor (if this object was constructed using Base_ProgressStatus) or Owner() of the scope specified in the constructor (if this object was constructed using Base_ProgressScope).
void cadex::Base_ProgressScope::SetRange | ( | value_type | theMin, |
value_type | theMax | ||
) |
Set the scope range.
The range must be set before creating child scopes. Default range is [0, 100].
Base_ProgressScope::value_type cadex::Base_ProgressScope::Value | ( | ) | const |
Returns a current value.
The value is in the range specified by SetRange() or [0, 100] by default.