MComputation Class Reference

#include <MComputation.h>

Class Description

Interupt monitor for long computations.

An MComputation allows long computations to check for user interrupts. It is very simple to use. Create a new MComputation object and call the beginComputation method at the beginning of the computation and call the endComputation method when you finish. Then, during the computation, use the isInterruptRequested method to check if the user has requested that the computation terminate.

Example: (of a simple traversal)

MComputation computation;
computation.beginComputation();
for (int i= 1; i<1000; i++) {
Computation(); // Some expensive operation
if (computation.isInterruptRequested()) break ;
}
computation.endComputation();

An alternate form of computation with a progress indicator is supported. In this case, the beginProgressiveComputation method is called along with the progress methods.

Example: (of a simple progressive traversal)

MComputation computation;
computation.beginComputation( true );
computation.setProgressRange( 0, 100 );
for (int i= 1; i<1000; i++) {
Computation(); // Some expensive operation
if (computation.isInterruptRequested()) break ;
computation.setProgress( (int)(i/1000.0 * 100.0) );
}
computation.endComputation();
+ Examples:

Public Member Functions

 MComputation ()
 Constructor for MComputation. More...
 
virtual ~MComputation ()
 Class destructor.
 
void beginComputation (bool showProgressBar=false, bool isInterruptable=true, bool useWaitCursor=true)
 Mark the beginning of a long computation. More...
 
bool isInterruptRequested ()
 Query whether a user-interrupt has occurred. More...
 
void endComputation ()
 Mark the ending of a long computation. More...
 
MStatus setProgressRange (const int minValue, const int maxValue)
 Sets the range (minValue, maxValue) of the progress indicator. More...
 
int progressMin (MStatus *ReturnStatus=NULL) const
 Get the minimum progress value. More...
 
int progressMax (MStatus *ReturnStatus=NULL) const
 Get the maximum progress value. More...
 
MStatus setProgress (const int amount)
 Sets the progress value. More...
 
int progress (MStatus *ReturnStatus=NULL) const
 Get the progress value. More...
 
MStatus setProgressStatus (const MString &)
 Sets the progress status string. More...
 

Static Public Member Functions

static const char * className ()
 Returns the name of this class. More...
 

Constructor & Destructor Documentation

Constructor for MComputation.

Instantiate an MComputation before entering a long computation that should be interruptible.

Member Function Documentation

void beginComputation ( bool  showProgressBar = false,
bool  isInterruptable = true,
bool  useWaitCursor = true 
)

Mark the beginning of a long computation.

The application will begin looking for user interupts.

Parameters
[in]showProgressBarif true a progress bar is displayed
[in]isInterruptableESC can be used in conjunction with the isInterruptRequested() method to stop the computation. In this case setProgressStatus() should not be called.
[in]useWaitCursorif true, cursor goes busy during computation
+ Examples:
bool isInterruptRequested ( )

Query whether a user-interrupt has occurred.

Returns
true if an interrupt has occurred
+ Examples:
void endComputation ( )

Mark the ending of a long computation.

The application will stop looking for user interupts.

+ Examples:
MStatus setProgressRange ( const int  minValue,
const int  maxValue 
)

Sets the range (minValue, maxValue) of the progress indicator.

When the progress value is set to a value of minValue, the progress bar is displayed as empty. When the progress value is set to a value of maxValue, the progress bar is displayed as full. Intermediate progress values are displayed as intermediate positions of the progress bar.

Parameters
[in]minValueMinimum progress value
[in]maxValueMaximum progress value
Returns
Status code
Status Codes:
+ Examples:
int progressMin ( MStatus ReturnStatus = NULL) const

Get the minimum progress value.

Parameters
[out]ReturnStatusStatus code
Returns
Minimum progress value. Returns -1 if query fails.
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An object error has occurred or the computation was not started with a progress bar.
int progressMax ( MStatus ReturnStatus = NULL) const

Get the maximum progress value.

Parameters
[out]ReturnStatusStatus code
Returns
Maximum progress value. Returns -1 if query fails.
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An object error has occurred or the computation was not started with a progress bar.
MStatus setProgress ( const int  amount)

Sets the progress value.

Advancing the progress value updates the progress bar to show the new amount of progress.

Parameters
[in]amountNew progress value
Returns
Status code
Status Codes:
  • MS::kSuccess Progress value set.
  • MS::kFailure Progress has not been started or computation was not started with progress bar.
+ Examples:
int progress ( MStatus ReturnStatus = NULL) const

Get the progress value.

Parameters
[out]ReturnStatusStatus code
Returns
Progress value. Returns -1 if query fails.
Status Codes:
  • MS::kSuccess The method was successful.
  • MS::kFailure An object error has occurred or the computation was not started with a progress bar.
MStatus setProgressStatus ( const MString progressString)

Sets the progress status string.

For example, you could use this to display the percentage of the computation which has been completed.

Parameters
[in]progressStringNew status string
Returns
Status code
Status Codes:
  • MS::kSuccess Progress status set.
  • MS::kFailure Progress has not been started or the computation was not started with a progress bar.
const char * className ( )
static

Returns the name of this class.

Returns
Name of this class.

The documentation for this class was generated from the following files:
  • MComputation.h
  • MComputation.cpp