00001 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00002 #pragma implementation 00003 #endif 00004 //: 00005 // \file 00006 // \brief Progress class that outputs elapsed time reporting on progress 00007 // \author Kevin de Souza 00008 // \date 26 June 2008 00009 00010 #include "mbl_progress_time.h" 00011 #include <vcl_ios.h> 00012 00013 00014 //======================================================================== 00015 // Constructor 00016 //======================================================================== 00017 mbl_progress_time::mbl_progress_time(vcl_ostream& os/*=vcl_cout*/) 00018 : os_(os), ios_state_(os_) 00019 { 00020 os_.precision(3); 00021 os_.setf(vcl_ios_fixed, vcl_ios_floatfield); 00022 } 00023 00024 00025 //======================================================================== 00026 // Destructor 00027 //======================================================================== 00028 mbl_progress_time::~mbl_progress_time() 00029 { 00030 } 00031 00032 00033 //======================================================================== 00034 // Name of the class 00035 //======================================================================== 00036 vcl_string mbl_progress_time::is_a() const 00037 { 00038 return "mbl_progress_time"; 00039 } 00040 00041 00042 //======================================================================== 00043 // Called when set_estimate_iterations() is called for a given identifier. 00044 //======================================================================== 00045 void mbl_progress_time::on_set_estimated_iterations(const vcl_string& identifier, 00046 const int /*total_iterations*/) 00047 { 00048 os_ << "Starting mbl_progress_time \"" << identifier << "\"" << vcl_endl; 00049 timer_.mark(); 00050 } 00051 00052 00053 //======================================================================== 00054 // Called when set_progress() is called for a given identifier. 00055 //======================================================================== 00056 void mbl_progress_time::on_set_progress(const vcl_string& identifier, 00057 const int progress) 00058 { 00059 double tsec = timer_.real()/1000.0; 00060 os_ << "Elapsed time for mbl_progress_time \"" << identifier << "\": " << tsec << " s" << vcl_endl; 00061 } 00062 00063 00064 //======================================================================== 00065 // Called when end_progress() is called for a given identifier. 00066 //======================================================================== 00067 void mbl_progress_time::on_end_progress(const vcl_string &identifier) 00068 { 00069 double tsec = timer_.real()/1000.0; 00070 os_ << "Finishing mbl_progress_time \"" << identifier << "\" (total elapsed time: " << tsec << " s)" << vcl_endl; 00071 }