17#ifndef __progressbar_h__
18#define __progressbar_h__
23#include <condition_variable>
33#define BUSY_INTERVAL 0.1
131 template <
class TextFunc>
141 progressbar_active =
false;
145 template <
class ThreadType>
171 std::string _text, _ellipsis;
172 size_t _value, current_val, next_percent;
176 bool _text_has_been_modified;
180 static bool progressbar_active;
203 _text_has_been_modified (false) {
206 progressbar_active =
true;
218 _multiplier = 0.01 * target;
232 _text_has_been_modified =
true;
233 if (new_text.size()) {
235 size_t old_size = _text.size();
239 if (_text.size() < old_size)
240 _text.resize (old_size,
' ');
249 template <
class TextFunc>
255 if (increment && _multiplier) {
256 if (++current_val >= next_percent) {
259 _value =
std::round (current_val / _multiplier);
260 next_percent =
std::ceil ((_value+1) * _multiplier);
266 if (time >= next_time) {
274 while (next_time <= time);
288 if (++current_val >= next_percent) {
289 _value =
std::round (current_val / _multiplier);
290 next_percent =
std::ceil ((_value+1) * _multiplier);
296 if (time >= next_time) {
299 while (next_time <= time);
309 template <
class ThreadType>
314 std::unique_lock<std::mutex> lock (
mutex);
implements a progress meter to provide feedback to the user
ProgressBar()
Create an unusable ProgressBar.
bool text_has_been_modified() const
static bool notification_is_genuine
void operator++()
increment the current value by one.
bool operator!() const
returns whether the progress will be shown
void run_update_thread(const ThreadType &threads) const
static void(* display_func)(const ProgressBar &p)
const std::string & text() const
static void(* previous_display_func)(const ProgressBar &p)
static bool set_update_method()
void set_max(size_t new_target)
set the maximum target value of the ProgressBar
ProgressBar(const ProgressBar &p)=delete
const std::string & ellipsis() const
static void(* done_func)(const ProgressBar &p)
static std::condition_variable notifier
void update(TextFunc &&text_func, bool increment=true)
update text displayed and optionally increment counter
ProgressBar(ProgressBar &&p)=default
bool show_percent() const
void set_text(const std::string &new_text)
constexpr I ceil(const T x)
template function with cast to different type
constexpr I round(const T x)
const std::thread::id main_thread_ID
vector< std::future< void > > threads