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 #include <algorithm> 00026 #include <cmath> 00027 #include <string> 00028 00029 #include "../common/WCondition.h" 00030 00031 #include "WProgress.h" 00032 00033 WProgress::WProgress( std::string name, size_t count ) 00034 : m_name( name ), 00035 m_max( count - 1 ), 00036 m_count( 0 ), 00037 m_pending( true ), 00038 m_determined( true ) 00039 { 00040 if( count == 0 ) 00041 { 00042 m_max = 0; 00043 m_determined = false; 00044 } 00045 } 00046 00047 WProgress::~WProgress() 00048 { 00049 // clean up 00050 } 00051 00052 void WProgress::update() 00053 { 00054 // This updates the internal state. But as this class updates its state directly -> do nothing here 00055 } 00056 00057 void WProgress::finish() 00058 { 00059 m_pending = false; 00060 m_count = m_max; 00061 } 00062 00063 WProgress& WProgress::operator++() 00064 { 00065 return *this + 1; 00066 } 00067 00068 float WProgress::getProgress() 00069 { 00070 return isDetermined() ? 100.0 * ( static_cast< float >( m_count ) / static_cast< float >( m_max ) ) : 0.0; 00071 } 00072 00073 bool WProgress::isPending() 00074 { 00075 return m_pending; 00076 } 00077 00078 std::string WProgress::getName() const 00079 { 00080 return m_name; 00081 } 00082 00083 bool WProgress::isDetermined() 00084 { 00085 return m_determined; 00086 } 00087 00088 WProgress& WProgress::operator+( size_t steps ) 00089 { 00090 if( isDetermined() ) 00091 { 00092 m_count = std::min( m_max, m_count + steps ); 00093 } 00094 00095 return *this; 00096 } 00097 00098 void WProgress::increment( size_t steps ) 00099 { 00100 operator+( steps ); 00101 }