ROSE  0.11.145.0
Classes | Public Types | Public Member Functions | List of all members
Sawyer::ProgressBar< T, S > Class Template Reference

Description

template<typename T, typename S = std::string>
class Sawyer::ProgressBar< T, S >

Progress bars.

Progress bars are fully integrated with the Sawyer logging system so that they behave with respect to other messages.

Example usage:

void f() {
int total = 200;
ProgressBar<int> progress(total, mlog[MARCH], "test");
for (int i=0; i<total; ++i, ++progress)
do_some_work();
}

The progress bar is created with a name and capacity. As the progress bar is incremented the bar will increase. Messages printed while the progress bar is active do not interfere with the progress bar. When the progress bar object is destroyed the progress bar disappears.

Progress bars should be output to the MARCH stream rather than INFO. If all progress bars follow this policy then it's easy to enable or disable them without affecting other diagnostic output.

The entire progress bar public interface is synchronized–it can be called from multiple threads all accessing the same object and their operations will be serialized.

Definition at line 109 of file ProgressBar.h.

#include <util/Sawyer/ProgressBar.h>

Inheritance diagram for Sawyer::ProgressBar< T, S >:
Inheritance graph
[legend]

Public Types

typedef S Suffix
 
typedef T ValueType
 

Public Member Functions

 ProgressBar (const Message::SProxy &stream, const std::string &name="progress")
 Construct spinning progress bar. More...
 
 ProgressBar (ValueType rightValue, const Message::SProxy &stream, const std::string &name="progress")
 Construct a progress bar incrementing from zero to some limit. More...
 
 ProgressBar (ValueType leftValue, ValueType curValue, ValueType rightValue, const Message::SProxy &stream, const std::string &name="progress")
 Construct a progress bar with left and right limits. More...
 
double ratio () const
 Value of progress bar as a ratio of completeness clipped between 0 and 1. More...
 
bool isEmpty () const
 True if the distance between the minimum and maximum is zero. More...
 
bool isBackward () const
 True if the minimum value is greater than the maximum value. More...
 
ValueType value () const
 Value for the progress bar.
 
void value (ValueType curValue)
 Value for the progress bar.
 
void value (ValueType curValue, ValueType rightValue)
 Value for the progress bar.
 
void value (ValueType leftValue, ValueType curValue, ValueType rightValue)
 Value for the progress bar.
 
Suffix suffix ()
 Property: suffix. More...
 
Suffix suffix () const
 Property: suffix. More...
 
ProgressBarsuffix (const Suffix &suffix)
 Property: suffix. More...
 
std::pair< ValueType, ValueType > domain () const
 Possible values. More...
 
void domain (const std::pair< ValueType, ValueType > &p)
 Possible values. More...
 
void domain (ValueType leftValue, ValueType rightValue)
 Possible values. More...
 
void increment (ValueType delta=1)
 Increment or decrement the progress bar.
 
void decrement (ValueType delta=1)
 Increment or decrement the progress bar.
 
ProgressBaroperator++ ()
 Increment or decrement the progress bar.
 
ProgressBaroperator++ (int)
 Increment or decrement the progress bar.
 
ProgressBaroperator-- ()
 Increment or decrement the progress bar.
 
ProgressBaroperator-- (int)
 Increment or decrement the progress bar.
 
ProgressBaroperator+= (ValueType delta)
 Increment or decrement the progress bar.
 
ProgressBaroperator-= (ValueType delta)
 Increment or decrement the progress bar.
 
size_t width () const
 Width of progress bar in characters at 100%.
 
void width (size_t width)
 Width of progress bar in characters at 100%.
 
const std::string & prefix () const
 String to show before the beginning of the bar. More...
 
void prefix (const std::string &s)
 String to show before the beginning of the bar. More...
 
std::pair< char, char > barchars () const
 Characters to use for the bar. More...
 
void barchars (char bar, char nonBar)
 Characters to use for the bar. More...
 
std::pair< std::string, std::string > endchars () const
 Characters to use for the left and right ends of the bar. More...
 
void endchars (const std::string &lt, const std::string &rt)
 Characters to use for the left and right ends of the bar. More...
 
bool showPercent () const
 Whether to show the percent indication. More...
 
void showPercent (bool b)
 Whether to show the percent indication. More...
 
bool showValue () const
 Whether to show the current value. More...
 
void showValue (bool b)
 Whether to show the current value. More...
 

Constructor & Destructor Documentation

template<typename T, typename S = std::string>
Sawyer::ProgressBar< T, S >::ProgressBar ( const Message::SProxy stream,
const std::string &  name = "progress" 
)
inlineexplicit

Construct spinning progress bar.

A progress bar without a capacity results in a "spinner" that moves back and forth instead of a 0 to 100% bar. This kind of progress bar can be used when the number of iterations to complete a task is unknown.

Definition at line 133 of file ProgressBar.h.

template<typename T, typename S = std::string>
Sawyer::ProgressBar< T, S >::ProgressBar ( ValueType  rightValue,
const Message::SProxy stream,
const std::string &  name = "progress" 
)
inline

Construct a progress bar incrementing from zero to some limit.

The progress bar is initialized to zero and constructed so that when the value reaches rightValue the bar will read 100%.

Definition at line 141 of file ProgressBar.h.

template<typename T, typename S = std::string>
Sawyer::ProgressBar< T, S >::ProgressBar ( ValueType  leftValue,
ValueType  curValue,
ValueType  rightValue,
const Message::SProxy stream,
const std::string &  name = "progress" 
)
inline

Construct a progress bar with left and right limits.

The progress bar is set so that leftValue represents the zero percent point and rightValue represents the 100% point. The curValue is the current value of the progress bar, which need not be between the the limits (the percent indications will be clipped the the specified interval).

Definition at line 150 of file ProgressBar.h.

Member Function Documentation

template<typename T, typename S = std::string>
Suffix Sawyer::ProgressBar< T, S >::suffix ( )
inline

Property: suffix.

This user-defined object provides the suffix for the progress bar. It will be appended to the progress bar string with the std::ostream's << operator. It should not contain any line feeds.

Definition at line 190 of file ProgressBar.h.

Referenced by Sawyer::ProgressBar< size_t >::suffix().

template<typename T, typename S = std::string>
Suffix Sawyer::ProgressBar< T, S >::suffix ( ) const
inline

Property: suffix.

This user-defined object provides the suffix for the progress bar. It will be appended to the progress bar string with the std::ostream's << operator. It should not contain any line feeds.

Definition at line 194 of file ProgressBar.h.

template<typename T, typename S = std::string>
ProgressBar& Sawyer::ProgressBar< T, S >::suffix ( const Suffix &  suffix)
inline

Property: suffix.

This user-defined object provides the suffix for the progress bar. It will be appended to the progress bar string with the std::ostream's << operator. It should not contain any line feeds.

Definition at line 198 of file ProgressBar.h.

template<typename T, typename S = std::string>
double Sawyer::ProgressBar< T, S >::ratio ( ) const
inline

Value of progress bar as a ratio of completeness clipped between 0 and 1.

A progress bar that is backward (min value is greater than max value) also returns a value between zero and one, and also is a measurement of how far the progress bar should be drawn from the left side toward the right.

Definition at line 208 of file ProgressBar.h.

template<typename T, typename S = std::string>
bool Sawyer::ProgressBar< T, S >::isEmpty ( ) const
inline

True if the distance between the minimum and maximum is zero.

Definition at line 214 of file ProgressBar.h.

template<typename T, typename S = std::string>
bool Sawyer::ProgressBar< T, S >::isBackward ( ) const
inline

True if the minimum value is greater than the maximum value.

Definition at line 220 of file ProgressBar.h.

template<typename T, typename S = std::string>
std::pair<ValueType, ValueType> Sawyer::ProgressBar< T, S >::domain ( ) const
inline

Possible values.

These indicate the zero and 100% end points.

Definition at line 227 of file ProgressBar.h.

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::domain ( const std::pair< ValueType, ValueType > &  p)
inline

Possible values.

These indicate the zero and 100% end points.

Definition at line 231 of file ProgressBar.h.

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::domain ( ValueType  leftValue,
ValueType  rightValue 
)
inline

Possible values.

These indicate the zero and 100% end points.

Definition at line 237 of file ProgressBar.h.

template<typename T, typename S = std::string>
const std::string& Sawyer::ProgressBar< T, S >::prefix ( ) const
inline

String to show before the beginning of the bar.

This should be something very short, like "processing input".

Definition at line 290 of file ProgressBar.h.

Referenced by Rose::BinaryAnalysis::SerialInput::loadObject(), and Rose::BinaryAnalysis::SerialOutput::saveObject().

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::prefix ( const std::string &  s)
inline

String to show before the beginning of the bar.

This should be something very short, like "processing input".

Definition at line 294 of file ProgressBar.h.

template<typename T, typename S = std::string>
std::pair<char, char> Sawyer::ProgressBar< T, S >::barchars ( ) const
inline

Characters to use for the bar.

The first is from zero to the current ratio() and the second is the character with which to fill the rest of the bar's area. The defaults are '#' and '-'.

Definition at line 304 of file ProgressBar.h.

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::barchars ( char  bar,
char  nonBar 
)
inline

Characters to use for the bar.

The first is from zero to the current ratio() and the second is the character with which to fill the rest of the bar's area. The defaults are '#' and '-'.

Definition at line 308 of file ProgressBar.h.

template<typename T, typename S = std::string>
std::pair<std::string, std::string> Sawyer::ProgressBar< T, S >::endchars ( ) const
inline

Characters to use for the left and right ends of the bar.

The default is '[' and ']'.

Definition at line 318 of file ProgressBar.h.

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::endchars ( const std::string &  lt,
const std::string &  rt 
)
inline

Characters to use for the left and right ends of the bar.

The default is '[' and ']'.

Definition at line 322 of file ProgressBar.h.

template<typename T, typename S = std::string>
bool Sawyer::ProgressBar< T, S >::showPercent ( ) const
inline

Whether to show the percent indication.

The default is true.

Definition at line 332 of file ProgressBar.h.

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::showPercent ( bool  b)
inline

Whether to show the percent indication.

The default is true.

Definition at line 336 of file ProgressBar.h.

template<typename T, typename S = std::string>
bool Sawyer::ProgressBar< T, S >::showValue ( ) const
inline

Whether to show the current value.

The is true.

Definition at line 345 of file ProgressBar.h.

template<typename T, typename S = std::string>
void Sawyer::ProgressBar< T, S >::showValue ( bool  b)
inline

Whether to show the current value.

The is true.

Definition at line 349 of file ProgressBar.h.


The documentation for this class was generated from the following file: