OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #include <boost/shared_ptr.hpp>
32 
33 #include "WExportCommon.h"
34 /**
35  * Class managing progress inside of modules. It interacts with the abstract WGUI 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 WGUI
40  */
41 class OWCOMMON_EXPORT WProgress // NOLINT
42 {
43 friend class WProgressTest;
44 public:
45 
46  /**
47  * Creates a new progress instance as child of the specified progress. The instance is instantly marked "running".
48  *
49  * \param name name of the progress, can be empty.
50  * \param count value denoting the final value. A value of zero will cause this progress to be indetermined.
51  *
52  * \note Reaching the count does not automatically stop the progress. You still need to call finish().
53  * \note An indetermined progress is just indicating a pending progress without progress information.
54  */
55  WProgress( std::string name, unsigned int count = 0 );
56 
57  /**
58  * Destructor.
59  */
60  virtual ~WProgress();
61 
62  /**
63  * Stops the progress. After finishing, the progress de-registers from its parent (if any).
64  */
65  virtual void finish();
66 
67  /**
68  * Simple increment operator to signal a forward stepping.
69  *
70  * \note this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count.
71  *
72  * \return the incremented WProgress instance.
73  */
74  virtual WProgress& operator++();
75 
76  /**
77  * Increments the operator by the given number of steps to signal forward progress.
78  *
79  * \param steps The number of steps to increment
80  *
81  * \return the incremented WProgress instance.
82  */
83  virtual WProgress& operator+( unsigned int steps );
84 
85  /**
86  * Returns the overall progress of this progress instance, including the child progress'.
87  *
88  * \return the progress.
89  */
90  virtual float getProgress();
91 
92  /**
93  * Returns true when the operation is pending. After calling finish() this will always return false.
94  *
95  * \return true if not finished.
96  */
97  virtual bool isPending();
98 
99  /**
100  * Returns the name of the progress.
101  *
102  * \return name
103  */
104  std::string getName() const;
105 
106  /**
107  * Function updating the internal state. This needs to be called before any get function to ensure the getter return the right
108  * values.
109  */
110  virtual void update();
111 
112  /**
113  * 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
114  * known end point.
115  *
116  * \return false if no end point is known.
117  */
118  virtual bool isDetermined();
119 
120 protected:
121 
122  /**
123  * Progress name. Can be set only once (during construction).
124  */
125  std::string m_name;
126 
127  /**
128  * The maximum count (which marks the 100%).
129  */
130  unsigned int m_max;
131 
132  /**
133  * The current counter.
134  */
135  unsigned int m_count;
136 
137  /**
138  * Flag denoting whether the progress is running or not.
139  */
140  bool m_pending;
141 
142  /**
143  * True if the progress has a known end point.
144  */
146 
147 private:
148 };
149 
150 #endif // WPROGRESS_H
151