presage  0.8.7
progress.h
Go to the documentation of this file.
00001 
00002 /******************************************************
00003  *  Presage, an extensible predictive text entry system
00004  *  ---------------------------------------------------
00005  *
00006  *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License along
00019     with this program; if not, write to the Free Software Foundation, Inc.,
00020     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021     *
00022     **********(*)*/
00023 
00024 
00025 #ifndef PROGRESS_H
00026 #define PROGRESS_H
00027 
00028 #include <iostream>
00029 
00030 template <class _charT, class _Traits=std::char_traits<_charT> >
00031 class ProgressBar {
00032     
00033 private:
00034     int progress;
00035     int quantum;
00036     std::basic_ostream<_charT,_Traits>&  outstream;
00037     
00038 public:
00039     ProgressBar(std::basic_ostream<_charT,_Traits>& ostr = std::cout) : outstream(ostr)
00040         {
00041             progress = 0;
00042             quantum = 2;
00043             outstream << "0---10---20---30---40---50---60---70---80---90--100" << std::endl;
00044         }
00045     
00046     ~ProgressBar()
00047         {
00048             for (int i = progress; i <= 100; i += quantum) {
00049                 outstream << '#';
00050             }
00051             outstream << std::endl;
00052         }
00053 
00054     void update(const double percentage)
00055         {
00056             if ((percentage*100) >= progress) {
00057                 progress += quantum;
00058                 outstream << '#' << std::flush;
00059             }
00060         }
00061 
00062 };
00063 
00064 #endif
00065