source: tags/release-1.1.1/src/Utils/feedback.hh @ 1323

Last change on this file since 1323 was 301, checked in by Matthew Whiting, 17 years ago

Mostly adding the distribution text to the start of files, with a few additional comments added too.

File size: 3.8 KB
Line 
1// -----------------------------------------------------------------------
2// feedback.hh: Definition of the ProgressBar class, used to indicate
3//              progress through a lengthy iteration.
4// -----------------------------------------------------------------------
5// Copyright (C) 2006, Matthew Whiting, ATNF
6//
7// This program is free software; you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2 of the License, or (at your
10// option) any later version.
11//
12// Duchamp is distributed in the hope that it will be useful, but WITHOUT
13// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15// for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Duchamp; if not, write to the Free Software Foundation,
19// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20//
21// Correspondence concerning Duchamp may be directed to:
22//    Internet email: Matthew.Whiting [at] atnf.csiro.au
23//    Postal address: Dr. Matthew Whiting
24//                    Australia Telescope National Facility, CSIRO
25//                    PO Box 76
26//                    Epping NSW 1710
27//                    AUSTRALIA
28// -----------------------------------------------------------------------
29#ifndef FEEDBACK_HH
30#define FEEDBACK_HH
31
32#include <iostream>
33#include <string>
34
35// Simple functions to print a given number of backspaces or spaces
36//  to std::cout
37inline void printBackSpace(int num){for(int i=0;i<num;i++) std::cout << '\b';};
38inline void printSpace(int num){ for(int i=0;i<num;i++) std::cout << ' '; };
39inline void printHash(int num){ for(int i=0;i<num;i++) std::cout << '#'; };
40
41/**
42 *  Controls printing out a progress bar.
43 *
44 *   A class that prints out a progress bar in the form
45 *    \f$|\#\#\#\ \ \ \ \ \ \ \ \ \ |\f$
46 *    that shows how far through a function or loop you are.
47 *   The length of it defaults to 20 hashes, but can be set when
48 *   declaring the object.
49 *   There are five functions:
50 *    <ul><li>init(int)   Prints an empty bar, and defines the increment
51 *        <li>update(int) Prints the correct number of #s, but only when
52 *                         num is a multiple of the increment.
53 *        <li>rewind()    Prints backspaces to cover the entire bar.
54 *        <li>remove()    Does a rewind(), then prints spaces to overwrite
55 *                         the bar area -- more clean.
56 *        <li>fillSpace(std::string) Does a remove(), then writes
57 *                                    the string into the same space.
58 * </ul>
59 */
60class ProgressBar
61{
62public:
63  ProgressBar();                          ///< Default Constructor
64  ProgressBar(int newlength);             ///< Alternative constructor
65  virtual ~ProgressBar();                 ///< Destructor.
66  enum POS {BEG=0,END};                   ///< So that we can record
67                                          ///   where we are.
68
69  void init(int size);                    ///< Prints empty bar,
70                                          ///   defines increment.
71  void update(int num);                   ///< Prints correct number of hashes
72  void rewind();                          ///< Prints backspaces over bar.
73  void remove();                          ///< Overwrites bar with blanks
74  void fillSpace(std::string someString); ///< Overwrites bar with a string.
75
76private:
77  POS loc;                                ///< Are we at the start or end?
78  float stepSize;                         ///< What is the interval
79                                          ///   between hashes?
80  int length;                             ///< What's the maximum
81                                          ///   number of hashes?
82  int numVisible;                         ///< How many hashes are
83                                          ///   there currently visible?
84};
85
86
87
88#endif // FEEDBACK_HH
Note: See TracBrowser for help on using the repository browser.