include/EDoc/ProgressBar.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 by Brendon Costa
00004 
00005    This library is free software; you can redistribute it and/or modify 
00006    it under the terms of the "LGPL Like" License defined in the file COPYING 
00007    that should have been distributed along with this source.
00008 
00009    This library is distributed in the hope that it will be useful, 
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013    You should have received a copy of the "LGPL Like" License 
00014    along with this library; see the file COPYING. if not, it can be 
00015    obtained from the EDoc++ website: 
00016    http://edoc.sourceforge.net/license.html
00017 
00018 *******************************************************************************/
00019 #ifndef EDOC_PROGRESSBAR_H
00020 #define EDOC_PROGRESSBAR_H
00021 
00022 #include "EDoc/ProgressIFace.h"
00023 #include <string>
00024 
00025 namespace EDoc
00026 {
00027    //===========================================================================
00028    /** \brief Displays a percentage progress bar as a bar of '=' characters
00029     * across the screen.
00030     *
00031     * This has two configurations:
00032     *    -# Interactive
00033     *    -# Non Interactive
00034     *    .
00035     *
00036     * The interactive varient will display a "spinner" in addition to the '='
00037     * characters that updates regulary. This requires a terminal as otherwise
00038     * of exporting output to a file it will contain a number of back-space
00039     * characters.
00040     */
00041    class ProgressBar : public FunctionProgressIFace
00042    {
00043    public:
00044 
00045       //------------------------------------------------------------------------
00046       /** \brief This is the default spin sequence for the spinner.
00047        *
00048        * It is a sequence of characters to display when the progress indication
00049        * increases.
00050        */
00051       static const char* DEFAULT_SPIN_SEQUENCE;
00052 
00053       //------------------------------------------------------------------------
00054       /** \brief This is the default screen width to use.
00055        *
00056        * \todo Find a way of getting the current terminal width so we do not
00057        * make assumptions.
00058        */
00059       static const int DEFAULT_SCREEN_WIDTH = 80;
00060 
00061 
00062 
00063       //------------------------------------------------------------------------
00064       /** \brief Create a new progress bar instance.
00065        *
00066        * \param enable_spinner_in When in iteractive mode this is enabled and
00067        * displays a spinner when any progress is made.
00068        *
00069        * \param width_in The width to assume the terminal width is.
00070        *
00071        * \param spin_sequence_in The spin sequence to use if enable_spinner_in
00072        * is true.
00073        */
00074       ProgressBar(bool enable_spinner_in = false,
00075             int width_in = DEFAULT_SCREEN_WIDTH, 
00076             std::string spin_sequence_in = DEFAULT_SPIN_SEQUENCE);
00077 
00078       //------------------------------------------------------------------------
00079       /** \brief Resets the progress bar to start displaying progress again from
00080        * 0.
00081        */
00082       void Reset();
00083 
00084       //------------------------------------------------------------------------
00085       /** \brief See FunctionProgressIFace::Start()
00086        */
00087       virtual void Start(size_t total);
00088 
00089       //------------------------------------------------------------------------
00090       /** \brief See FunctionProgressIFace::Progress()
00091        */
00092       virtual void Progress(Function* data);
00093 
00094       //------------------------------------------------------------------------
00095 
00096    private:
00097 
00098       //------------------------------------------------------------------------
00099       /** \brief True if spinner is enabled.
00100        */
00101       bool enable_spinner;
00102 
00103       //------------------------------------------------------------------------
00104       /** \brief The width of the terminal to assume.
00105        */
00106       int width;
00107 
00108       //------------------------------------------------------------------------
00109       /** \brief The equence of characters to display when incrementing the
00110        * progres for a spinner.
00111        */
00112       std::string spin_sequence;
00113 
00114       //------------------------------------------------------------------------
00115       /** \brief Current number of bars being displayed.
00116        */
00117       int bars;
00118 
00119       //------------------------------------------------------------------------
00120       /** \brief Current index for the spinner. This determines which character
00121        * to display next from the spin_sequence.
00122        */
00123       int spin_index;
00124 
00125       size_t total;
00126       size_t current;
00127       //------------------------------------------------------------------------
00128    };
00129    //===========================================================================
00130 
00131 }
00132 
00133 #endif // EDOC_PROGRESSBAR_H

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1