TPIE

2362a60
tpie::progress_indicator_arrow Class Reference

A class that indicates the progress by expanding an arrow. More...

#include <tpie/progress_indicator_arrow.h>

Inherits tpie::progress_indicator_terminal.

Public Member Functions

 progress_indicator_arrow (const char *title, stream_size_type range, std::ostream &os=std::cout)
 Initializes the indicator. More...
 
void set_indicator_length (int indicatorLength)
 Set the maximum length of the indicator. More...
 
virtual void reset ()
 Reset the current state of the indicator and its current length. More...
 
void push_breadcrumb (const char *crumb, description_importance)
 
void pop_breadcrumb ()
 
virtual void refresh ()
 Display the indicator. More...
 
void done ()
 Advance the indicator to the end and print an (optional) message that is followed by a newline. 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 ()
 

Protected Member Functions

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

Protected Attributes

memory_size_type m_indicatorLength
 The maximal length of the indicator. More...
 
std::string m_status
 The previously displayed status line. More...
 
std::ostream & m_os
 ostream on which to display the progress indicator More...
 
std::deque< std::string > m_crumbs
 
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 expanding an arrow.

Definition at line 37 of file progress_indicator_arrow.h.

Constructor & Destructor Documentation

tpie::progress_indicator_arrow::progress_indicator_arrow ( const char *  title,
stream_size_type  range,
std::ostream &  os = std::cout 
)
inline

Initializes the indicator.

Parameters
titleThe title of the progress indicator.
rangeThe number of times we call step

Definition at line 48 of file progress_indicator_arrow.h.

References m_indicatorLength.

48  :
49  progress_indicator_terminal(title, range, os) , m_indicatorLength(0), m_os(os) {
50  m_indicatorLength = 110;
51  }
memory_size_type m_indicatorLength
The maximal length of the indicator.
std::ostream & m_os
ostream on which to display the progress indicator
progress_indicator_terminal(const char *title, stream_size_type range, std::ostream &os=std::cout)
Initializes the indicator.

Member Function Documentation

void tpie::progress_indicator_terminal::display_percentage ( )
inlineprotectedinherited

Compute and print the percentage or step count.

Definition at line 143 of file progress_indicator_terminal.h.

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

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

144  {
145  //if (m_percentageUnit) {
146  // std::cout << std::setw(6) << std::setiosflags(std::ios::fixed) << std::setprecision(2)
147  // << ((static_cast<double>(m_current) * 100.0) /
148  // static_cast<double>(m_percentageUnit))
149  // << "%";
150  //}
151  //else {
152  // std::cout <<
153  //}
154  stream_size_type r = (m_current) * 100 / (m_range);
155  m_os << r << '%';
156  }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
stream_size_type m_range
The upper bound of the counting range.
void tpie::progress_indicator_terminal::done ( )
inlinevirtualinherited

Advance the indicator to the end and print an (optional) message that is followed by a newline.

Parameters
textThe message to be printed at the end of the indicator.

Reimplemented from tpie::progress_indicator_base.

Definition at line 99 of file progress_indicator_terminal.h.

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

99  {
100  m_current = m_range;
101  refresh();
102  m_os << std::endl;
103  }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
virtual void refresh()
Display the indicator.
stream_size_type m_range
The upper bound of the counting range.
stream_size_type tpie::progress_indicator_base::get_current ( )
inlineinherited

Get the current value of the step counter.

Definition at line 151 of file progress_indicator_base.h.

References tpie::progress_indicator_base::m_current.

151 { return m_current; }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
stream_size_type tpie::progress_indicator_base::get_range ( )
inlineinherited

Get the maximum value of the current range.

Definition at line 156 of file progress_indicator_base.h.

References tpie::progress_indicator_base::m_range.

156 { return m_range; }
stream_size_type m_range
The upper bound of the counting range.
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_null, and tpie::progress_indicator_subindicator.

Definition at line 120 of file progress_indicator_base.h.

References tpie::progress_indicator_base::m_current, and tpie::progress_indicator_base::set_range().

Referenced by tpie::merge_sorter< T, UseProgress, pred_t, store_t >::calc(), tpie::pipelining::serialization_bits::sort_calc_t< Traits >::go(), and tpie::parallel_sort().

120  {
121  if (range != 0) set_range(range);
122  m_current = 0;
123  call_refresh();
124  }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
virtual void set_range(stream_size_type range)
Set the upper bound of the counting range.
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 110 of file progress_indicator_base.h.

References tpie::progress_indicator_base::m_current, tpie::progress_indicator_base::refresh(), and tpie::progress_indicator_base::step().

110  {
111  m_current += step;
112  // Don't call call_refresh(); call refresh() directly instead.
113  refresh();
114  }
virtual void refresh()=0
Display the indicator.
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.
virtual void tpie::progress_indicator_arrow::refresh ( )
inlinevirtual

Display the indicator.

Reimplemented from tpie::progress_indicator_terminal.

Definition at line 81 of file progress_indicator_arrow.h.

References tpie::progress_indicator_base::m_current, m_indicatorLength, tpie::progress_indicator_base::m_range, and tpie::progress_indicator_terminal::m_title.

81  {
82  // Compute the relative length of the arrow.
83  //std::cout << "refresh " << m_description << std::endl;
84 
85  memory_size_type l = m_indicatorLength - 12 - m_title.size();
86  memory_size_type progress = (m_range != 0) ?
87  static_cast<memory_size_type>(l * m_current / m_range) : 0;
88 
89  std::string newStatus;
90  {
91  std::stringstream status;
92 
93  // Don't print the last item.
94  if (progress >= l) progress = l -1;
95 
96  // Go to the beginning of the line and print the description.
97  status << m_title << " [";
98 
99  // Extend the arrow.
100 
101  status << std::string(progress, '=');
102  status << '>';
103 
104  // Print blank space.
105  status << std::string(l-progress-1, ' ');
106  status << "] ";
107 
108  status << m_current * 100 / m_range << '%';
109 
110  for (std::deque<std::string>::iterator i = m_crumbs.begin(); i != m_crumbs.end(); ++i) {
111  if (i == m_crumbs.begin()) status << ' ';
112  else status << " > ";
113  status << *i;
114  }
115 
116  status << ' ' << estimated_remaining_time();
117 
118  newStatus = status.str();
119  }
120 
121  if (newStatus != m_status) {
122 #ifdef WIN32
123  m_os << '\r' << std::string(m_status.size(), ' ') << '\r'
124  << newStatus << std::flush;
125 #else
126  m_os << "\r\x1B[K" << newStatus << std::flush;
127 #endif
128  std::swap(newStatus, m_status);
129  }
130  }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
memory_size_type m_indicatorLength
The maximal length of the indicator.
stream_size_type m_range
The upper bound of the counting range.
std::string m_title
A string holding the description of the title.
virtual void tpie::progress_indicator_arrow::reset ( )
inlinevirtual

Reset the current state of the indicator and its current length.

Definition at line 66 of file progress_indicator_arrow.h.

References tpie::progress_indicator_base::m_current.

66  {
67  m_current = 0;
68  }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
void tpie::progress_indicator_arrow::set_indicator_length ( int  indicatorLength)
inline

Set the maximum length of the indicator.

The length is enforced to be an integer in [2,60].

Parameters
indicatorLengthThe maximum length of the indicator.

Definition at line 59 of file progress_indicator_arrow.h.

References m_indicatorLength.

59  {
60  m_indicatorLength = std::max(2, std::min(60, indicatorLength));
61  }
memory_size_type m_indicatorLength
The maximal length of the indicator.
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 139 of file progress_indicator_base.h.

References tpie::progress_indicator_base::m_range.

Referenced by tpie::progress_indicator_base::init().

139  {
140  m_range = range;
141  }
stream_size_type m_range
The upper bound of the counting range.
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 116 of file progress_indicator_terminal.h.

References tpie::progress_indicator_terminal::m_title.

117  {
118  m_title = title;
119  m_os << title << std::endl;
120  }
std::string m_title
A string holding the description of the title.
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 90 of file progress_indicator_base.h.

References tpie::progress_indicator_base::m_current.

Referenced by tpie::merge_sorter< T, UseProgress, pred_t, store_t >::calc(), tpie::pipelining::serialization_bits::sort_calc_t< Traits >::go(), tpie::progress_indicator_base::raw_step(), tpie::ami::Internal_Sorter_Obj< T, Compare >::sort(), and tpie::pipelining::node::step().

90  {
91  m_current += step;
92 
93  if (step >= m_remainingSteps) {
94  call_refresh();
95  } else {
96  m_remainingSteps -= step;
97  }
98  }
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.

Member Data Documentation

memory_size_type tpie::progress_indicator_arrow::m_indicatorLength
protected

The maximal length of the indicator.

Definition at line 135 of file progress_indicator_arrow.h.

Referenced by progress_indicator_arrow(), refresh(), and set_indicator_length().

std::ostream& tpie::progress_indicator_arrow::m_os
protected

ostream on which to display the progress indicator

Definition at line 141 of file progress_indicator_arrow.h.

stream_size_type tpie::progress_indicator_base::m_range
protectedinherited
std::string tpie::progress_indicator_arrow::m_status
protected

The previously displayed status line.

Definition at line 138 of file progress_indicator_arrow.h.

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

A string holding the description of the title.

Definition at line 159 of file progress_indicator_terminal.h.

Referenced by refresh(), tpie::progress_indicator_terminal::refresh(), and tpie::progress_indicator_terminal::set_title().


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