00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef STXXL_COMPLETION_HANDLER_HEADER
00017 #define STXXL_COMPLETION_HANDLER_HEADER
00018
00019 #include <stxxl/bits/namespace.h>
00020 #include <stxxl/bits/compat_unique_ptr.h>
00021
00022
00023 __STXXL_BEGIN_NAMESPACE
00024
00025 class request;
00026
00027 class completion_handler_impl
00028 {
00029 public:
00030 virtual void operator () (request *) = 0;
00031 virtual completion_handler_impl * clone() const = 0;
00032 virtual ~completion_handler_impl() { }
00033 };
00034
00035 template <typename handler_type>
00036 class completion_handler1 : public completion_handler_impl
00037 {
00038 private:
00039 handler_type handler_;
00040
00041 public:
00042 completion_handler1(const handler_type & handler__) : handler_(handler__) { }
00043 completion_handler1 * clone() const
00044 {
00045 return new completion_handler1(*this);
00046 }
00047 void operator () (request * req)
00048 {
00049 handler_(req);
00050 }
00051 };
00052
00054
00063 class completion_handler
00064 {
00065 compat_unique_ptr<completion_handler_impl>::result sp_impl_;
00066
00067 public:
00068 completion_handler() :
00069 sp_impl_(static_cast<completion_handler_impl *>(0))
00070 { }
00071
00072 completion_handler(const completion_handler & obj) :
00073 sp_impl_(obj.sp_impl_.get()->clone())
00074 { }
00075
00076 template <typename handler_type>
00077 completion_handler(const handler_type & handler__) :
00078 sp_impl_(new completion_handler1<handler_type>(handler__))
00079 { }
00080
00081 completion_handler & operator = (const completion_handler & obj)
00082 {
00083 sp_impl_.reset(obj.sp_impl_.get()->clone());
00084 return *this;
00085 }
00086 void operator () (request * req)
00087 {
00088 (*sp_impl_)(req);
00089 }
00090 };
00091
00093
00094 struct default_completion_handler
00095 {
00097 void operator () (request *) { }
00098 };
00099
00100 __STXXL_END_NAMESPACE
00101
00102 #endif // !STXXL_COMPLETION_HANDLER_HEADER
00103