ProgressReporterOld.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #include <cmath>
00025 
00026 #include "ProgressReporterOld.h"
00027 
00028 
00029 namespace AppBase {
00030 
00031     
00032 ProgressReporter::ProgressReporter(double maxProgress) 
00033   : m_progress(0), m_maxProgress(maxProgress)
00034 {    
00035 }
00036 
00037 
00038 
00039 
00041 ProgressReporterAdaptor::ProgressReporterAdaptor(ProgressDisplay& myProgressDisplay, const double& maxProgress)
00042   : ProgressReporter(maxProgress), o_progressDisplay(myProgressDisplay)
00043 {
00044     o_progressDisplay.startSubtask(maxProgress);
00045     o_progressDisplay.startSubtask("", 0.0, 0.0, false);
00046 };
00047 
00048 
00050 ProgressReporterAdaptor::~ProgressReporterAdaptor()
00051 {
00052     o_progressDisplay.finishSubtask();
00053     o_progressDisplay.finishSubtask();
00054 };
00055 
00056 
00058 bool ProgressReporterAdaptor::increaseProgress(double delta)
00059 {
00060     std::string msg = o_progressDisplay.getSubtaskMessage();
00061     o_progressDisplay.finishSubtask();
00062     o_progressDisplay.increaseSubtaskProgressBy(delta);
00063     o_progressDisplay.startSubtask(msg, 0.0, 0.0, false);
00064     
00065     return !o_progressDisplay.wasCancelled();
00066 }
00067 
00068 
00070 void ProgressReporterAdaptor::setMessage(const std::string & msg)
00071 {
00072     o_progressDisplay.setSubtaskMessage(msg);
00073 }
00074 
00075 
00076 ProgressReporter* ProgressReporterAdaptor::newProgressReporter(ProgressDisplay* myProgressDisplay, const double& maxProgress)
00077 {
00078     if(myProgressDisplay != NULL)
00079         return new ProgressReporterAdaptor(*myProgressDisplay, maxProgress);
00080     else
00081         return new DummyProgressReporter(maxProgress);
00082 }
00083 
00084     
00085 
00086 
00087 
00088 StreamProgressReporter::StreamProgressReporter(double maxProgress, std::ostream & out)
00089 : ProgressReporter(maxProgress), m_stream(out)
00090 {
00091     
00092 }
00093 
00094 StreamProgressReporter::~StreamProgressReporter()
00095 {
00096     m_stream << "\r" << std::flush;
00097 }
00098 
00099 
00100 bool StreamProgressReporter::increaseProgress(double delta) 
00101 {
00102     m_progress += delta;
00103     print();
00104     // check for Ctrl-C ?
00105     return true;
00106 }
00107 
00108 
00109 bool StreamProgressReporter::increaseProgress(double delta, const std::string & msg) 
00110 {
00111     m_message = msg;
00112     m_progress += delta;
00113     print();
00114     // check for Ctrl-C ?
00115     return true;
00116 }
00117 
00118 
00119 void StreamProgressReporter::setMessage(const std::string & msg)
00120 {
00121     m_message = msg;
00122     print();
00123 }
00124 
00125 
00126 void StreamProgressReporter::print()
00127 {
00128     double prog = floor(m_progress/m_maxProgress*100);
00129     if (prog > 100) prog = 100;
00130     m_stream << "\r" << m_message << ": " << prog << "%" << std::flush;
00131 }
00132 
00133 
00134 } //namespace
00135 

Generated on Wed Aug 20 01:25:38 2014 for Hugintrunk by  doxygen 1.3.9.1