2016-01-08 09:53:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <atomic>
|
|
|
|
#include <future>
|
2016-01-28 18:13:40 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
#include <mutex>
|
2016-01-08 09:53:35 +00:00
|
|
|
|
2016-01-28 18:13:40 +00:00
|
|
|
class ProgressSink {
|
|
|
|
public:
|
|
|
|
virtual ~ProgressSink() {}
|
|
|
|
virtual void reportProgress(double value) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProgressForwarder : public ProgressSink {
|
|
|
|
public:
|
|
|
|
ProgressForwarder(std::function<void(double progress)> callback);
|
|
|
|
void reportProgress(double value) override;
|
|
|
|
private:
|
|
|
|
std::function<void(double progress)> callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProgressMerger {
|
|
|
|
public:
|
|
|
|
ProgressMerger(ProgressSink& sink);
|
|
|
|
ProgressSink& addSink(double weight);
|
|
|
|
private:
|
|
|
|
void report();
|
|
|
|
|
|
|
|
ProgressSink& sink;
|
|
|
|
std::mutex mutex;
|
|
|
|
double totalWeight = 0;
|
|
|
|
std::list<ProgressForwarder> forwarders;
|
|
|
|
std::vector<double> weightedValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProgressBar : public ProgressSink {
|
2016-01-08 09:53:35 +00:00
|
|
|
public:
|
|
|
|
ProgressBar();
|
|
|
|
~ProgressBar();
|
2016-01-28 18:13:40 +00:00
|
|
|
void reportProgress(double value) override;
|
2016-01-08 09:53:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void updateLoop();
|
|
|
|
void updateText(const std::string& text);
|
|
|
|
|
|
|
|
std::future<void> updateLoopFuture;
|
|
|
|
std::atomic<double> currentProgress { 0 };
|
|
|
|
std::atomic<bool> done { false };
|
|
|
|
|
|
|
|
std::string currentText;
|
|
|
|
int animationIndex = 0;
|
|
|
|
};
|