OpenWalnut  1.5.0dev
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 <memory>
29 #include <set>
30 #include <string>
31 
32 
33 
34 /**
35  * Class managing progress inside of modules. It interacts with the abstract WUI class to present those information to the user.
36  * At the same time, it also is a simple tree structure, allowing the programmer to arrange complex sub progress. This is
37  * especially useful if several time-consuming tasks need to be performed.
38  *
39  * \see WUI
40  */
41 class WProgress // NOLINT
42 {
43 friend class WProgressTest; //!< Access for test class.
44 public:
45  /**
46  * Shared pointer on a WProgress
47  */
48  typedef std::shared_ptr< WProgress > SPtr;
49 
50  /**
51  * Const Shared pointer on a WProgress
52  */
53  typedef std::shared_ptr< const WProgress > ConstSPtr;
54 
55  /**
56  * Creates a new progress instance as child of the specified progress. The instance is instantly marked "running".
57  *
58  * \param name name of the progress, can be empty.
59  * \param count value denoting the final value. A value of zero will cause this progress to be indetermined.
60  *
61  * \note Reaching the count does not automatically stop the progress. You still need to call finish().
62  * \note An indetermined progress is just indicating a pending progress without progress information.
63  */
64  WProgress( std::string name, size_t count = 0 );
65 
66  /**
67  * Destructor.
68  */
69  virtual ~WProgress();
70 
71  /**
72  * Stops the progress. After finishing, the progress de-registers from its parent (if any).
73  */
74  virtual void finish();
75 
76  /**
77  * Simple increment operator to signal a forward stepping.
78  *
79  * \note this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count.
80  *
81  * \return the incremented WProgress instance.
82  */
83  virtual WProgress& operator++();
84 
85  /**
86  * Increments the operator by the given number of steps to signal forward progress.
87  *
88  * \param steps The number of steps to increment
89  *
90  * \return the incremented WProgress instance.
91  */
92  virtual WProgress& operator+( size_t steps );
93 
94  /**
95  * Returns the overall progress of this progress instance, including the child progress'.
96  *
97  * \return the progress.
98  */
99  virtual float getProgress();
100 
101  /**
102  * Returns true when the operation is pending. After calling finish() this will always return false.
103  *
104  * \return true if not finished.
105  */
106  virtual bool isPending();
107 
108  /**
109  * Returns the name of the progress.
110  *
111  * \return name
112  */
113  std::string getName() const;
114 
115  /**
116  * Function updating the internal state. This needs to be called before any get function to ensure the getter return the right
117  * values.
118  */
119  virtual void update();
120 
121  /**
122  * 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
123  * known end point.
124  *
125  * \return false if no end point is known.
126  */
127  virtual bool isDetermined();
128 
129  /**
130  * Increment the progress counter by the given amount.
131  *
132  * \param steps how much
133  */
134  virtual void increment( size_t steps );
135 
136 protected:
137  /**
138  * Progress name. Can be set only once (during construction).
139  */
140  std::string m_name;
141 
142  /**
143  * The maximum count (which marks the 100%).
144  */
145  size_t m_max;
146 
147  /**
148  * The current counter.
149  */
150  size_t m_count;
151 
152  /**
153  * Flag denoting whether the progress is running or not.
154  */
155  bool m_pending;
156 
157  /**
158  * True if the progress has a known end point.
159  */
161 
162 private:
163 };
164 
165 #endif // WPROGRESS_H
166 
Test Class for the base progress class.
Class managing progress inside of modules.
Definition: WProgress.h:42
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:48
std::shared_ptr< const WProgress > ConstSPtr
Const Shared pointer on a WProgress.
Definition: WProgress.h:53
virtual void finish()
Stops the progress.
Definition: WProgress.cpp:57
bool m_pending
Flag denoting whether the progress is running or not.
Definition: WProgress.h:155
size_t m_count
The current counter.
Definition: WProgress.h:150
virtual bool isPending()
Returns true when the operation is pending.
Definition: WProgress.cpp:73
bool m_determined
True if the progress has a known end point.
Definition: WProgress.h:160
virtual ~WProgress()
Destructor.
Definition: WProgress.cpp:47
virtual bool isDetermined()
Returns true whenever the progress has a known end.
Definition: WProgress.cpp:83
size_t m_max
The maximum count (which marks the 100%).
Definition: WProgress.h:145
virtual void increment(size_t steps)
Increment the progress counter by the given amount.
Definition: WProgress.cpp:98
std::string m_name
Progress name.
Definition: WProgress.h:140
virtual float getProgress()
Returns the overall progress of this progress instance, including the child progress'.
Definition: WProgress.cpp:68
virtual void update()
Function updating the internal state.
Definition: WProgress.cpp:52
WProgress(std::string name, size_t count=0)
Creates a new progress instance as child of the specified progress.
Definition: WProgress.cpp:33
virtual WProgress & operator+(size_t steps)
Increments the operator by the given number of steps to signal forward progress.
Definition: WProgress.cpp:88
std::string getName() const
Returns the name of the progress.
Definition: WProgress.cpp:78
virtual WProgress & operator++()
Simple increment operator to signal a forward stepping.
Definition: WProgress.cpp:63