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 |
---|
37 | void printBackSpace(std::ostream &stream, int num); |
---|
38 | void printBackSpace(int num); |
---|
39 | void printSpace(std::ostream &stream, int num); |
---|
40 | void printSpace(int num); |
---|
41 | void printHash(std::ostream &stream, int num); |
---|
42 | void printHash(int num); |
---|
43 | |
---|
44 | /** |
---|
45 | * Controls printing out a progress bar. |
---|
46 | * |
---|
47 | * A class that prints out a progress bar in the form |
---|
48 | * \f$|\#\#\#\ \ \ \ \ \ \ \ \ \ |\f$ |
---|
49 | * that shows how far through a function or loop you are. |
---|
50 | * The length of it defaults to 20 hashes, but can be set when |
---|
51 | * declaring the object. |
---|
52 | * There are five functions: |
---|
53 | * <ul><li>init(int) Prints an empty bar, and defines the increment |
---|
54 | * <li>update(int) Prints the correct number of hashes, but only when |
---|
55 | * num is a multiple of the increment. |
---|
56 | * <li>rewind() Prints backspaces to cover the entire bar. |
---|
57 | * <li>remove() Does a rewind(), then prints spaces to overwrite |
---|
58 | * the bar area -- more clean. |
---|
59 | * <li>fillSpace(std::string) Does a remove(), then writes |
---|
60 | * the string into the same space. |
---|
61 | * </ul> |
---|
62 | */ |
---|
63 | class ProgressBar |
---|
64 | { |
---|
65 | public: |
---|
66 | ProgressBar(); ///< Default Constructor |
---|
67 | ProgressBar(int newlength); ///< Alternative constructor |
---|
68 | virtual ~ProgressBar(); ///< Destructor. |
---|
69 | enum POS {BEG=0,END}; ///< So that we can record |
---|
70 | /// where we are. |
---|
71 | |
---|
72 | void init(int size); ///< Prints empty bar, |
---|
73 | /// defines increment. |
---|
74 | void update(int num); ///< Prints correct number of hashes |
---|
75 | void rewind(); ///< Prints backspaces over bar. |
---|
76 | void remove(); ///< Overwrites bar with blanks |
---|
77 | void fillSpace(std::string someString); ///< Overwrites bar with a string. |
---|
78 | |
---|
79 | private: |
---|
80 | POS loc; ///< Are we at the start or end? |
---|
81 | float stepSize; ///< What is the interval |
---|
82 | /// between hashes? |
---|
83 | int length; ///< What's the maximum |
---|
84 | /// number of hashes? |
---|
85 | int numVisible; ///< How many hashes are |
---|
86 | /// there currently visible? |
---|
87 | }; |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | #endif // FEEDBACK_HH |
---|