TPIE

11a2c2d
progress_indicator_terminal.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
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_TERMINAL_H
25 #define _TPIE_PROGRESS_INDICATOR_TERMINAL_H
26 
27 #include <tpie/portability.h>
28 
30 
31 namespace tpie {
32 
39 
41 private:
43 
44 public:
53 
54  progress_indicator_terminal(const char * title, stream_size_type range, std::ostream & os = std::cout) :
55  progress_indicator_base(range), m_title(title), m_os(os) {}
56 
57  // ////////////////////////////////////////////////////////////////////
58  // /// Copy-constructor.
59  // ////////////////////////////////////////////////////////////////////
60  // progress_indicator_terminal(const progress_indicator_terminal& other) :
61  // progress_indicator_base(other), m_title("") {
62  // *this = other;
63  // }
64 
65  // ////////////////////////////////////////////////////////////////////
66  // /// Assignment operator.
67  // ////////////////////////////////////////////////////////////////////
68 
69  // progress_indicator_terminal& operator=(const progress_indicator_terminal& other)
70  // {
71  // if (this != &other)
72  // {
73  // progress_indicator_base::operator=(other);
74  // m_title = other.m_title;
75  // m_description = other.m_description;
76  // }
77  // return *this;
78  // }
79 
85 
87  {};
88 
94 
95  void done() {
97  refresh();
98  m_os << std::endl;
99  }
100 
101 
111 
112  void set_title(const std::string& title)
113  {
114  m_title = title;
115  m_os << title << std::endl;
116  }
117 
123 
124  virtual void refresh() {
125  m_os << '\r' << m_title << ' ';
127  m_os << std::flush;
128  }
129 
130 protected:
131 
132 
138 
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  }
153 
155  std::string m_title;
156 
157 private:
162 
163  std::ostream & m_os;
164 };
165 } // tpie namespace
166 
167 #endif // _PROGRESS_INDICATOR_TERMINAL
tpie::progress_indicator_base
The base class for indicating the progress of some task.
Definition: progress_indicator_base.h:62
tpie::progress_indicator_terminal::~progress_indicator_terminal
virtual ~progress_indicator_terminal()
The destructor.
Definition: progress_indicator_terminal.h:86
portability.h
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_terminal::display_percentage
void display_percentage()
Compute and print the percentage or step count.
Definition: progress_indicator_terminal.h:139
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_terminal::m_title
std::string m_title
A string holding the description of the title.
Definition: progress_indicator_terminal.h:155
tpie::progress_indicator_terminal::set_title
void set_title(const std::string &title)
Set the title of a new task to be monitored.
Definition: progress_indicator_terminal.h:112
tpie::progress_indicator_terminal::done
void done()
Advance the indicator to the end.
Definition: progress_indicator_terminal.h:95
progress_indicator_base.h
tpie::progress_indicator_terminal
A class that indicates the progress by a simple counter that is printed to the terminal.
Definition: progress_indicator_terminal.h:40
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
tpie
Definition: access_type.h:26