TPIE

2362a60
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 
98 
99  void done() {
100  m_current = m_range;
101  refresh();
102  m_os << std::endl;
103  }
104 
105 
115 
116  void set_title(const std::string& title)
117  {
118  m_title = title;
119  m_os << title << std::endl;
120  }
121 
127 
128  virtual void refresh() {
129  m_os << '\r' << m_title << ' ';
131  m_os << std::flush;
132  }
133 
134 protected:
135 
136 
142 
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  }
157 
159  std::string m_title;
160 
161 private:
166 
167  std::ostream & m_os;
168 };
169 } // tpie namespace
170 
171 #endif // _PROGRESS_INDICATOR_TERMINAL
void done()
Advance the indicator to the end and print an (optional) message that is followed by a newline...
The base class for indicating the progress of some task.
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
This file contains a few deprecated definitions for legacy code.
virtual void refresh()
Display the indicator.
void set_title(const std::string &title)
Set the title of a new task to be monitored.
stream_size_type m_range
The upper bound of the counting range.
A class that indicates the progress by a simple counter that is printed to the terminal.
Progress indicator base.
virtual ~progress_indicator_terminal()
The destructor.
std::string m_title
A string holding the description of the title.
void display_percentage()
Compute and print the percentage or step count.
progress_indicator_terminal(const char *title, stream_size_type range, std::ostream &os=std::cout)
Initializes the indicator.