015c20f2334890b1a87f994a8e921da6a4855ddd
[senf.git] / senf / PPI / detail / Callback.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Callback public header */
25
26 #ifndef HH_SENF_PPI_detail_Callback_
27 #define HH_SENF_PPI_detail_Callback_ 1
28
29 // Custom includes
30 #include <boost/function.hpp>
31
32 //#include "Callback.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36 namespace ppi {
37 namespace detail {
38
39     /** \brief Provide callbacks with a single optional argument
40
41         This helper implements callbacks with an optional single argument. In addition to
42         boost::function, this helper provides the following functionality:
43
44         \li It allows the callback to ignore the argument: A callable with no argument may be used
45             as callback.
46         \li It allows to use member function pointers as callbacks. These will be automatically
47             bound to the \a owner argument of \ref make().
48
49         The callbacks follow the same restrictions as <a href="">Boost.Function</a>: They must be
50         either function, member function pointers or callable objects defining the appropriate
51         typedef members.
52      */
53     template <class Arg=void>
54     struct Callback
55     {
56         typedef boost::function<void (Arg)> type;
57
58         template <class Owner, class FnClass>
59         static type make(void (FnClass::* memfn )(), Owner & owner);
60         template <class Owner, class FnClass, class FnArg>
61         static type make(void (FnClass::* memfn )(FnArg arg), Owner & owner);
62         template <class Owner>
63         static type make(type callable, Owner &);
64         template <class Owner>
65         static type make(boost::function<void()> callable, Owner &);
66     };
67
68 #ifndef DOXYGEN
69
70     template <>
71     struct Callback<void>
72     {
73         typedef boost::function<void ()> type;
74
75         template <class Owner, class FnClass>
76         static type make(void (FnClass::* memfn )(), Owner & owner);
77         template <class Owner>
78         static type make(type callable, Owner &);
79     };
80
81 #endif
82
83 }}}
84
85 ///////////////////////////////hh.e////////////////////////////////////////
86 //#include "Callback.cci"
87 //#include "Callback.ct"
88 #include "Callback.cti"
89 #endif
90
91 \f
92 // Local Variables:
93 // mode: c++
94 // fill-column: 100
95 // comment-column: 40
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u ../test"
100 // End: