TPIE

2362a60
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/portability.h>
28 #include <algorithm>
30 #include <tpie/tpie_log.h>
31 
32 namespace tpie {
33 
34 enum description_importance {
35  IMPORTANCE_NONE,
36  IMPORTANCE_LOG,
37  IMPORTANCE_MINOR,
38  IMPORTANCE_MAJOR
39 };
40 
60 
62 public:
67  progress_indicator_base(stream_size_type range);
68 
72  virtual ~progress_indicator_base();
73 
74 
77 
79  progress_indicator_base() = delete;
83  progress_indicator_base & operator=(const progress_indicator_base &) = delete;
84 
85 
86 
90  void step(stream_size_type step=1) {
91  m_current += step;
92 
93  if (step >= m_remainingSteps) {
94  call_refresh();
95  } else {
96  m_remainingSteps -= step;
97  }
98  }
99 
110  void raw_step(stream_size_type step) {
111  m_current += step;
112  // Don't call call_refresh(); call refresh() directly instead.
113  refresh();
114  }
115 
120  virtual void init(stream_size_type range=0) {
121  if (range != 0) set_range(range);
122  m_current = 0;
123  call_refresh();
124  }
125 
129  virtual void done() {}
130 
139  virtual void set_range(stream_size_type range) {
140  m_range = range;
141  }
142 
146  virtual void refresh() = 0;
147 
151  stream_size_type get_current() { return m_current; }
152 
156  stream_size_type get_range() { return m_range; }
157 
158  execution_time_predictor * get_time_predictor() {return m_predictor;}
159  void set_time_predictor(execution_time_predictor * p) {m_predictor = p;}
160 
161  std::string estimated_remaining_time() {
162  if (m_range == 0 || m_predictor == 0) return "";
163  return m_predictor->estimate_remaining_time( double(m_current) / double(m_range) );
164  }
165 
166  virtual void push_breadcrumb(const char *, description_importance) {}
167  virtual void pop_breadcrumb() {}
168 protected:
170  stream_size_type m_range;
171 
173  stream_size_type m_current;
174 
175 private:
176  stream_size_type m_remainingSteps;
177 
178  execution_time_predictor * m_predictor;
179 
181  struct refresh_impl;
183  refresh_impl * m_refreshImpl;
187  void call_refresh();
188 };
189 
190 } // tpie namespace
191 
192 #endif // _TPIE_PROGRESS_INDICATOR_BASE
progress_indicator_base()=delete
Deleted default constructor.
The base class for indicating the progress of some task.
virtual void refresh()=0
Display the indicator.
stream_size_type get_range()
Get the maximum value of the current range.
virtual ~progress_indicator_base()
Destructor.
Execution time predictor used by fractional progress.
virtual void done()
Advance the indicator to the end.
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
This file contains a few deprecated definitions for legacy code.
Logging functionality and log_level codes for different priorities of log messages.
stream_size_type m_range
The upper bound of the counting range.
virtual void set_range(stream_size_type range)
Set the upper bound of the counting range.
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.
stream_size_type get_current()
Get the current value of the step counter.
void raw_step(stream_size_type step)
Internal method used in fractional progress.
virtual void init(stream_size_type range=0)
Initialize progress indicator.