mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-22 01:34:13 -05:00
50 lines
1.7 KiB
C++
50 lines
1.7 KiB
C++
#pragma once
|
|
#include "sys/Task.hpp"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
namespace sys
|
|
{
|
|
/// @brief Derived class of Task that has methods for tracking progress.
|
|
class ProgressTask final : public sys::Task
|
|
{
|
|
public:
|
|
/// @brief Contstructs a new ProgressTask
|
|
/// @param function Function for thread to execute.
|
|
/// @param args Arguments to forward to the thread function.
|
|
/// @note All functions passed to this must follow this signature: void function(sys::ProgressTask *,
|
|
//<arguments>)
|
|
template <typename... Args>
|
|
ProgressTask(void (*function)(sys::ProgressTask *, Args...), Args... args)
|
|
{
|
|
m_thread = std::thread(function, this, std::forward<Args>(args)...);
|
|
m_isRunning.store(true);
|
|
}
|
|
|
|
/// @brief Resets the progress and sets a new goal.
|
|
/// @param goal The goal we all strive for.
|
|
void reset(double goal) noexcept;
|
|
|
|
/// @brief Updates the current progress.
|
|
/// @param current The current progress value.
|
|
void update_current(double current) noexcept;
|
|
|
|
/// @brief Increases the current progress by a set amount.
|
|
void increase_current(double amount) noexcept;
|
|
|
|
/// @brief Returns the goal value.
|
|
/// @return Goal
|
|
double get_goal() const noexcept;
|
|
|
|
/// @brief Returns the current progress.
|
|
/// @return Current progress.
|
|
double get_progress() const noexcept;
|
|
|
|
private:
|
|
// Current value and goal
|
|
double m_current{};
|
|
double m_goal{};
|
|
};
|
|
} // namespace sys
|