contrib/mul/mbl/mbl_progress_hierarchy.h
Go to the documentation of this file.
00001 #ifndef mbl_progress_hierarchy_h_
00002 #define mbl_progress_hierarchy_h_
00003 //:
00004 // \file
00005 // \brief Assumes a hierarchy in the identifiers and reports a single float score.
00006 // \author Ian Scott
00007 // \date 10 Jan 2008
00008 
00009 #include <vcl_string.h>
00010 #include <vcl_vector.h>
00011 #include <mbl/mbl_progress.h>
00012 
00013 //========================================================================
00014 //: API for reporting a single progress fraction from multiple hierarchical sources.
00015 //
00016 // This progress class assumes that each identifier is arranged in a hierarchy,
00017 // and that calls to set_estimated_iterations and end_progress are correctly nested.
00018 //
00019 // In order to use this abstract you need to derive this class
00020 // and provide a definition of on_changed_progress().
00021 class mbl_progress_hierarchy: public mbl_progress
00022 {
00023  protected:
00024 
00025   //: Called when set_estimate_iterations() is called for a given identifier.
00026   //  Derived classes may take some action here.
00027   //  \param identifier The operation being monitored.
00028   virtual void on_set_estimated_iterations(const vcl_string& identifier,
00029                                            const int total_iterations);
00030 
00031   //: Called when set_progress() is called for a given identifier.
00032   //  Derived classes may take some action here.
00033   //  \param identifier The operation being monitored.
00034   //  \param progress The new progress status.
00035   virtual void on_set_progress(const vcl_string& identifier,
00036                                const int progress);
00037 
00038   //: Called when end_progress() is called for a given identifier.
00039   //  Derived classes may take some action here.
00040   //  \param identifier The operation being monitored.
00041   virtual void on_end_progress(const vcl_string& identifier);
00042 
00043 
00044   //: Called when the progress has started, changed, or finished.
00045   // \param fraction Progress of all identifiers towards the end.
00046   // value is out of 1.0.
00047   virtual void on_changed_progress(double fraction)=0;
00048 
00049   mbl_progress_hierarchy() : just_ended_(false) {}
00050 
00051  private:
00052   //: The ordered hierarchy of identifiers.
00053   vcl_vector<vcl_string> identifier_stack_;
00054 
00055   //: Has an existing identifier just been ended.
00056   bool just_ended_;
00057 };
00058 
00059 //========================================================================
00060 
00061 #endif // mbl_progress_hierarchy_h_