implements a progress meter to provide feedback to the user More...
#include "progressbar.h"
Classes | |
struct | SwitchToMultiThreaded |
Public Member Functions | |
ProgressBar () | |
Create an unusable ProgressBar. More... | |
ProgressBar (const ProgressBar &p)=delete | |
ProgressBar (ProgressBar &&p)=default | |
~ProgressBar () | |
ProgressBar (const std::string &text, size_t target=0, int log_level=1) | |
Create a new ProgressBar, displaying the specified text. More... | |
operator bool () const | |
returns whether the progress will be shown More... | |
bool | operator! () const |
returns whether the progress will be shown More... | |
size_t | value () const |
size_t | count () const |
bool | show_percent () const |
bool | text_has_been_modified () const |
const std::string & | text () const |
const std::string & | ellipsis () const |
void | set_max (size_t new_target) |
set the maximum target value of the ProgressBar More... | |
void | set_text (const std::string &new_text) |
template<class TextFunc > | |
void | update (TextFunc &&text_func, bool increment=true) |
update text displayed and optionally increment counter More... | |
void | operator++ () |
increment the current value by one. More... | |
void | operator++ (int) |
void | done () |
template<class ThreadType > | |
void | run_update_thread (const ThreadType &threads) const |
Static Public Member Functions | |
static bool | set_update_method () |
Public Attributes | |
bool | first_time |
size_t | last_value |
Static Public Attributes | |
static void(* | display_func )(const ProgressBar &p) |
static void(* | done_func )(const ProgressBar &p) |
static void(* | previous_display_func )(const ProgressBar &p) |
static std::condition_variable | notifier |
static bool | notification_is_genuine |
static std::mutex | mutex |
static void * | data |
implements a progress meter to provide feedback to the user
The ProgressBar class displays a text message along with a indication of the progress status. For command-line applications, this will be shown on the terminal. For GUI applications, this will be shown as a graphical progress bar.
It has two modes of operation:
Other implementations can be created by overriding the display_func() and done_func() static functions. These functions will then be used throughout the application.
Definition at line 58 of file progressbar.h.
|
inline |
Create an unusable ProgressBar.
Definition at line 62 of file progressbar.h.
|
delete |
|
default |
|
inline |
Definition at line 66 of file progressbar.h.
|
inline |
Create a new ProgressBar, displaying the specified text.
If target is unspecified or set to zero, the ProgressBar will display a busy indicator, updated at regular time intervals. Otherwise, the ProgressBar will display the percentage completed, computed from the number of times the ProgressBar::operator++() function was called relative to the value specified with target.
Definition at line 192 of file progressbar.h.
|
inline |
Definition at line 95 of file progressbar.h.
|
inline |
Definition at line 138 of file progressbar.h.
|
inline |
Definition at line 99 of file progressbar.h.
|
inline |
returns whether the progress will be shown
The progress may not be shown if the -quiet option has been supplied to the application.
Definition at line 82 of file progressbar.h.
|
inline |
returns whether the progress will be shown
The progress may not be shown if the -quiet option has been supplied to the application.
Definition at line 90 of file progressbar.h.
|
inline |
increment the current value by one.
Definition at line 283 of file progressbar.h.
|
inline |
Definition at line 136 of file progressbar.h.
|
inline |
Definition at line 310 of file progressbar.h.
|
inline |
set the maximum target value of the ProgressBar
This function should only be called if the ProgressBar has been created with a non-zero target value. In other words, the ProgressBar has been created to display a percentage value, rather than a busy indicator.
Definition at line 213 of file progressbar.h.
|
inline |
Definition at line 228 of file progressbar.h.
|
static |
|
inline |
Definition at line 96 of file progressbar.h.
|
inline |
Definition at line 98 of file progressbar.h.
|
inline |
Definition at line 97 of file progressbar.h.
|
inline |
update text displayed and optionally increment counter
This expects a function, functor or lambda function that should return a std::string to replace the text. This functor will only be called when necessary, i.e. when BUSY_INTERVAL time has elapsed, or if the percentage value to display has changed. The reason for passing a functor rather than the text itself is to minimise the overhead of forming the string in cases where this is sufficiently expensive to impact performance if invoked every iteration. By passing a function, this operation is only performed when strictly necessary.
The simplest way to use this method is using C++11 lambda functions, for example:
Definition at line 250 of file progressbar.h.
|
inline |
Definition at line 94 of file progressbar.h.
|
static |
Definition at line 163 of file progressbar.h.
|
static |
Definition at line 156 of file progressbar.h.
|
static |
Definition at line 157 of file progressbar.h.
|
mutable |
Definition at line 165 of file progressbar.h.
|
mutable |
Definition at line 166 of file progressbar.h.
|
static |
Definition at line 162 of file progressbar.h.
|
static |
Definition at line 161 of file progressbar.h.
|
static |
Definition at line 160 of file progressbar.h.
|
static |
Definition at line 158 of file progressbar.h.