/*!
@file progress.hpp
@brief boost::progress_displayの計算部分を抜き出したような物です。
@since 2004/10/23
@author d金魚
*/
#ifndef DKUTIL_PROGRESS_HPP
#define DKUTIL_PROGRESS_HPP

#include <dkutil/boost/progress.hpp>




namespace dkutil{

	/*
template<typename ULONG_T=ULONG,typename FLOAT_T = double>

class progress_calculator_float
{
public:
	typedef ULONG_T unsigned_type;
private:
	ULONG_T mMax;
	///カウンタ。
	ULONG_T mCount;
	///mDivValueが100以外の時はPercentだと可笑しいけど＾＾； percent保存
	ULONG_T mPercent;
	///1%のサイズ (mDivValueが100の時は
	ULONG m1PercentSize;
	///全体から割る数
	ULONG_T mDivValue;
public:
	
  explicit progress_calculator_base( ULONG_T max_value__ ,ULONG_T div_value__ = 100){
		reset(max_value__); 
	}

  void reset( ULONG_T max_value__ ,ULONG_T div_value__ = 100)
  {
		if(0==max_value__)
			max_value__ = 1;
		if(0==div_value__)
			div_value__ = 1;
		
    mMax = max_value__;
		mCount = 1;
		mPercent = 0;
		m1PercentSize = (max_value__ / div_value__);
		mDivValue = div_value__;

  } // restart

  ULONG_T operator+=( ULONG_T increment )
  {
    mCount += increment;
		
		//パーセンテージを求める。
		mPercent = mCount / m1PercentSize;
		return mCount;
  }

  ULONG_T operator++()           { 
		return operator+=( 1 ); 
	}
	ULONG_T operator++(int){
		return operator++();
	}
	ULONG_T  count() const          {
		return mCount; 
	}
  ULONG_T  max_count() const { 
		return mMax; 
	}
	ULONG_T percentage()const{
		return mPercent;
	}
	ULONG_T scaling(ULONG_T a)const{
		 return ( (a / mDivValue) * mPercent);
	}
	ULONG_T  one_count(){
		return m1Percent;
	}
	ULONG_T div_value()const{
		return mDivValue;
	}


};
*/
//template<typename ULONG_T=ULONG,typename FLOAT_T = double>
template<typename ULONG_T=double>
class progress_calculator_base
{
public:
	typedef ULONG_T unsigned_type;
private:
	ULONG_T mMax;
	///カウンタ。
	ULONG_T mCount;
	///mDivValueが100以外の時はPercentだと可笑しいけど＾＾； percent保存
	ULONG_T mPercent;
	///1%のサイズ (mDivValueが100の時は
	ULONG m1PercentSize;
	///全体から割る数
	ULONG_T mDivValue;
public:
	
  explicit progress_calculator_base( ULONG_T max_value__ ,ULONG_T div_value__ = 100){
		reset(max_value__); 
	}

  void reset( ULONG_T max_value__ ,ULONG_T div_value__ = 100)
  {
		if(0==max_value__)
			max_value__ = 1;
		if(0==div_value__)
			div_value__ = 1;
		
    mMax = max_value__;
		mCount = 1;
		mPercent = 0;
		m1PercentSize = (max_value__ / div_value__);
		mDivValue = div_value__;

  } // restart

  ULONG_T operator+=( ULONG_T increment )
  {
    mCount += increment;
		
		//パーセンテージを求める。
		mPercent = mCount / m1PercentSize;
		return mCount;
  }

  ULONG_T operator++()           { 
		return operator+=( 1 ); 
	}
	ULONG_T operator++(int){
		return operator++();
	}
	ULONG_T  count() const          {
		return mCount; 
	}
  ULONG_T  max_count() const { 
		return mMax; 
	}
	ULONG_T percentage()const{
		return mPercent;
	}
	ULONG_T scaling(ULONG_T a)const{
		 return ( (a / mDivValue) * mPercent);
	}
	ULONG_T  one_count(){
		return m1Percent;
	}
	ULONG_T div_value()const{
		return mDivValue;
	}


};

///doubleにしないと誤差が出る。　整数にするならscalingシナイト・・・。
typedef progress_calculator_base<double> progress_calculator;

}//end of dkutil namespace




#endif