OpenWalnut
1.2.5
|
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 WPROGRESSCOMBINER_H 00026 #define WPROGRESSCOMBINER_H 00027 00028 #include <set> 00029 #include <string> 00030 00031 #include <boost/thread.hpp> 00032 00033 #include "WProgress.h" 00034 #include "WExportCommon.h" 00035 00036 /** 00037 * Base class for all kinds of progress combinations. You might want to derive from this class to implement some special progress 00038 * combination. 00039 */ 00040 class OWCOMMON_EXPORT WProgressCombiner: public WProgress 00041 { 00042 friend class WProgressCombinerTest; 00043 public: 00044 00045 /** 00046 * Default constructor. It creates a empty combiner. 00047 * 00048 * \param name the (optional) name of this progress. 00049 */ 00050 explicit WProgressCombiner( std::string name = "" ); 00051 00052 /** 00053 * Destructor. 00054 */ 00055 virtual ~WProgressCombiner(); 00056 00057 /** 00058 * Stops the progress. Progress combiner propagate this request to their children. Please not that this operation is 00059 * expansive. It locks the updateLock and removes all child progress. 00060 */ 00061 virtual void finish(); 00062 00063 /** 00064 * Simple increment operator to signal a forward stepping. 00065 * 00066 * \note this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count. 00067 * 00068 * \return the incremented WProgress instance. 00069 */ 00070 virtual WProgressCombiner& operator++(); 00071 00072 /** 00073 * Returns the overall progress of this progress instance, including the child progress'. 00074 * 00075 * \return the progress. 00076 */ 00077 virtual float getProgress(); 00078 00079 /** 00080 * Adds a new progress to this combiner. It does not check whether the specified progress already is associated with another 00081 * combiner, which allows some kind of "shared" progress. The progress stays in the progress list until finish() is called, 00082 * which actually cleans up and resets a combiner. 00083 * 00084 * \param progress the progress to add as a child. 00085 * \note it is possible to add ProgressCombiner instances as well. 00086 */ 00087 virtual void addSubProgress( boost::shared_ptr< WProgress > progress ); 00088 00089 /** 00090 * Removes the specified sub progress from this combiner. 00091 * 00092 * \param progress the progress to remove. 00093 */ 00094 virtual void removeSubProgress( boost::shared_ptr< WProgress > progress ); 00095 00096 /** 00097 * Function updating the internal state. This needs to be called before any get function to ensure the getter return the right 00098 * values. 00099 * 00100 * \note this method is expansive. It uses a lock to avoid concurrent write and iterates over this combiners children. 00101 */ 00102 virtual void update(); 00103 00104 /** 00105 * Generates a string combined out of every child progress name. 00106 * 00107 * \return One describing string for all child progress names. 00108 */ 00109 std::string getCombinedNames() const; 00110 00111 protected: 00112 00113 /** 00114 * The name of the combiner. 00115 */ 00116 std::string m_name; 00117 00118 /** 00119 * The current conglomerated progress. Set by update(). 00120 */ 00121 float m_progress; 00122 00123 /** 00124 * Set of all child progress. 00125 */ 00126 std::set< boost::shared_ptr< WProgress > > m_children; 00127 00128 /** 00129 * Lock for the above child set and the internal state update. 00130 */ 00131 mutable boost::shared_mutex m_updateLock; 00132 00133 private: 00134 }; 00135 00136 #endif // WPROGRESSCOMBINER_H 00137