TPIE

11a2c2d
tpie::progress_indicator_spin Class Reference

A class that indicates the progress by a spinning cross. More...

#include <tpie/progress_indicator_spin.h>

Inherits tpie::progress_indicator_terminal.

Public Member Functions

 progress_indicator_spin (const std::string &title, const std::string &description, stream_size_type minRange, stream_size_type maxRange, stream_size_type stepValue)
 Initializes the indicator. More...
 
 progress_indicator_spin (const progress_indicator_spin &other)
 Copy-constructor. More...
 
progress_indicator_spinoperator= (const progress_indicator_spin &other)
 Assignment operator. More...
 
virtual ~progress_indicator_spin ()
 The destructor. More...
 
virtual void refresh ()
 Display the indicator. More...
 
void done ()
 Advance the indicator to the end. More...
 
void set_title (const std::string &title)
 Set the title of a new task to be monitored. More...
 
void step (stream_size_type step=1)
 Record an increment to the indicator and advance the indicator. More...
 
void raw_step (stream_size_type step)
 Internal method used in fractional progress. More...
 
virtual void init (stream_size_type range=0)
 Initialize progress indicator. More...
 
virtual void set_range (stream_size_type range)
 Set the upper bound of the counting range. More...
 
stream_size_type get_current ()
 Get the current value of the step counter. More...
 
stream_size_type get_range ()
 Get the maximum value of the current range. More...
 
execution_time_predictorget_time_predictor ()
 
void set_time_predictor (execution_time_predictor *p)
 
std::string estimated_remaining_time ()
 
virtual void push_breadcrumb (const char *, description_importance)
 
virtual void pop_breadcrumb ()
 

Protected Member Functions

void display_percentage ()
 Compute and print the percentage or step count. More...
 

Protected Attributes

char * m_symbols
 The characters used for the spinning indicator. More...
 
unsigned short m_numberOfStates
 The number of characters used for the spinning indicator. More...
 
unsigned short m_state
 The current character used for the spinning indicator. More...
 
std::string m_title
 A string holding the description of the title. More...
 
stream_size_type m_range
 The upper bound of the counting range. More...
 
stream_size_type m_current
 The current progress count [m_minRange...m_maxRange]. More...
 

Detailed Description

A class that indicates the progress by a spinning cross.

Definition at line 41 of file progress_indicator_spin.h.

Constructor & Destructor Documentation

◆ progress_indicator_spin() [1/2]

tpie::progress_indicator_spin::progress_indicator_spin ( const std::string &  title,
const std::string &  description,
stream_size_type  minRange,
stream_size_type  maxRange,
stream_size_type  stepValue 
)
inline

Initializes the indicator.

Parameters
titleThe title of the progress indicator.
descriptionA text to be printed in front of the indicator.
minRangeThe lower bound of the range.
maxRangeThe upper bound of the range.
stepValueThe increment for each step.

Definition at line 58 of file progress_indicator_spin.h.

62  :
63  progress_indicator_terminal(title, description, minRange, maxRange, stepValue), m_symbols(NULL), m_numberOfStates(0), m_state(0) {
64  m_numberOfStates = 4;
65  m_symbols = new char[m_numberOfStates+2];
66  m_symbols[0] = '|';
67  m_symbols[1] = '/';
68  m_symbols[2] = '-';
69  m_symbols[3] = '\\';
70  m_symbols[4] = 'X';
71  m_symbols[5] = '\0';
72  }

References m_numberOfStates, and m_symbols.

◆ progress_indicator_spin() [2/2]

tpie::progress_indicator_spin::progress_indicator_spin ( const progress_indicator_spin other)
inline

Copy-constructor.

Definition at line 78 of file progress_indicator_spin.h.

78  :
80  *this = other;
81  }

◆ ~progress_indicator_spin()

virtual tpie::progress_indicator_spin::~progress_indicator_spin ( )
inlinevirtual

The destructor.

Nothing is done.

Definition at line 109 of file progress_indicator_spin.h.

109  {
110  delete [] m_symbols;
111  };

References m_symbols.

Member Function Documentation

◆ display_percentage()

void tpie::progress_indicator_terminal::display_percentage ( )
inlineprotectedinherited

Compute and print the percentage or step count.

Definition at line 139 of file progress_indicator_terminal.h.

140  {
141  //if (m_percentageUnit) {
142  // std::cout << std::setw(6) << std::setiosflags(std::ios::fixed) << std::setprecision(2)
143  // << ((static_cast<double>(m_current) * 100.0) /
144  // static_cast<double>(m_percentageUnit))
145  // << "%";
146  //}
147  //else {
148  // std::cout <<
149  //}
150  stream_size_type r = (m_current) * 100 / (m_range);
151  m_os << r << '%';
152  }

References tpie::progress_indicator_base::m_current, and tpie::progress_indicator_base::m_range.

Referenced by tpie::progress_indicator_terminal::refresh().

◆ done()

void tpie::progress_indicator_terminal::done ( )
inlinevirtualinherited

Advance the indicator to the end.

Reimplemented from tpie::progress_indicator_base.

Definition at line 95 of file progress_indicator_terminal.h.

95  {
97  refresh();
98  m_os << std::endl;
99  }

References tpie::progress_indicator_base::m_current, tpie::progress_indicator_base::m_range, and tpie::progress_indicator_terminal::refresh().

◆ get_current()

stream_size_type tpie::progress_indicator_base::get_current ( )
inlineinherited

Get the current value of the step counter.

Definition at line 152 of file progress_indicator_base.h.

152 { return m_current; }

◆ get_range()

stream_size_type tpie::progress_indicator_base::get_range ( )
inlineinherited

Get the maximum value of the current range.

Definition at line 157 of file progress_indicator_base.h.

157 { return m_range; }

◆ init()

virtual void tpie::progress_indicator_base::init ( stream_size_type  range = 0)
inlinevirtualinherited

Initialize progress indicator.

Parameters
rangeThe number of times step() is going to be called.

Reimplemented in tpie::fractional_subindicator, tpie::progress_indicator_subindicator, and tpie::progress_indicator_null.

Definition at line 121 of file progress_indicator_base.h.

121  {
122  if (range != 0) set_range(range);
123  m_current = 0;
124  call_refresh();
125  }

Referenced by tpie::merge_sorter< T, UseProgress, pred_t, store_t >::calc(), and tpie::parallel_sort().

◆ operator=()

progress_indicator_spin& tpie::progress_indicator_spin::operator= ( const progress_indicator_spin other)
inline

Assignment operator.

Definition at line 87 of file progress_indicator_spin.h.

87  {
88  if (this != &other) {
89 
90  progress_indicator_terminal::operator=(other);
91 
92  m_numberOfStates = other.m_numberOfStates;
93  m_state = other.m_state;
94 
95  delete[] m_symbols;
96 
97  m_symbols = new char[m_numberOfStates+2];
98  memcpy(m_symbols, other.m_symbols, m_numberOfStates+2);
99  }
100  return *this;
101  }

References m_numberOfStates, m_state, and m_symbols.

◆ raw_step()

void tpie::progress_indicator_base::raw_step ( stream_size_type  step)
inlineinherited

Internal method used in fractional progress.

In a hierarchy of fractional progress subindicators, only the lowest level of indicators should determine how many steps should pass until the next call to refresh(). When this happens, the subindicator calls raw_step() on its parent indicator rather than step(), which will short-circuit the logic and call the virtual method refresh() directly. You should probably not use this method; use step() instead.

Definition at line 111 of file progress_indicator_base.h.

111  {
112  m_current += step;
113  // Don't call call_refresh(); call refresh() directly instead.
114  refresh();
115  }

◆ refresh()

virtual void tpie::progress_indicator_spin::refresh ( )
inlinevirtual

Display the indicator.

Reimplemented from tpie::progress_indicator_terminal.

Definition at line 119 of file progress_indicator_spin.h.

119  {
121 
122  // Use the last symbol for indicating "done".
123  if (m_current == m_maxRange) m_state = m_numberOfStates;
124 
125  // Go to the beginning of the line and print the description.
126  std::cout << "\r" << m_description << " " << m_symbols[m_state] << std::flush;
127  }

References tpie::progress_indicator_base::m_current, m_numberOfStates, m_state, and m_symbols.

◆ set_range()

virtual void tpie::progress_indicator_base::set_range ( stream_size_type  range)
inlinevirtualinherited

Set the upper bound of the counting range.

This method also implies a reset of the counter. In order to be able to set the uper bound independent of setting the lower bound, no range checking is done.

Parameters
rangeThe new upper bound.

Reimplemented in tpie::progress_indicator_null.

Definition at line 140 of file progress_indicator_base.h.

140  {
141  m_range = range;
142  }

◆ set_title()

void tpie::progress_indicator_terminal::set_title ( const std::string &  title)
inlineinherited

Set the title of a new task to be monitored.

The terminal line will be newline'd, and the title will be followed by a newline as well.

Parameters
titleThe title of the new task to be monitored.

Definition at line 112 of file progress_indicator_terminal.h.

113  {
114  m_title = title;
115  m_os << title << std::endl;
116  }

References tpie::progress_indicator_terminal::m_title.

◆ step()

void tpie::progress_indicator_base::step ( stream_size_type  step = 1)
inlineinherited

Record an increment to the indicator and advance the indicator.

Definition at line 91 of file progress_indicator_base.h.

91  {
92  m_current += step;
93 
94  if (step >= m_remainingSteps) {
95  call_refresh();
96  } else {
97  m_remainingSteps -= step;
98  }
99  }

Referenced by tpie::merge_sorter< T, UseProgress, pred_t, store_t >::calc(), and tpie::ami::Internal_Sorter_Obj< T, Compare >::sort().

Member Data Documentation

◆ m_current

stream_size_type tpie::progress_indicator_base::m_current
protectedinherited

◆ m_numberOfStates

unsigned short tpie::progress_indicator_spin::m_numberOfStates
protected

The number of characters used for the spinning indicator.


Definition at line 135 of file progress_indicator_spin.h.

Referenced by operator=(), progress_indicator_spin(), and refresh().

◆ m_range

stream_size_type tpie::progress_indicator_base::m_range
protectedinherited

◆ m_state

unsigned short tpie::progress_indicator_spin::m_state
protected

The current character used for the spinning indicator.


Definition at line 138 of file progress_indicator_spin.h.

Referenced by operator=(), and refresh().

◆ m_symbols

char* tpie::progress_indicator_spin::m_symbols
protected

The characters used for the spinning indicator.


Definition at line 132 of file progress_indicator_spin.h.

Referenced by operator=(), progress_indicator_spin(), refresh(), and ~progress_indicator_spin().

◆ m_title

std::string tpie::progress_indicator_terminal::m_title
protectedinherited

The documentation for this class was generated from the following file:
tpie::progress_indicator_base::refresh
virtual void refresh()=0
Display the indicator.
tpie::progress_indicator_spin::m_numberOfStates
unsigned short m_numberOfStates
The number of characters used for the spinning indicator.
Definition: progress_indicator_spin.h:135
tpie::progress_indicator_base::set_range
virtual void set_range(stream_size_type range)
Set the upper bound of the counting range.
Definition: progress_indicator_base.h:140
tpie::progress_indicator_terminal::progress_indicator_terminal
progress_indicator_terminal(const char *title, stream_size_type range, std::ostream &os=std::cout)
Initializes the indicator.
Definition: progress_indicator_terminal.h:54
tpie::progress_indicator_base::m_current
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
Definition: progress_indicator_base.h:174
tpie::progress_indicator_base::step
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.
Definition: progress_indicator_base.h:91
tpie::progress_indicator_terminal::m_title
std::string m_title
A string holding the description of the title.
Definition: progress_indicator_terminal.h:155
tpie::progress_indicator_spin::m_state
unsigned short m_state
The current character used for the spinning indicator.
Definition: progress_indicator_spin.h:138
tpie::progress_indicator_spin::m_symbols
char * m_symbols
The characters used for the spinning indicator.
Definition: progress_indicator_spin.h:132
tpie::progress_indicator_terminal::refresh
virtual void refresh()
Display the indicator.
Definition: progress_indicator_terminal.h:124
tpie::progress_indicator_base::m_range
stream_size_type m_range
The upper bound of the counting range.
Definition: progress_indicator_base.h:171