#pragma once #include #include #include #include #include #include #include class ProgressSink { public: virtual ~ProgressSink() {} virtual void reportProgress(double value) = 0; }; class ProgressForwarder : public ProgressSink { public: ProgressForwarder(std::function callback); void reportProgress(double value) override; private: std::function callback; }; class ProgressMerger { public: ProgressMerger(ProgressSink& sink); ProgressSink& addSink(double weight); private: void report(); ProgressSink& sink; std::mutex mutex; double totalWeight = 0; std::list forwarders; std::vector weightedValues; }; class ProgressBar : public ProgressSink { public: ProgressBar(); ~ProgressBar(); void reportProgress(double value) override; private: void updateLoop(); void updateText(const std::string& text); std::future updateLoopFuture; std::atomic currentProgress { 0 }; std::atomic done { false }; std::string currentText; int animationIndex = 0; };