1 #ifndef TAGPARSER_PROGRESS_FEEDBACK_H 2 #define TAGPARSER_PROGRESS_FEEDBACK_H 6 #include <c++utilities/conversion/types.h> 16 using Callback = std::function<void(ActualProgressFeedback &feedback)>;
21 const std::string &
step()
const;
34 byte m_stepPercentage;
35 byte m_overallPercentage;
43 template <
typename ActualProgressFeedback>
45 : m_callback(callback)
46 , m_percentageOnlyCallback(percentageOnlyCallback)
48 , m_overallPercentage(0)
57 template <
typename ActualProgressFeedback>
59 : m_callback(callback)
60 , m_percentageOnlyCallback(percentageOnlyCallback)
62 , m_overallPercentage(0)
80 return m_stepPercentage;
89 return m_overallPercentage;
96 template <
typename ActualProgressFeedback>
100 m_stepPercentage = stepPercentage;
102 m_callback(*static_cast<ActualProgressFeedback *>(
this));
110 template <
typename ActualProgressFeedback>
114 m_stepPercentage = stepPercentage;
116 m_callback(*static_cast<ActualProgressFeedback *>(
this));
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));
139 template <
typename ActualProgressFeedback>
142 updateStepPercentage(static_cast<byte>(stepPercentage * 100.0));
151 m_overallPercentage = overallPercentage;
152 if (m_percentageOnlyCallback) {
153 m_percentageOnlyCallback(*static_cast<ActualProgressFeedback *>(
this));
154 }
else if (m_callback) {
155 m_callback(*static_cast<ActualProgressFeedback *>(
this));
161 ProgressFeedback(
const Callback &callback,
const Callback &percentageOnlyCallback = Callback());
162 ProgressFeedback(Callback &&callback, Callback &&percentageOnlyCallback = Callback());
170 inline ProgressFeedback::ProgressFeedback(
const Callback &callback,
const Callback &percentageOnlyCallback)
197 std::atomic_bool m_aborted;
227 return m_aborted.load();
237 return m_aborted.store(
true);
277 #endif // TAGPARSER_PROGRESS_FEEDBACK_H void updateStepPercentage(byte stepPercentage)
Updates the current step percentage and invokes the second callback specified on construction (or the...
std::function< void(AbortableProgressFeedback &feedback)> Callback
The ProgressFeedback class provides feedback about an ongoing operation via callbacks.
void stopIfAborted() const
Throws an OperationAbortedException if aborted.
BasicProgressFeedback(const Callback &callback, const Callback &percentageOnlyCallback=Callback())
Constructs a new BasicProgressFeedback.
The BasicProgressFeedback class provides the base for ProgressFeedback and AbortableProgressFeedback...
ProgressFeedback(const Callback &callback, const Callback &percentageOnlyCallback=Callback())
Constructs a new ProgressFeedback.
void updateStepPercentageFromFraction(double stepPercentage)
Updates the current step percentage and invokes the second callback specified on construction (or the...
bool isAborted() const
Returns whether the operation has been aborted via tryToAbort().
byte stepPercentage() const
Returns the percentage of the current step (initially 0, supposed to be a value from 0 to 100)...
byte overallPercentage() const
Returns the overall percentage (initially 0, supposed to be a value from 0 to 100).
void tryToAbort()
Aborts the operation.
AbortableProgressFeedback(const Callback &callback, const Callback &percentageOnlyCallback=Callback())
Constructs a new AbortableProgressFeedback.
void updateOverallPercentage(byte overallPercentage)
Updates the overall percentage and invokes the second callback specified on construction (or the firs...
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks...
void updateStep(const std::string &step, byte stepPercentage=0)
Updates the current step and invokes the first callback specified on construction.
const std::string & step() const
Returns the name of the current step (initially empty).
The exception that is thrown when an operation has been stopped and thus not successfully completed b...
Contains all classes and functions of the TagInfo library.
void nextStepOrStop(const std::string &step, byte stepPercentage=0)
Throws an OperationAbortedException if aborted; otherwise the data for the next step is set...