31 #ifndef STRUCT_STATUSSETTER_HPP_ 32 #define STRUCT_STATUSSETTER_HPP_ 34 #include "../Helper/CommaLocale.hpp" 118 const std::string& setCurrentStatus,
119 float setProgressAfter,
120 std::function<
void(
const std::string&)> callbackToSetStatus,
121 std::function<
void(
float)> callbackToSetProgress,
122 std::function<
bool()> callbackToCheckIsRunning
123 ) : currentStatus(setCurrentStatus),
124 progressAfter(setProgressAfter),
125 callbackSetStatus(std::move(callbackToSetStatus)),
126 callbackSetProgress(std::move(callbackToSetProgress)),
127 callbackIsRunning(std::move(callbackToCheckIsRunning)) {
143 bool change(
const std::string& statusMessage) {
144 this->currentStatus = statusMessage;
161 bool update(std::size_t done, std::size_t total)
const {
162 std::ostringstream statusStrStr;
167 statusStrStr <<
" [";
168 statusStrStr << done;
170 statusStrStr << total;
192 bool update(
float percentage,
bool precise)
const {
193 std::ostringstream statusStrStr;
199 statusStrStr.precision(0);
203 statusStrStr <<
" [";
205 statusStrStr <<
"%]";
227 bool update(std::size_t done, std::size_t total,
bool precise)
const {
228 return this->
update(static_cast<float>(done) / total, precise);
float progressAfter
The progress to which the thread will be (re-)set when the current task has been finished, in percent.
Definition: StatusSetter.hpp:69
std::function< bool()> callbackIsRunning
Callback function to check whether the current thread should still be running.
Definition: StatusSetter.hpp:82
constexpr auto precisionProgress
The precision (number of fractal digits) when showing the progress in percent.
Definition: StatusSetter.hpp:49
bool isRunning() const
Checks whether the thread is still supposed to run.
Definition: StatusSetter.hpp:236
bool update(std::size_t done, std::size_t total) const
Updates the status with a fractal progress.
Definition: StatusSetter.hpp:161
std::string currentStatus
The current status, to which the current progress will be added.
Definition: StatusSetter.hpp:62
bool update(std::size_t done, std::size_t total, bool precise) const
Calculates the current percentage and updates the status accordingly.
Definition: StatusSetter.hpp:227
bool change(const std::string &statusMessage)
Changes the status message and resets the current progress.
Definition: StatusSetter.hpp:143
static std::locale locale()
Definition: CommaLocale.hpp:44
constexpr auto percentageFactor
The factor for converting a fractal into a percentage.
Definition: StatusSetter.hpp:52
Structure containing all the data needed to keep the status of a thread updated.
Definition: StatusSetter.hpp:57
bool update(float percentage, bool precise) const
Updates the status with a percentage.
Definition: StatusSetter.hpp:192
std::function< void(float)> callbackSetProgress
Callback function to update the progress of the current thread, in percent.
Definition: StatusSetter.hpp:79
StatusSetter(const std::string &setCurrentStatus, float setProgressAfter, std::function< void(const std::string &)> callbackToSetStatus, std::function< void(float)> callbackToSetProgress, std::function< bool()> callbackToCheckIsRunning)
Constructor setting the initial status.
Definition: StatusSetter.hpp:117
void finish() const
Re-sets the progress of the thread.
Definition: StatusSetter.hpp:241
Namespace for data structures.
Definition: AlgoThreadProperties.hpp:43
std::function< void(const std::string &)> callbackSetStatus
Callback function to update the status message of the current thread.
Definition: StatusSetter.hpp:76