libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00009 00010 #ifndef ZYPP_ParserProgress_H 00011 #define ZYPP_ParserProgress_H 00012 00013 #include "boost/shared_ptr.hpp" 00014 #include "boost/function.hpp" 00015 00017 namespace zypp 00018 { 00019 namespace parser 00020 { 00021 00022 class ParserProgress 00023 { 00024 public: 00025 typedef boost::shared_ptr<ParserProgress> Ptr; 00026 00033 ParserProgress( boost::function<void (long int)> fnc, long int total_steps = 100 ) 00034 : _fnc(fnc), _previous_progress(0), _total_steps(total_steps) 00035 { 00036 00037 }; 00038 00039 ~ParserProgress() 00040 {}; 00041 00048 void progress(long int p) 00049 { 00050 //std::cout << "real " << p << std::endl; 00051 if ( _total_steps != 100 ) 00052 { 00053 long int current_done = p; 00054 p = (long int)(((double) current_done/(double) _total_steps)*100); 00055 } 00056 00057 if (_fnc && ( p != _previous_progress )) 00058 { 00059 _previous_progress = p; 00060 _fnc(p); 00061 } 00062 } 00063 00064 void setTotalSteps( long int total_steps ) 00065 { 00066 _total_steps = total_steps; 00067 } 00068 00072 void finish() 00073 { 00074 int p = 100; 00075 if (_fnc && ( p != _previous_progress )) 00076 { 00077 _previous_progress = p; 00078 _fnc(p); 00079 } 00080 } 00081 00085 void start() 00086 { 00087 int p = 0; 00088 if (_fnc && ( p != _previous_progress )) 00089 { 00090 _previous_progress = p; 00091 _fnc(p); 00092 } 00093 } 00094 00095 private: 00096 boost::function<void (long int)> _fnc; 00097 long int _previous_progress; 00098 long int _total_steps; 00099 }; 00100 00101 } // namespace parser 00102 } // namespace zypp 00104 #endif // ZYPP_ParserProgress_H