TPIE

2362a60
progress_indicator_spin.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_SPIN_H
25 #define _TPIE_PROGRESS_INDICATOR_SPIN_H
26 
27 #include <tpie/portability.h>
28 #include <string.h>
29 #include <algorithm>
30 
32 
33 namespace tpie {
34 
40 
42 
43  public:
44 
57 
58  progress_indicator_spin(const std::string& title,
59  const std::string& description,
60  stream_size_type minRange,
61  stream_size_type maxRange,
62  stream_size_type stepValue) :
63  progress_indicator_terminal(title, description, minRange, maxRange, stepValue), m_symbols(NULL), m_numberOfStates(0), m_state(0) {
64  m_numberOfStates = 4;
65  m_symbols = new char[m_numberOfStates+2];
66  m_symbols[0] = '|';
67  m_symbols[1] = '/';
68  m_symbols[2] = '-';
69  m_symbols[3] = '\\';
70  m_symbols[4] = 'X';
71  m_symbols[5] = '\0';
72  }
73 
77 
80  *this = other;
81  }
82 
86 
88  if (this != &other) {
89 
90  progress_indicator_terminal::operator=(other);
91 
93  m_state = other.m_state;
94 
95  delete[] m_symbols;
96 
97  m_symbols = new char[m_numberOfStates+2];
98  memcpy(m_symbols, other.m_symbols, m_numberOfStates+2);
99  }
100  return *this;
101  }
102 
108 
110  delete [] m_symbols;
111  };
112 
118 
119  virtual void refresh() {
121 
122  // Use the last symbol for indicating "done".
123  if (m_current == m_maxRange) m_state = m_numberOfStates;
124 
125  // Go to the beginning of the line and print the description.
126  std::cout << "\r" << m_description << " " << m_symbols[m_state] << std::flush;
127  }
128 
129  protected:
130 
132  char* m_symbols;
133 
135  unsigned short m_numberOfStates;
136 
138  unsigned short m_state;
139 
140  private:
142  };
143 
144 } // tpie namespace
145 
146 #endif // _TPIE_PROGRESS_INDICATOR_SPIN_H
A class that indicates the progress by a spinning cross.
stream_size_type m_current
The current progress count [m_minRange...m_maxRange].
This file contains a few deprecated definitions for legacy code.
progress_indicator_spin(const progress_indicator_spin &other)
Copy-constructor.
A class that indicates the progress by a simple counter that is printed to the terminal.
progress_indicator_spin & operator=(const progress_indicator_spin &other)
Assignment operator.
virtual ~progress_indicator_spin()
The destructor.
unsigned short m_numberOfStates
The number of characters used for the spinning indicator.
virtual void refresh()
Display the indicator.
Indicate progress by a simple counter.
unsigned short m_state
The current character used for the spinning indicator.
char * m_symbols
The characters used for the spinning indicator.
progress_indicator_spin(const std::string &title, const std::string &description, stream_size_type minRange, stream_size_type maxRange, stream_size_type stepValue)
Initializes the indicator.