TPIE

11a2c2d
progress_indicator_base.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2008, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
23 
24 #ifndef _TPIE_PROGRESS_INDICATOR_BASE_H
25 #define _TPIE_PROGRESS_INDICATOR_BASE_H
26 
27 #include <tpie/tpie_export.h>
28 #include <tpie/portability.h>
29 #include <algorithm>
31 #include <tpie/tpie_log.h>
32 
33 namespace tpie {
34 
35 enum description_importance {
36  IMPORTANCE_NONE,
37  IMPORTANCE_LOG,
38  IMPORTANCE_MINOR,
39  IMPORTANCE_MAJOR
40 };
41 
61 
62 class TPIE_EXPORT progress_indicator_base {
63 public:
68  progress_indicator_base(stream_size_type range);
69 
73  virtual ~progress_indicator_base();
74 
75 
78 
80  progress_indicator_base() = delete;
84  progress_indicator_base & operator=(const progress_indicator_base &) = delete;
85 
86 
87 
91  void step(stream_size_type step=1) {
92  m_current += step;
93 
94  if (step >= m_remainingSteps) {
95  call_refresh();
96  } else {
97  m_remainingSteps -= step;
98  }
99  }
100 
111  void raw_step(stream_size_type step) {
112  m_current += step;
113  // Don't call call_refresh(); call refresh() directly instead.
114  refresh();
115  }
116 
121  virtual void init(stream_size_type range=0) {
122  if (range != 0) set_range(range);
123  m_current = 0;
124  call_refresh();
125  }
126 
130  virtual void done() {}
131 
140  virtual void set_range(stream_size_type range) {
141  m_range = range;
142  }
143 
147  virtual void refresh() = 0;
148 
152  stream_size_type get_current() { return m_current; }
153 
157  stream_size_type get_range() { return m_range; }
158 
159  execution_time_predictor * get_time_predictor() {return m_predictor;}
160  void set_time_predictor(execution_time_predictor * p) {m_predictor = p;}
161 
162  std::string estimated_remaining_time() {
163  if (m_range == 0 || m_predictor == 0) return "";
164  return m_predictor->estimate_remaining_time( double(m_current) / double(m_range) );
165  }
166 
167  virtual void push_breadcrumb(const char *, description_importance) {}
168  virtual void pop_breadcrumb() {}
169 protected:
171  stream_size_type m_range;
172 
174  stream_size_type m_current;
175 
176 private:
177  stream_size_type m_remainingSteps;
178 
179  execution_time_predictor * m_predictor;
180 
182  struct refresh_impl;
184  refresh_impl * m_refreshImpl;
188  void call_refresh();
189 };
190 
191 } // tpie namespace
192 
193 #endif // _TPIE_PROGRESS_INDICATOR_BASE
tpie::progress_indicator_base
The base class for indicating the progress of some task.
Definition: progress_indicator_base.h:62
portability.h
tpie::progress_indicator_base::get_range
stream_size_type get_range()
Get the maximum value of the current range.
Definition: progress_indicator_base.h:157
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
execution_time_predictor.h
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::execution_time_predictor
Definition: execution_time_predictor.h:66
tpie::progress_indicator_base::init
virtual void init(stream_size_type range=0)
Initialize progress indicator.
Definition: progress_indicator_base.h:121
tpie::progress_indicator_base::raw_step
void raw_step(stream_size_type step)
Internal method used in fractional progress.
Definition: progress_indicator_base.h:111
tpie_log.h
tpie::progress_indicator_base::get_current
stream_size_type get_current()
Get the current value of the step counter.
Definition: progress_indicator_base.h:152
tpie::progress_indicator_base::done
virtual void done()
Advance the indicator to the end.
Definition: progress_indicator_base.h:130
tpie::progress_indicator_base::m_range
stream_size_type m_range
The upper bound of the counting range.
Definition: progress_indicator_base.h:171
tpie
Definition: access_type.h:26