30 ProgressNode(
int id,
const std::vector<float>& weights, std::optional<ProgressNode*> parent);
37 ProgressNode(std::function<
void(
float)> progress_callback,
38 const std::vector<float>& weights = {});
45 void advance(uint64_t num_steps = 1);
65 void addChildren(
const std::vector<float>& weights);
ProgressNode & child(int id)
Returns a reference to the child with the given id.
Definition progressnode.cpp:63
float update_step_size_
minimal progress interval after which set_progress_ is called.
Definition progressnode.h:106
float updateStepSize() const
Returns the minimal progress interval after which the progress callback is called.
Definition progressnode.cpp:74
void propagateProgress()
Informs this nodes parent of a change in progress.
Definition progressnode.cpp:97
float prev_progress_
Progress at the time of the last call to set_progress_.
Definition progressnode.h:104
std::vector< float > weights_
Weights of children.
Definition progressnode.h:110
void setTotalSteps(uint64_t total_steps)
Sets the total number of steps in this task.
Definition progressnode.cpp:37
void setUpdateStepSize(float step_size)
Sets the minimal progress interval after which the progress callback is called.
Definition progressnode.cpp:79
void addChildren(const std::vector< float > &weights)
Adds new child nodes with given weights to this node.
Definition progressnode.cpp:49
float progress_
Current progress in this task.
Definition progressnode.h:102
float getProgress() const
Returns the current progress.
Definition progressnode.cpp:84
void updateProgress()
Sets the current progress of this node to the weighted sum of the current progresses of its children.
Definition progressnode.cpp:89
std::function< void(float)> set_progress_
Callback function used by the root node to inform about changes in the task progress.
Definition progressnode.h:118
uint64_t total_steps_
Number of total steps in this task. Only used for leaf nodes.
Definition progressnode.h:100
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.
Definition progressnode.cpp:20
uint64_t cur_step_
Current step in this task. Only used for leaf nodes.
Definition progressnode.h:98
int id_
This nodes id.
Definition progressnode.h:96
int totalSteps() const
Returns the total number of steps in this task.
Definition progressnode.cpp:32
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.
Definition progressnode.cpp:68
ProgressNode(int id, const std::vector< float > &weights, std::optional< ProgressNode * > parent)
Constructor.
Definition progressnode.cpp:6
std::vector< ProgressNode > children_
Children representing sub-tasks of this task.
Definition progressnode.h:112
int id() const
Returns the id of this node.
Definition progressnode.cpp:44
std::optional< ProgressNode * > parent_
The parent of this, if this is not the root.
Definition progressnode.h:108