presage  0.9.2~beta
progress.h
Go to the documentation of this file.
1 
2 /******************************************************
3  * Presage, an extensible predictive text entry system
4  * ---------------------------------------------------
5  *
6  * Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  **********(*)*/
23 
24 
25 #ifndef PROGRESS_H
26 #define PROGRESS_H
27 
28 #include <iostream>
29 
30 template <class _charT, class _Traits=std::char_traits<_charT> >
31 class ProgressBar {
32 
33 private:
34  int progress;
35  int quantum;
36  std::basic_ostream<_charT,_Traits>& outstream;
37 
38 public:
39  ProgressBar(std::basic_ostream<_charT,_Traits>& ostr = std::cout) : outstream(ostr)
40  {
41  progress = 0;
42  quantum = 2;
43  outstream << "0---10---20---30---40---50---60---70---80---90--100" << std::endl;
44  }
45 
47  {
48  for (int i = progress; i <= 100; i += quantum) {
49  outstream << '#';
50  }
52  }
53 
54  void update(const double percentage)
55  {
56  if ((percentage*100) >= progress) {
57  progress += quantum;
58  outstream << '#' << std::flush;
59  }
60  }
61 
62 };
63 
64 #endif
65 
~ProgressBar()
Definition: progress.h:46
void update(const double percentage)
Definition: progress.h:54
int quantum
Definition: progress.h:35
ProgressBar(std::basic_ostream< _charT, _Traits > &ostr=std::cout)
Definition: progress.h:39
std::basic_ostream< _charT, _Traits > & outstream
Definition: progress.h:36
int progress
Definition: progress.h:34
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)
Definition: logger.h:278