Graphite
Version 3
An experimental 3D geometry processing program
|
Tracks the progress of a task. More...
#include <geogram/basic/progress.h>
Public Member Functions | |
ProgressTask (const std::string &task_name, index_t max_steps, bool quiet) | |
Creates a logger for a task. More... | |
ProgressTask (const std::string &task_name="", index_t max_steps=100) | |
Creates a logger for a task. More... | |
virtual | ~ProgressTask () |
Destroys a ProgressTask. More... | |
virtual void | progress (index_t step) |
Sets the current execution step. More... | |
virtual void | next () |
Goes to the next step. More... | |
bool | is_canceled () const |
Checks if the task is canceled. More... | |
void | reset () |
Resets the execution step. More... | |
void | reset (index_t max_steps) |
Resets the execution step. More... | |
const std::string & | task_name () const |
Gets the name of the task. | |
double | start_time () const |
Gets the start time of the task. | |
index_t | max_steps () const |
Gets the number of steps of the task. | |
index_t | step () const |
Gets the current step of the task. | |
index_t | percent () const |
Gets the percentage of completion of the task. | |
Protected Member Functions | |
virtual void | update () |
Updates progress values. More... | |
Tracks the progress of a task.
The progress of a task can be represented by a number of steps to execute. As the task progresses, the client code informs the ProgressTask of the execution step by calling function next() or progress(), which notify the LoggerClients of the progress. Finally, when the current logger goes out of scope (is destroyed), the logger notifies the LoggerClients that the task is terminated.
When a task is canceled by Progress::cancel() the next call to progress() throws an exception TaskCanceled. It is the responsibility of the client code to catch this exception and do appropriate cleanup. The recommended usage of ProgressTask is illustrated below:
ProgressTask can be sub-classed by client code, typically to route progress display to a progress bar.
Definition at line 240 of file progress.h.
GEO::ProgressTask::ProgressTask | ( | const std::string & | task_name, |
index_t | max_steps, | ||
bool | quiet | ||
) |
Creates a logger for a task.
This creates a ProgressTask object for task task_name
with a number of steps given by max_steps
. The registered LoggerClient is notified to start listening to the progress of the task.
[in] | task_name | the name of the task |
[in] | max_steps | the number of steps of the task |
[in] | quiet | set to true to make the progress silent |
GEO::ProgressTask::ProgressTask | ( | const std::string & | task_name = "" , |
index_t | max_steps = 100 |
||
) |
Creates a logger for a task.
This creates a ProgressTask object for task task_name
with a number of steps given by max_steps
. The registered LoggerClient is notified to start listening to the progress of the task.
[in] | task_name | the name of the task |
[in] | max_steps | the number of steps of the task |
|
virtual |
Destroys a ProgressTask.
This notifies the registered LoggerClients that the task is terminated.
bool GEO::ProgressTask::is_canceled | ( | ) | const |
Checks if the task is canceled.
This function must be called as often as possible during the execution of the current task to stop the current task in case a request was made to cancel it (e.g., from the user interface).
true | if the task was canceled |
false | otherwise |
|
virtual |
Goes to the next step.
This increments the current step value by 1. This updates the percentage of completion of the task and notifies the registered LoggerClients that the execution step has changed.
|
virtual |
Sets the current execution step.
This sets the current step value to step
. The new value must not be greater than the configured number of steps in the ProgressTask constructor. This updates the percentage of completion of the task and notifies the registered LoggerClients that the execution step has changed.
[in] | step | the new step value |
TaskCanceled |
void GEO::ProgressTask::reset | ( | ) |
Resets the execution step.
Resets progress at the beginning. This updates the percentage of completion of the task and notifies the registered LoggerClients that the execution step has changed. This is equivalent to call progress(0)
.
void GEO::ProgressTask::reset | ( | index_t | max_steps | ) |
Resets the execution step.
This changes the maximum number of steps to max_steps
and resets progress at the beginning. This updates the percentage of completion of the task and notifies the registered LoggerClients that the execution step has changed.
[in] | max_steps | the new number of steps of the task. |
|
protectedvirtual |
Updates progress values.
Updates the percentage of completion of the task and notifies the registered LoggerClients that the execution step has changed.