OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPROGRESS_H 00026 #define WPROGRESS_H 00027 00028 #include <set> 00029 #include <string> 00030 00031 #include <boost/shared_ptr.hpp> 00032 00033 00034 /** 00035 * Class managing progress inside of modules. It interacts with the abstract WUI class to present those information to the user. 00036 * At the same time, it also is a simple tree structure, allowing the programmer to arrange complex sub progress. This is 00037 * especially useful if several time-consuming tasks need to be performed. 00038 * 00039 * \see WUI 00040 */ 00041 class WProgress // NOLINT 00042 { 00043 friend class WProgressTest; 00044 public: 00045 /** 00046 * Shared pointer on a WProgress 00047 */ 00048 typedef boost::shared_ptr< WProgress > SPtr; 00049 00050 /** 00051 * Const Shared pointer on a WProgress 00052 */ 00053 typedef boost::shared_ptr< const WProgress > ConstSPtr; 00054 00055 /** 00056 * Creates a new progress instance as child of the specified progress. The instance is instantly marked "running". 00057 * 00058 * \param name name of the progress, can be empty. 00059 * \param count value denoting the final value. A value of zero will cause this progress to be indetermined. 00060 * 00061 * \note Reaching the count does not automatically stop the progress. You still need to call finish(). 00062 * \note An indetermined progress is just indicating a pending progress without progress information. 00063 */ 00064 WProgress( std::string name, size_t count = 0 ); 00065 00066 /** 00067 * Destructor. 00068 */ 00069 virtual ~WProgress(); 00070 00071 /** 00072 * Stops the progress. After finishing, the progress de-registers from its parent (if any). 00073 */ 00074 virtual void finish(); 00075 00076 /** 00077 * Simple increment operator to signal a forward stepping. 00078 * 00079 * \note this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count. 00080 * 00081 * \return the incremented WProgress instance. 00082 */ 00083 virtual WProgress& operator++(); 00084 00085 /** 00086 * Increments the operator by the given number of steps to signal forward progress. 00087 * 00088 * \param steps The number of steps to increment 00089 * 00090 * \return the incremented WProgress instance. 00091 */ 00092 virtual WProgress& operator+( size_t steps ); 00093 00094 /** 00095 * Returns the overall progress of this progress instance, including the child progress'. 00096 * 00097 * \return the progress. 00098 */ 00099 virtual float getProgress(); 00100 00101 /** 00102 * Returns true when the operation is pending. After calling finish() this will always return false. 00103 * 00104 * \return true if not finished. 00105 */ 00106 virtual bool isPending(); 00107 00108 /** 00109 * Returns the name of the progress. 00110 * 00111 * \return name 00112 */ 00113 std::string getName() const; 00114 00115 /** 00116 * Function updating the internal state. This needs to be called before any get function to ensure the getter return the right 00117 * values. 00118 */ 00119 virtual void update(); 00120 00121 /** 00122 * 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 00123 * known end point. 00124 * 00125 * \return false if no end point is known. 00126 */ 00127 virtual bool isDetermined(); 00128 00129 /** 00130 * Increment the progress counter by the given amount. 00131 * 00132 * \param steps how much 00133 */ 00134 virtual void increment( size_t steps ); 00135 00136 protected: 00137 /** 00138 * Progress name. Can be set only once (during construction). 00139 */ 00140 std::string m_name; 00141 00142 /** 00143 * The maximum count (which marks the 100%). 00144 */ 00145 size_t m_max; 00146 00147 /** 00148 * The current counter. 00149 */ 00150 size_t m_count; 00151 00152 /** 00153 * Flag denoting whether the progress is running or not. 00154 */ 00155 bool m_pending; 00156 00157 /** 00158 * True if the progress has a known end point. 00159 */ 00160 bool m_determined; 00161 00162 private: 00163 }; 00164 00165 #endif // WPROGRESS_H 00166