Stxxl  1.3.2
completion_handler.h
1 /***************************************************************************
2  * include/stxxl/bits/io/completion_handler.h
3  *
4  * Loki-style completion handler (functors)
5  *
6  * Part of the STXXL. See http://stxxl.sourceforge.net
7  *
8  * Copyright (C) 2003 Roman Dementiev <[email protected]>
9  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
10  *
11  * Distributed under the Boost Software License, Version 1.0.
12  * (See accompanying file LICENSE_1_0.txt or copy at
13  * http://www.boost.org/LICENSE_1_0.txt)
14  **************************************************************************/
15 
16 #ifndef STXXL_COMPLETION_HANDLER_HEADER
17 #define STXXL_COMPLETION_HANDLER_HEADER
18 
19 #include <stxxl/bits/namespace.h>
20 #include <stxxl/bits/compat_unique_ptr.h>
21 
22 
23 __STXXL_BEGIN_NAMESPACE
24 
25 class request;
26 
27 class completion_handler_impl
28 {
29 public:
30  virtual void operator () (request *) = 0;
31  virtual completion_handler_impl * clone() const = 0;
32  virtual ~completion_handler_impl() { }
33 };
34 
35 template <typename handler_type>
36 class completion_handler1 : public completion_handler_impl
37 {
38 private:
39  handler_type handler_;
40 
41 public:
42  completion_handler1(const handler_type & handler__) : handler_(handler__) { }
43  completion_handler1 * clone() const
44  {
45  return new completion_handler1(*this);
46  }
47  void operator () (request * req)
48  {
49  handler_(req);
50  }
51 };
52 
54 
64 {
65  compat_unique_ptr<completion_handler_impl>::result sp_impl_;
66 
67 public:
69  sp_impl_(static_cast<completion_handler_impl *>(0))
70  { }
71 
73  sp_impl_(obj.sp_impl_.get()->clone())
74  { }
75 
76  template <typename handler_type>
77  completion_handler(const handler_type & handler__) :
78  sp_impl_(new completion_handler1<handler_type>(handler__))
79  { }
80 
81  completion_handler & operator = (const completion_handler & obj)
82  {
83  sp_impl_.reset(obj.sp_impl_.get()->clone());
84  return *this;
85  }
86  void operator () (request * req)
87  {
88  (*sp_impl_)(req);
89  }
90 };
91 
93 
95 {
97  void operator () (request *) { }
98 };
99 
100 __STXXL_END_NAMESPACE
101 
102 #endif // !STXXL_COMPLETION_HANDLER_HEADER
103 // vim: et:ts=4:sw=4
Default completion handler class.
Definition: completion_handler.h:94
Request with basic properties like file and offset.
Definition: request.h:39
Completion handler class (Loki-style)
Definition: completion_handler.h:63
void operator()(request *)
An operator that does nothing.
Definition: completion_handler.h:97