libzypp 17.35.9
ParserProgress.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#ifndef ZYPP_ParserProgress_H
11#define ZYPP_ParserProgress_H
12
13#include <boost/shared_ptr.hpp>
14#include <boost/function.hpp>
15#include <utility>
16
18namespace zypp
19{
20namespace parser
21{
22
24 {
25 public:
26 using Ptr = boost::shared_ptr<ParserProgress>;
27
34 ParserProgress( boost::function<void (long int)> fnc, long int total_steps = 100 )
35 : _fnc(std::move(fnc)), _previous_progress(0), _total_steps(total_steps)
36 {
37
38 };
39
42
49 void progress(long int p)
50 {
51 //std::cout << "real " << p << std::endl;
52 if ( _total_steps != 100 )
53 {
54 long int current_done = p;
55 p = (long int)(((double) current_done/(double) _total_steps)*100);
56 }
57
58 if (_fnc && ( p != _previous_progress ))
59 {
61 _fnc(p);
62 }
63 }
64
65 void setTotalSteps( long int total_steps )
66 {
67 _total_steps = total_steps;
68 }
69
73 void finish()
74 {
75 int p = 100;
76 if (_fnc && ( p != _previous_progress ))
77 {
79 _fnc(p);
80 }
81 }
82
86 void start()
87 {
88 int p = 0;
89 if (_fnc && ( p != _previous_progress ))
90 {
92 _fnc(p);
93 }
94 }
95
96 private:
97 boost::function<void (long int)> _fnc;
99 long int _total_steps;
100 };
101
102} // namespace parser
103} // namespace zypp
105#endif // ZYPP_ParserProgress_H
boost::function< void(long int)> _fnc
boost::shared_ptr< ParserProgress > Ptr
ParserProgress(boost::function< void(long int)> fnc, long int total_steps=100)
initializes a progress objetc, with a callback functor if you are not reporting percentage,...
void setTotalSteps(long int total_steps)
void start()
report progress started
void progress(long int p)
report progress, which in most cases executes the functor associated with this progress object to upd...
void finish()
report progress finished
Definition Arch.h:364
Easy-to use interface to the ZYPP dependency resolver.