[301] | 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 | // ----------------------------------------------------------------------- |
---|
[213] | 29 | #ifndef FEEDBACK_HH |
---|
| 30 | #define FEEDBACK_HH |
---|
| 31 | |
---|
| 32 | #include <iostream> |
---|
| 33 | #include <string> |
---|
| 34 | |
---|
[258] | 35 | // Simple functions to print a given number of backspaces or spaces |
---|
[213] | 36 | // to std::cout |
---|
[368] | 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); |
---|
[220] | 43 | |
---|
[528] | 44 | /// @brief |
---|
| 45 | /// Controls printing out a progress bar. |
---|
| 46 | /// @details |
---|
| 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 | |
---|
[213] | 63 | class ProgressBar |
---|
| 64 | { |
---|
| 65 | public: |
---|
[220] | 66 | ProgressBar(); ///< Default Constructor |
---|
| 67 | ProgressBar(int newlength); ///< Alternative constructor |
---|
| 68 | virtual ~ProgressBar(); ///< Destructor. |
---|
[528] | 69 | enum POS {BEG=0,END}; ///< So that we can record where we are. |
---|
[213] | 70 | |
---|
[528] | 71 | void init(int size); ///< Prints empty bar, defines increment. |
---|
[220] | 72 | void update(int num); ///< Prints correct number of hashes |
---|
| 73 | void rewind(); ///< Prints backspaces over bar. |
---|
| 74 | void remove(); ///< Overwrites bar with blanks |
---|
| 75 | void fillSpace(std::string someString); ///< Overwrites bar with a string. |
---|
| 76 | |
---|
[213] | 77 | private: |
---|
[220] | 78 | POS loc; ///< Are we at the start or end? |
---|
[528] | 79 | float stepSize; ///< What is the interval between hashes? |
---|
| 80 | int length; ///< What's the maximum number of hashes? |
---|
| 81 | int numVisible; ///< How many hashes are there currently visible? |
---|
[213] | 82 | }; |
---|
| 83 | |
---|
[220] | 84 | |
---|
| 85 | |
---|
[213] | 86 | #endif // FEEDBACK_HH |
---|