ROSE 0.11.145.192
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();
}
Progress bars.

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 <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.
 
 ProgressBar (ValueType rightValue, const Message::SProxy &stream, const std::string &name="progress")
 Construct a progress bar incrementing from zero to some limit.
 
 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.
 
double ratio () const
 Value of progress bar as a ratio of completeness clipped between 0 and 1.
 
bool isEmpty () const
 True if the distance between the minimum and maximum is zero.
 
bool isBackward () const
 True if the minimum value is greater than the maximum value.
 
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.
 
Suffix suffix () const
 Property: suffix.
 
ProgressBarsuffix (const Suffix &suffix)
 Property: suffix.
 
std::pair< ValueType, ValueType > domain () const
 Possible values.
 
void domain (const std::pair< ValueType, ValueType > &p)
 Possible values.
 
void domain (ValueType leftValue, ValueType rightValue)
 Possible values.
 
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.
 
void prefix (const std::string &s)
 String to show before the beginning of the bar.
 
std::pair< char, char > barchars () const
 Characters to use for the bar.
 
void barchars (char bar, char nonBar)
 Characters to use for the bar.
 
std::pair< std::string, std::string > endchars () const
 Characters to use for the left and right ends of the bar.
 
void endchars (const std::string &lt, const std::string &rt)
 Characters to use for the left and right ends of the bar.
 
bool showPercent () const
 Whether to show the percent indication.
 
void showPercent (bool b)
 Whether to show the percent indication.
 
bool showValue () const
 Whether to show the current value.
 
void showValue (bool b)
 Whether to show the current value.
 

Member Typedef Documentation

◆ Suffix

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

Definition at line 111 of file ProgressBar.h.

◆ ValueType

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

Definition at line 112 of file ProgressBar.h.

Constructor & Destructor Documentation

◆ ProgressBar() [1/3]

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.

◆ ProgressBar() [2/3]

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.

◆ ProgressBar() [3/3]

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

◆ value() [1/4]

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

Value for the progress bar.

Definition at line 159 of file ProgressBar.h.

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

◆ value() [2/4]

template<typename T , typename S = std::string>
void Sawyer::ProgressBar< T, S >::value ( ValueType  curValue)
inline

Value for the progress bar.

Definition at line 163 of file ProgressBar.h.

◆ value() [3/4]

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

Value for the progress bar.

Definition at line 169 of file ProgressBar.h.

◆ value() [4/4]

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

Value for the progress bar.

Definition at line 176 of file ProgressBar.h.

◆ suffix() [1/3]

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< T, S >::suffix().

◆ suffix() [2/3]

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.

◆ suffix() [3/3]

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.

References Sawyer::ProgressBar< T, S >::suffix().

◆ ratio()

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.

◆ isEmpty()

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.

◆ isBackward()

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.

◆ domain() [1/3]

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.

◆ domain() [2/3]

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.

◆ domain() [3/3]

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.

◆ increment()

template<typename T , typename S >
void Sawyer::ProgressBar< T, S >::increment ( ValueType  delta = 1)

Increment or decrement the progress bar.

Definition at line 415 of file ProgressBar.h.

Referenced by Sawyer::ProgressBar< T, S >::operator++(), Sawyer::ProgressBar< T, S >::operator++(), and Sawyer::ProgressBar< T, S >::operator+=().

◆ decrement()

template<typename T , typename S >
void Sawyer::ProgressBar< T, S >::decrement ( ValueType  delta = 1)

Increment or decrement the progress bar.

Definition at line 424 of file ProgressBar.h.

Referenced by Sawyer::ProgressBar< T, S >::operator--(), Sawyer::ProgressBar< T, S >::operator--(), and Sawyer::ProgressBar< T, S >::operator-=().

◆ operator++() [1/2]

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

Increment or decrement the progress bar.

Definition at line 249 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::increment().

◆ operator++() [2/2]

template<typename T , typename S = std::string>
ProgressBar & Sawyer::ProgressBar< T, S >::operator++ ( int  )
inline

Increment or decrement the progress bar.

Definition at line 253 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::increment().

◆ operator--() [1/2]

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

Increment or decrement the progress bar.

Definition at line 257 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::decrement().

◆ operator--() [2/2]

template<typename T , typename S = std::string>
ProgressBar & Sawyer::ProgressBar< T, S >::operator-- ( int  )
inline

Increment or decrement the progress bar.

Definition at line 261 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::decrement().

◆ operator+=()

template<typename T , typename S = std::string>
ProgressBar & Sawyer::ProgressBar< T, S >::operator+= ( ValueType  delta)
inline

Increment or decrement the progress bar.

Definition at line 265 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::increment().

◆ operator-=()

template<typename T , typename S = std::string>
ProgressBar & Sawyer::ProgressBar< T, S >::operator-= ( ValueType  delta)
inline

Increment or decrement the progress bar.

Definition at line 269 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::decrement().

◆ width() [1/2]

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

Width of progress bar in characters at 100%.

Definition at line 277 of file ProgressBar.h.

Referenced by Sawyer::ProgressBar< T, S >::width().

◆ width() [2/2]

template<typename T , typename S = std::string>
void Sawyer::ProgressBar< T, S >::width ( size_t  width)
inline

Width of progress bar in characters at 100%.

Definition at line 281 of file ProgressBar.h.

References Sawyer::ProgressBar< T, S >::width().

◆ prefix() [1/2]

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().

◆ prefix() [2/2]

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.

◆ barchars() [1/2]

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.

◆ barchars() [2/2]

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.

◆ endchars() [1/2]

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.

◆ endchars() [2/2]

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.

◆ showPercent() [1/2]

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.

◆ showPercent() [2/2]

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.

◆ showValue() [1/2]

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.

◆ showValue() [2/2]

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: