1 //:
2 // \file
3 // \brief Progress class that outputs elapsed time reporting on progress
4 // \author Kevin de Souza
5 // \date 26 June 2008
6 
7 #include <iostream>
8 #include <ios>
9 #include "mbl_progress_time.h"
10 #ifdef _MSC_VER
11 #  include "vcl_msvc_warnings.h"
12 #endif
13 
14 
15 //========================================================================
16 // Constructor
17 //========================================================================
mbl_progress_time(std::ostream & os)18 mbl_progress_time::mbl_progress_time(std::ostream& os/*=std::cout*/)
19 : os_(os), ios_state_(os_)
20 {
21   os_.precision(3);
22   os_.setf(std::ios::fixed, std::ios::floatfield);
23 }
24 
25 
26 //========================================================================
27 // Destructor
28 //========================================================================
29 mbl_progress_time::~mbl_progress_time() = default;
30 
31 
32 //========================================================================
33 // Name of the class
34 //========================================================================
is_a() const35 std::string mbl_progress_time::is_a() const
36 {
37   return "mbl_progress_time";
38 }
39 
40 
41 //========================================================================
42 // Called when set_estimate_iterations() is called for a given identifier.
43 //========================================================================
on_set_estimated_iterations(const std::string & identifier,const int)44 void mbl_progress_time::on_set_estimated_iterations(const std::string& identifier,
45                                                     const int /*total_iterations*/)
46 {
47   os_ << "Starting mbl_progress_time \"" << identifier << "\"" << std::endl;
48   timer_.mark();
49 }
50 
51 
52 //========================================================================
53 // Called when set_progress() is called for a given identifier.
54 //========================================================================
on_set_progress(const std::string & identifier,const int)55 void mbl_progress_time::on_set_progress(const std::string& identifier,
56                                         const int  /*progress*/)
57 {
58   double tsec = timer_.real()/1000.0;
59   os_ << "Elapsed time for mbl_progress_time \"" << identifier << "\": " << tsec << " s" << std::endl;
60 }
61 
62 
63 //========================================================================
64 // Called when end_progress() is called for a given identifier.
65 //========================================================================
on_end_progress(const std::string & identifier)66 void mbl_progress_time::on_end_progress(const std::string &identifier)
67 {
68   double tsec = timer_.real()/1000.0;
69   os_ << "Finishing mbl_progress_time \"" << identifier << "\" (total elapsed time: " << tsec << " s)" << std::endl;
70 }
71