Commit f1c3d812 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD #157] now we have a status reporter

parent b72f56f7
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <cassert>
#include <cmath>
#include <string>
#include "WStatusReport.h"
WStatusReport::WStatusReport( unsigned int totalSteps )
: m_totalSteps( totalSteps ),
m_finishedSteps( 0 )
{
}
double WStatusReport::operator++()
{
assert( m_totalSteps > m_finishedSteps );
m_finishedSteps++;
return progress();
}
double WStatusReport::operator+=( unsigned int numSteps )
{
assert( m_totalSteps > m_finishedSteps );
if( m_totalSteps - m_finishedSteps < numSteps )
{
m_finishedSteps = m_totalSteps;
}
else
{
m_finishedSteps += numSteps;
}
return progress();
}
std::string WStatusReport::stringBar( char symbol, unsigned int finalNumOfSymbols ) const
{
unsigned int numSymbols = progress() * finalNumOfSymbols;
return std::string( numSymbols, symbol );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WSTATUSREPORT_H
#define WSTATUSREPORT_H
#include <string>
/**
* A counter for reporting the progress of some work.
*/
class WStatusReport
{
friend class WStatusReportTest;
public:
/**
* Constructs a new status reporter with the number of total steps
* which it should reach to reach the 100 percent.
*/
explicit WStatusReport( unsigned int totalSteps );
/**
* Returns the total number of steps which are considered as 100 percent
* work.
*/
unsigned int getTotalSteps() const
{
return m_totalSteps;
}
/**
* Returns the number of steps done so far
*/
unsigned int getFinishedSteps() const
{
return m_finishedSteps;
}
/**
* Returns the progress in percentage done so far: e.g. 0.7 == 70%
*/
double progress() const
{
return static_cast< double >( m_finishedSteps ) / m_totalSteps;
}
/**
* Increments the finished work by one step.
*
* \return The progress()
*/
double operator++();
/**
* Increments the finished work by the number of the given steps.
*
* \return The progress()
*/
double operator+=( unsigned int numSteps );
/**
* Generates a string which represents the progress in terms of
* characters. When reaching 100 percent finally finalNumOfSymbols are
* returned.
*/
std::string stringBar( char symbol = '#', unsigned int finalNumOfSymbols = 50 ) const;
protected:
private:
unsigned int m_totalSteps;
unsigned int m_finishedSteps;
};
#endif // WSTATUSREPORT_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WSTATUSREPORT_TEST_H
#define WSTATUSREPORT_TEST_H
#include <string>
#include <cxxtest/TestSuite.h>
#include "../WStatusReport.h"
/**
* Unit tests our StatusReporter class
*/
class WStatusReportTest : public CxxTest::TestSuite
{
public:
/**
* Given a certain percentage of progress and a char, and a number
* of total chars to display, the StringBar of a WStatusReporter
* object should be determined.
*/
void testStringBar( void )
{
WStatusReport st( 312 );
st += 189;
std::string expected( 30, '#' );
TS_ASSERT_EQUALS( st.stringBar(), expected );
}
/**
* When incrementing over total and the progress is below 100%, it should
* be accumulated to 100%. But if the progress is already at 100%
* an assert should fail!
*/
void testIncrementOverTotal( void )
{
WStatusReport st( 312 );
st += 311;
st += 9000;
TS_ASSERT_EQUALS( st.progress(), 1.0 );
}
};
#endif // WSTATUSREPORT_TEST_H
......@@ -127,11 +127,13 @@ void WFiberCulling::cullOutFibers( boost::shared_ptr< WDataSetFibers > fibers )
if( dst < m_dSt_culling_t ) // cullout small fibs nearby long fibs
{
if( q.size() < r.size() ) {
if( q.size() < r.size() )
{
unusedFibers[i] = true;
break;
}
else {
else
{
unusedFibers[j] = true;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment