Represents a node in a tree used to track the progress of a task.
More...
#include <progressnode.h>
|
| ProgressNode (int id, const std::vector< float > &weights, std::optional< ProgressNode * > parent) |
| Constructor.
|
|
| ProgressNode (std::function< void(float)> progress_callback, const std::vector< float > &weights={}) |
| Constructor for a root node.
|
|
void | advance (uint64_t num_steps=1) |
| Advances the current progress of this node by the given amount of steps. This must be a leaf node.
|
|
int | totalSteps () const |
| Returns the total number of steps in this task.
|
|
void | setTotalSteps (uint64_t total_steps) |
| Sets the total number of steps in this task.
|
|
int | id () const |
| Returns the id of this node.
|
|
void | addChildren (const std::vector< float > &weights) |
| Adds new child nodes with given weights to this node.
|
|
ProgressNode & | child (int id) |
| Returns a reference to the child with the given id.
|
|
void | setProgressCallback (std::function< void(float)> progress_callback) |
| Sets a callback function used by the root node to inform about changes in the task progress.
|
|
float | updateStepSize () const |
| Returns the minimal progress interval after which the progress callback is called.
|
|
void | setUpdateStepSize (float step_size) |
| Sets the minimal progress interval after which the progress callback is called.
|
|
float | getProgress () const |
| Returns the current progress.
|
|
|
void | updateProgress () |
| Sets the current progress of this node to the weighted sum of the current progresses of its children.
|
|
void | propagateProgress () |
| Informs this nodes parent of a change in progress.
|
|
|
int | id_ |
| This nodes id.
|
|
uint64_t | cur_step_ = 0 |
| Current step in this task. Only used for leaf nodes.
|
|
uint64_t | total_steps_ |
| Number of total steps in this task. Only used for leaf nodes.
|
|
float | progress_ = 0.0f |
| Current progress in this task.
|
|
float | prev_progress_ = 0.0f |
| Progress at the time of the last call to set_progress_.
|
|
float | update_step_size_ = 0.01f |
| minimal progress interval after which set_progress_ is called.
|
|
std::optional< ProgressNode * > | parent_ |
| The parent of this, if this is not the root.
|
|
std::vector< float > | weights_ |
| Weights of children.
|
|
std::vector< ProgressNode > | children_ |
| Children representing sub-tasks of this task.
|
|
std::function< void(float)> | set_progress_ = [](float f) {} |
| Callback function used by the root node to inform about changes in the task progress.
|
|
Represents a node in a tree used to track the progress of a task.
Each node in the tree represents the progress in a sub-task. Each sub-task has a weight associated to it, which should be proportional to the time this task takes to be completed.
◆ ProgressNode() [1/2]
ProgressNode::ProgressNode |
( |
int | id, |
|
|
const std::vector< float > & | weights, |
|
|
std::optional< ProgressNode * > | parent ) |
Constructor.
- Parameters
-
id | Id of this node. Used to index weights and children of parent. |
weights | If not empty: Weights of sub-tasks. |
parent | Parent of this node. If empty: This is a root node. |
◆ ProgressNode() [2/2]
ProgressNode::ProgressNode |
( |
std::function< void(float)> | progress_callback, |
|
|
const std::vector< float > & | weights = {} ) |
Constructor for a root node.
- Parameters
-
progress_callback | a callback function used by the root node to inform about changes in the task progress. |
weights | If not empty: Weights of sub-tasks. |
◆ addChildren()
void ProgressNode::addChildren |
( |
const std::vector< float > & | weights | ) |
|
Adds new child nodes with given weights to this node.
- Parameters
-
weights | The child weights. |
◆ advance()
void ProgressNode::advance |
( |
uint64_t | num_steps = 1 | ) |
|
Advances the current progress of this node by the given amount of steps. This must be a leaf node.
- Parameters
-
num_steps | Number steps to advance. |
◆ child()
Returns a reference to the child with the given id.
- Parameters
-
- Returns
- The child.
◆ getProgress()
float ProgressNode::getProgress |
( |
| ) |
const |
Returns the current progress.
- Returns
- The progress.
◆ id()
int ProgressNode::id |
( |
| ) |
const |
Returns the id of this node.
- Returns
- The id.
◆ propagateProgress()
void ProgressNode::propagateProgress |
( |
| ) |
|
|
private |
Informs this nodes parent of a change in progress.
If this is a root node and the change of progress since the last update exceeds update_step_size_ : Call set_progress_.
◆ setProgressCallback()
void ProgressNode::setProgressCallback |
( |
std::function< void(float)> | progress_callback | ) |
|
Sets a callback function used by the root node to inform about changes in the task progress.
- Parameters
-
set_progress | The callback function. |
◆ setTotalSteps()
void ProgressNode::setTotalSteps |
( |
uint64_t | total_steps | ) |
|
Sets the total number of steps in this task.
- Parameters
-
total_steps | The number of steps. |
◆ setUpdateStepSize()
void ProgressNode::setUpdateStepSize |
( |
float | step_size | ) |
|
Sets the minimal progress interval after which the progress callback is called.
- Parameters
-
◆ totalSteps()
int ProgressNode::totalSteps |
( |
| ) |
const |
Returns the total number of steps in this task.
- Returns
- The number of steps.
◆ updateStepSize()
float ProgressNode::updateStepSize |
( |
| ) |
const |
Returns the minimal progress interval after which the progress callback is called.
- Returns
- The interval.
The documentation for this class was generated from the following files: