http://stxxl.sourceforge.net
<dementiev@mpi-sb.mpg.de>
<beckmann@cs.uni-frankfurt.de>
http://www.boost.org/LICENSE_1_0.txt
#ifndef STXXL_COMPLETION_HANDLER_HEADER
#define STXXL_COMPLETION_HANDLER_HEADER
#include <stxxl/bits/namespace.h>
#include <stxxl/bits/compat_unique_ptr.h>
__STXXL_BEGIN_NAMESPACE
class request;
class completion_handler_impl
{
public:
virtual void operator () (request *) = 0;
virtual completion_handler_impl * clone() const = 0;
virtual ~completion_handler_impl() { }
};
template <typename handler_type>
class completion_handler1 : public completion_handler_impl
{
private:
handler_type handler_;
public:
completion_handler1(const handler_type & handler__) : handler_(handler__) { }
completion_handler1 * clone() const
{
return new completion_handler1(*this);
}
void operator () (request * req)
{
handler_(req);
}
};
class completion_handler
{
compat_unique_ptr<completion_handler_impl>::result sp_impl_;
public:
completion_handler() :
sp_impl_(static_cast<completion_handler_impl *>(0))
{ }
completion_handler(const completion_handler & obj) :
sp_impl_(obj.sp_impl_.get()->clone())
{ }
template <typename handler_type>
completion_handler(const handler_type & handler__) :
sp_impl_(new completion_handler1<handler_type>(handler__))
{ }
completion_handler & operator = (const completion_handler & obj)
{
sp_impl_.reset(obj.sp_impl_.get()->clone());
return *this;
}
void operator () (request * req)
{
(*sp_impl_)(req);
}
};
struct default_completion_handler
{
void operator () (request *) { }
};
__STXXL_END_NAMESPACE
#endif