OpenWalnut  1.4.0
WProgress.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROGRESS_H
26 #define WPROGRESS_H
27 
28 #include <set>
29 #include <string>
30 
31 #ifndef Q_MOC_RUN
32 #include <boost/shared_ptr.hpp>
33 #endif
34 
35 
36 /**
37  * Class managing progress inside of modules. It interacts with the abstract WUI class to present those information to the user.
38  * At the same time, it also is a simple tree structure, allowing the programmer to arrange complex sub progress. This is
39  * especially useful if several time-consuming tasks need to be performed.
40  *
41  * \see WUI
42  */
43 class WProgress // NOLINT
44 {
45 friend class WProgressTest;
46 public:
47  /**
48  * Shared pointer on a WProgress
49  */
50  typedef boost::shared_ptr< WProgress > SPtr;
51 
52  /**
53  * Const Shared pointer on a WProgress
54  */
55  typedef boost::shared_ptr< const WProgress > ConstSPtr;
56 
57  /**
58  * Creates a new progress instance as child of the specified progress. The instance is instantly marked "running".
59  *
60  * \param name name of the progress, can be empty.
61  * \param count value denoting the final value. A value of zero will cause this progress to be indetermined.
62  *
63  * \note Reaching the count does not automatically stop the progress. You still need to call finish().
64  * \note An indetermined progress is just indicating a pending progress without progress information.
65  */
66  WProgress( std::string name, size_t count = 0 );
67 
68  /**
69  * Destructor.
70  */
71  virtual ~WProgress();
72 
73  /**
74  * Stops the progress. After finishing, the progress de-registers from its parent (if any).
75  */
76  virtual void finish();
77 
78  /**
79  * Simple increment operator to signal a forward stepping.
80  *
81  * \note this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count.
82  *
83  * \return the incremented WProgress instance.
84  */
85  virtual WProgress& operator++();
86 
87  /**
88  * Increments the operator by the given number of steps to signal forward progress.
89  *
90  * \param steps The number of steps to increment
91  *
92  * \return the incremented WProgress instance.
93  */
94  virtual WProgress& operator+( size_t steps );
95 
96  /**
97  * Returns the overall progress of this progress instance, including the child progress'.
98  *
99  * \return the progress.
100  */
101  virtual float getProgress();
102 
103  /**
104  * Returns true when the operation is pending. After calling finish() this will always return false.
105  *
106  * \return true if not finished.
107  */
108  virtual bool isPending();
109 
110  /**
111  * Returns the name of the progress.
112  *
113  * \return name
114  */
115  std::string getName() const;
116 
117  /**
118  * Function updating the internal state. This needs to be called before any get function to ensure the getter return the right
119  * values.
120  */
121  virtual void update();
122 
123  /**
124  * Returns true whenever the progress has a known end. If this instance has m_max==0 then this will be false, as there is no
125  * known end point.
126  *
127  * \return false if no end point is known.
128  */
129  virtual bool isDetermined();
130 
131  /**
132  * Increment the progress counter by the given amount.
133  *
134  * \param steps how much
135  */
136  virtual void increment( size_t steps );
137 
138 protected:
139  /**
140  * Progress name. Can be set only once (during construction).
141  */
142  std::string m_name;
143 
144  /**
145  * The maximum count (which marks the 100%).
146  */
147  size_t m_max;
148 
149  /**
150  * The current counter.
151  */
152  size_t m_count;
153 
154  /**
155  * Flag denoting whether the progress is running or not.
156  */
157  bool m_pending;
158 
159  /**
160  * True if the progress has a known end point.
161  */
163 
164 private:
165 };
166 
167 #endif // WPROGRESS_H
168 
std::string m_name
Progress name.
Definition: WProgress.h:142
virtual WProgress & operator+(size_t steps)
Increments the operator by the given number of steps to signal forward progress.
Definition: WProgress.cpp:88
Class managing progress inside of modules.
Definition: WProgress.h:43
virtual float getProgress()
Returns the overall progress of this progress instance, including the child progress'.
Definition: WProgress.cpp:68
boost::shared_ptr< const WProgress > ConstSPtr
Const Shared pointer on a WProgress.
Definition: WProgress.h:55
Test Class for the base progress class.
virtual void update()
Function updating the internal state.
Definition: WProgress.cpp:52
size_t m_count
The current counter.
Definition: WProgress.h:152
virtual ~WProgress()
Destructor.
Definition: WProgress.cpp:47
virtual bool isDetermined()
Returns true whenever the progress has a known end.
Definition: WProgress.cpp:83
bool m_pending
Flag denoting whether the progress is running or not.
Definition: WProgress.h:157
virtual void finish()
Stops the progress.
Definition: WProgress.cpp:57
virtual void increment(size_t steps)
Increment the progress counter by the given amount.
Definition: WProgress.cpp:98
std::string getName() const
Returns the name of the progress.
Definition: WProgress.cpp:78
virtual bool isPending()
Returns true when the operation is pending.
Definition: WProgress.cpp:73
WProgress(std::string name, size_t count=0)
Creates a new progress instance as child of the specified progress.
Definition: WProgress.cpp:33
bool m_determined
True if the progress has a known end point.
Definition: WProgress.h:162
virtual WProgress & operator++()
Simple increment operator to signal a forward stepping.
Definition: WProgress.cpp:63
boost::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:50
size_t m_max
The maximum count (which marks the 100%).
Definition: WProgress.h:147