OpenWalnut 1.2.5
WProgress.h
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 #include "WExportCommon.h"
00034 /**
00035  * Class managing progress inside of modules. It interacts with the abstract WGUI 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 WGUI
00040  */
00041 class OWCOMMON_EXPORT WProgress // NOLINT
00042 {
00043 friend class WProgressTest;
00044 public:
00045 
00046     /**
00047      * Creates a new progress instance as child of the specified progress. The instance is instantly marked "running".
00048      *
00049      * \param name   name of the progress, can be empty.
00050      * \param count  value denoting the final value. A value of zero will cause this progress to be indetermined.
00051      *
00052      * \note Reaching the count does not automatically stop the progress. You still need to call finish().
00053      * \note An indetermined progress is just indicating a pending progress without progress information.
00054      */
00055     WProgress( std::string name, unsigned int count = 0 );
00056 
00057     /**
00058      * Destructor.
00059      */
00060     virtual ~WProgress();
00061 
00062     /**
00063      * Stops the progress. After finishing, the progress de-registers from its parent (if any).
00064      */
00065     virtual void finish();
00066 
00067     /**
00068      * Simple increment operator to signal a forward stepping.
00069      *
00070      * \note this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count.
00071      *
00072      * \return the incremented WProgress instance.
00073      */
00074     virtual WProgress& operator++();
00075 
00076     /**
00077      * Increments the operator by the given number of steps to signal forward progress.
00078      *
00079      * \param steps The number of steps to increment
00080      *
00081      * \return the incremented WProgress instance.
00082      */
00083     virtual WProgress& operator+( unsigned int steps );
00084 
00085     /**
00086      * Returns the overall progress of this progress instance, including the child progress'.
00087      *
00088      * \return the progress.
00089      */
00090     virtual float getProgress();
00091 
00092     /**
00093      * Returns true when the operation is pending. After calling finish() this will always return false.
00094      *
00095      * \return true if not finished.
00096      */
00097     virtual bool isPending();
00098 
00099     /**
00100      * Returns the name of the progress.
00101      *
00102      * \return name
00103      */
00104     std::string getName() const;
00105 
00106     /**
00107      * Function updating the internal state. This needs to be called before any get function to ensure the getter return the right
00108      * values.
00109      */
00110     virtual void update();
00111 
00112     /**
00113      * 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
00114      * known end point.
00115      *
00116      * \return false if no end point is known.
00117      */
00118     virtual bool isDetermined();
00119 
00120 protected:
00121 
00122     /**
00123      * Progress name. Can be set only once (during construction).
00124      */
00125     std::string m_name;
00126 
00127     /**
00128      * The maximum count (which marks the 100%).
00129      */
00130     unsigned int m_max;
00131 
00132     /**
00133      * The current counter.
00134      */
00135     unsigned int m_count;
00136 
00137     /**
00138      * Flag denoting whether the progress is running or not.
00139      */
00140     bool m_pending;
00141 
00142     /**
00143      * True if the progress has a known end point.
00144      */
00145     bool m_determined;
00146 
00147 private:
00148 };
00149 
00150 #endif  // WPROGRESS_H
00151 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends