12#include <shared_mutex>
50 virtual void set(_In_ T value)
88 lazy_progress(_In_
const std::chrono::nanoseconds& timeout = std::chrono::nanoseconds(500000)) :
112 virtual void set(_In_ T value)
114 if (value == m_start || value == m_end)
115 m_last = std::chrono::high_resolution_clock::now();
116 else if (value == m_value)
119 auto now = std::chrono::high_resolution_clock::now();
120 if (now - m_last < m_timeout)
135 std::chrono::nanoseconds m_timeout;
136 std::chrono::system_clock::time_point m_last;
137 T m_start, m_end, m_value;
187 m_global.start = start;
190 m_host->set_range(m_global.start, m_global.end);
201 m_section.start = start;
213 m_host->set_text(msg);
224 m_local.start = start;
233 virtual void set(_In_ T value)
236 T size = m_local.size();
239 m_host->set(((value - m_local.start) * m_section.size() / size) + m_section.start);
260 return m_host && m_host->cancel();
286 m_host_ref = this->
detach();
309 T m_start, m_end, m_value;
314 m_start(0), m_end(0),
325 std::shared_lock<std::shared_mutex> lk(m_host.m_mutex);
327 m_host.m_host->set_text(msg);
339 combined_start = m_host.m_start += start - m_start,
340 combined_end = m_host.m_end += end - m_end;
343 std::shared_lock<std::shared_mutex> lk(m_host.m_mutex);
345 m_host.m_host->set_range(combined_start, combined_end);
353 virtual void set(_In_ T value)
355 T combined_value = m_host.m_value += value - m_value;
357 std::shared_lock<std::shared_mutex> lk(m_host.m_mutex);
359 m_host.m_host->set(combined_value);
369 std::shared_lock<std::shared_mutex> lk(m_host.m_mutex);
371 m_host.m_host->show(
show);
379 std::shared_lock<std::shared_mutex> lk(m_host.m_mutex);
380 return m_host.m_host && m_host.m_host->cancel();
385 std::atomic<T> m_start, m_end, m_value;
386 std::vector<worker_progress> m_workers;
387 std::shared_mutex m_mutex;
398 m_start(0), m_end(0),
401 m_workers.reserve(num_workers);
402 for (
size_t i = 0; i < num_workers; ++i)
406 m_host->
set(m_value);
417 std::unique_lock<std::shared_mutex> lk(m_mutex);
421 m_host->
set(m_value);
432 std::unique_lock<std::shared_mutex> lk(m_mutex);
447 return m_workers[index];
Progress indicator for individual worker.
Definition progress.hpp:306
virtual void set(T value)
Set local current progress.
Definition progress.hpp:353
virtual bool cancel()
Query whether user requested abort.
Definition progress.hpp:377
virtual void show(bool show=true)
Show or hide progress.
Definition progress.hpp:367
virtual void set_range(T start, T end)
Set local extend of the progress indicator.
Definition progress.hpp:336
virtual void set_text(const char *msg)
Set progress indicator text.
Definition progress.hpp:323
Aggregated progress indicator.
Definition progress.hpp:300
progress< T > & operator[](size_t index)
Returns progress indicator for specific worker.
Definition progress.hpp:445
void attach(progress< T > *host)
Attach to a host progress indicator.
Definition progress.hpp:415
progress< T > * detach()
Detach host progress indicator.
Definition progress.hpp:430
aggregate_progress(size_t num_workers, progress< T > *host=nullptr)
Constructs a progress indicator.
Definition progress.hpp:396
Global progress indicator.
Definition progress.hpp:147
void set_section_range(T start, T end)
Set section extend of the progress indicator.
Definition progress.hpp:199
virtual void show(bool show=true)
Show or hide progress.
Definition progress.hpp:249
virtual bool cancel()
Query whether user requested abort.
Definition progress.hpp:258
virtual void set(T value)
Set local current progress.
Definition progress.hpp:233
virtual void set_text(const char *msg)
Set progress indicator text.
Definition progress.hpp:210
progress< T > * detach()
Detach host progress indicator.
Definition progress.hpp:172
void set_global_range(T start, T end)
Set global extend of the progress indicator.
Definition progress.hpp:185
global_progress(progress< T > *host=nullptr)
Constructs a progress indicator.
Definition progress.hpp:154
void attach(progress< T > *host)
Attach to a host progress indicator.
Definition progress.hpp:162
virtual void set_range(T start, T end)
Set local extend of the progress indicator.
Definition progress.hpp:222
Lazy progress indicator.
Definition progress.hpp:81
virtual void set(T value)
Set current progress.
Definition progress.hpp:112
lazy_progress(const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds(500000))
Constructs a lazy progress indicator.
Definition progress.hpp:88
virtual void do_set()
Called when progress reporting is due. Should override this method to implement actual progress refre...
Definition progress.hpp:132
virtual void set_range(T start, T end)
Set progress range extent.
Definition progress.hpp:101
Progress indicator switcher.
Definition progress.hpp:275
Progress indicator base class.
Definition progress.hpp:22
virtual bool cancel()
Query whether user requested abort.
Definition progress.hpp:68
virtual void set_text(const char *msg)
Set progress indicator text.
Definition progress.hpp:29
virtual void show(bool show=true)
Show or hide progress.
Definition progress.hpp:60
virtual void set(T value)
Set current progress.
Definition progress.hpp:50
virtual void set_range(T start, T end)
Set progress range extent.
Definition progress.hpp:40
Numerical interval.
Definition interval.hpp:18