1#ifndef TAGPARSER_PROGRESS_FEEDBACK_H
2#define TAGPARSER_PROGRESS_FEEDBACK_H
15 using Callback = std::function<void(ActualProgressFeedback &feedback)>;
20 const std::string &
step()
const;
33 std::uint8_t m_stepPercentage;
34 std::uint8_t m_overallPercentage;
42template <
typename ActualProgressFeedback>
44 : m_callback(callback)
45 , m_percentageOnlyCallback(percentageOnlyCallback)
47 , m_overallPercentage(0)
56template <
typename ActualProgressFeedback>
58 : m_callback(callback)
59 , m_percentageOnlyCallback(percentageOnlyCallback)
61 , m_overallPercentage(0)
79 return m_stepPercentage;
88 return m_overallPercentage;
95template <
typename ActualProgressFeedback>
99 m_stepPercentage = stepPercentage;
101 m_callback(*
static_cast<ActualProgressFeedback *
>(
this));
109template <
typename ActualProgressFeedback>
113 m_stepPercentage = stepPercentage;
115 m_callback(*
static_cast<ActualProgressFeedback *
>(
this));
123template <
typename ActualProgressFeedback>
126 m_stepPercentage = stepPercentage;
127 if (m_percentageOnlyCallback) {
128 m_percentageOnlyCallback(*
static_cast<ActualProgressFeedback *
>(
this));
129 }
else if (m_callback) {
130 m_callback(*
static_cast<ActualProgressFeedback *
>(
this));
139template <
typename ActualProgressFeedback>
142 updateStepPercentage(
static_cast<std::uint8_t
>(stepPercentage * 100.0));
149template <
typename ActualProgressFeedback>
152 m_overallPercentage = overallPercentage;
153 if (m_percentageOnlyCallback) {
154 m_percentageOnlyCallback(*
static_cast<ActualProgressFeedback *
>(
this));
155 }
else if (m_callback) {
156 m_callback(*
static_cast<ActualProgressFeedback *
>(
this));
199 std::atomic_bool m_aborted;
229 , m_aborted(other.isAborted())
238 return m_aborted.load();
248 return m_aborted.store(
true);
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
bool isAborted() const
Returns whether the operation has been aborted via tryToAbort().
void stopIfAborted() const
Throws an OperationAbortedException if aborted.
AbortableProgressFeedback(const Callback &callback, const Callback &percentageOnlyCallback=Callback())
Constructs a new AbortableProgressFeedback.
void tryToAbort()
Aborts the operation.
void nextStepOrStop(const std::string &step, std::uint8_t stepPercentage=0)
Throws an OperationAbortedException if aborted; otherwise the data for the next step is set.
The BasicProgressFeedback class provides the base for ProgressFeedback and AbortableProgressFeedback.
std::uint8_t stepPercentage() const
Returns the percentage of the current step (initially 0, supposed to be a value from 0 to 100).
void updateStep(std::string &&step, std::uint8_t stepPercentage=0)
Updates the current step and invokes the first callback specified on construction.
void updateStep(const std::string &step, std::uint8_t stepPercentage=0)
Updates the current step and invokes the first callback specified on construction.
BasicProgressFeedback(Callback &&callback=Callback(), Callback &&percentageOnlyCallback=Callback())
Constructs a new BasicProgressFeedback.
void updateStepPercentage(std::uint8_t stepPercentage)
Updates the current step percentage and invokes the second callback specified on construction (or the...
const std::string & step() const
Returns the name of the current step (initially empty).
void updateStepPercentageFromFraction(double stepPercentage)
Updates the current step percentage and invokes the second callback specified on construction (or the...
std::function< void(ActualProgressFeedback &feedback)> Callback
BasicProgressFeedback(const Callback &callback, const Callback &percentageOnlyCallback=Callback())
Constructs a new BasicProgressFeedback.
std::uint8_t overallPercentage() const
Returns the overall percentage (initially 0, supposed to be a value from 0 to 100).
void updateOverallPercentage(std::uint8_t overallPercentage)
Updates the overall percentage and invokes the second callback specified on construction (or the firs...
The exception that is thrown when an operation has been stopped and thus not successfully completed b...
The ProgressFeedback class provides feedback about an ongoing operation via callbacks.
ProgressFeedback(const Callback &callback, const Callback &percentageOnlyCallback=Callback())
Constructs a new ProgressFeedback.
Contains all classes and functions of the TagInfo library.