STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
completion_handler.h
Go to the documentation of this file.
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_IO_COMPLETION_HANDLER_HEADER
17 #define STXXL_IO_COMPLETION_HANDLER_HEADER
18 
19 #include <stxxl/bits/namespace.h>
21 
22 
24 
25 class request;
26 
28 {
29 public:
30  virtual void operator () (request*) = 0;
31  virtual completion_handler_impl * clone() const = 0;
33 };
34 
35 template <typename handler_type>
37 {
38 private:
39  handler_type handler_;
40 
41 public:
42  completion_handler1(const handler_type& handler__) : handler_(handler__) { }
44  {
45  return new completion_handler1(*this);
46  }
47  void operator () (request* req)
48  {
49  handler_(req);
50  }
51 };
52 
53 //! Completion handler class (Loki-style).
54 //!
55 //! In some situations one needs to execute
56 //! some actions after completion of an I/O
57 //! request. In these cases one can use
58 //! an I/O completion handler - a function
59 //! object that can be passed as a parameter
60 //! to asynchronous I/O calls \c stxxl::file::aread
61 //! and \c stxxl::file::awrite .
63 {
65 
66 public:
68  sp_impl_(static_cast<completion_handler_impl*>(0))
69  { }
70 
72  sp_impl_(obj.sp_impl_.get()->clone())
73  { }
74 
75  template <typename handler_type>
76  completion_handler(const handler_type& handler__) :
77  sp_impl_(new completion_handler1<handler_type>(handler__))
78  { }
79 
80  completion_handler& operator = (const completion_handler& obj)
81  {
82  sp_impl_.reset(obj.sp_impl_.get()->clone());
83  return *this;
84  }
85  void operator () (request* req)
86  {
87  (* sp_impl_)(req);
88  }
89 };
90 
91 //! Default completion handler class.
92 
94 {
95  //! An operator that does nothing.
96  void operator () (request*) { }
97 };
98 
100 
101 #endif // !STXXL_IO_COMPLETION_HANDLER_HEADER
102 // vim: et:ts=4:sw=4
completion_handler(const handler_type &handler__)
Default completion handler class.
compat_unique_ptr< completion_handler_impl >::result sp_impl_
Completion handler class (Loki-style).
completion_handler1(const handler_type &handler__)
std::auto_ptr< _Tp > result
Definition: unique_ptr.h:31
completion_handler(const completion_handler &obj)
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
completion_handler1 * clone() const
Request with basic properties like file and offset.
Definition: request.h:39
#define STXXL_END_NAMESPACE
Definition: namespace.h:17