/* ImLib3D
 * Copyright (c) 2001, ULP-IPB Strasbourg.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program 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
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
/*! \file ImageProgress.hpp */

#ifndef _ImageProgress_hpp
#define _ImageProgress_hpp

#include<ImLib3D/TaskProgressManager.hpp>
#include<ImLib3D.hpp>

class ImageProgressHelper
{
public:
	virtual double Progress()=0;
	virtual ~ImageProgressHelper(){;};
};
template<class ItType>
class ImageProgressHelperNormal : public ImageProgressHelper
{
	ItType *it;
public:
	virtual double Progress(){return it->Progress();}
	ImageProgressHelperNormal(ItType &_it):it(&_it){;}
};
//! Progress tracker specifically made for easy tracking of progress of an iterator
/*! this non template class is used to avoid the user having to specify
template args. Template args are automagically determined using templated constructors. */
class ImageProgress : public TaskInProgress
{
	ImageProgressHelper *helper;
public:
	virtual double Progress(){return helper->Progress();}
	virtual string ProgressLabel(){return SPrintf("%2.1f%%",100*Progress());}
	//! Templated contructor for other iterators (that have a "Progress" fct)
	template<class ItType>
	ImageProgress(const string &_name,ItType &p):
		TaskInProgress(_name,imLib3D.taskProgressManager),
		helper(new ImageProgressHelperNormal<ItType>(p))
	{
	}
	virtual ~ImageProgress(){delete helper;}
};

#ifdef  USE_EXPLICIT_INSTANTIATION
// explicit instantiation of common templates, only for faster compilation
extern template class ImageProgressHelperNormal<Container3D<int>::iteratorXYZ>;
extern template class ImageProgressHelperNormal<Container3D<int>::const_iteratorXYZ>;

extern template class ImageProgressHelperNormal<Container3D<float>::iteratorXYZ>;
extern template class ImageProgressHelperNormal<Container3D<float>::const_iteratorXYZ>;
#endif // USE_EXPLICIT_INSTANTIATION

#endif //_ImageProgress_hpp
