CAD Exchanger SDK
cadex::Base_ProgressScope Class Reference

Represents a node in a hierarchy of progress scopes. More...

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. More...
 
 Base_ProgressScope (const Base_ProgressScope &theStatus, ValueType theScaleInParent)
 Constructor. More...
 
 ~Base_ProgressScope ()
 Destructor. More...
 
value_type Value () const
 Returns a current value. More...
 
void SetRange (value_type theMin, value_type theMax)
 Set the scope range. More...
 
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. More...
 
value_type MaxValue () const
 Returns a maximum value. More...
 
Base_ProgressStatus Owner () const
 Returns an owning progress status object. More...
 

Detailed Description

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:

ACIS_Reader aReader;
Base_ProgressStatus& aStatus = aReader.ProgressStatus();
Base_ProgressScope aTopScope (aStatus); //take entire remaining range (in this case 100%)
{
Base_ProgressScope aScope (aStatus, 25); //25% of TopRange
anIsOK = aReader.ReadFile (theFileName.c_str());
}
if (anIsOK) {
Base_ProgressScope aScope (aStatus); //remaining 75% of TopRange
anIsOK = aReader.Transfer (aShapeModel);
}

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.

Examples:
misc/progressindicator/main.cxx, and misc/progressindicatorgui/main.cxx.

Constructor & Destructor Documentation

◆ Base_ProgressScope() [1/2]

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.

◆ Base_ProgressScope() [2/2]

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().

◆ ~Base_ProgressScope()

cadex::Base_ProgressScope::~Base_ProgressScope ( )

Destructor.

During destruction the parent scope will be notified and parent value will be incremented.

Member Function Documentation

◆ MaxValue()

Base_ProgressScope::value_type cadex::Base_ProgressScope::MaxValue ( ) const

Returns a maximum value.

Returns a value set with SetRange() or 100 by default.

◆ MinValue()

Base_ProgressScope::value_type cadex::Base_ProgressScope::MinValue ( ) const

Returns a minimum value.

Returns a value set with SetRange() or 0 by default.

◆ Owner()

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).

◆ SetRange()

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].

◆ Value()

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.