switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / detail / Callback.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief Callback public header */
30
31 #ifndef HH_SENF_PPI_detail_Callback_
32 #define HH_SENF_PPI_detail_Callback_ 1
33
34 // Custom includes
35 #include <boost/function.hpp>
36
37 //#include "Callback.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 namespace senf {
41 namespace ppi {
42 namespace detail {
43
44     /** \brief Provide callbacks with a single optional argument
45
46         This helper implements callbacks with an optional single argument. In addition to
47         boost::function, this helper provides the following functionality:
48
49         \li It allows the callback to ignore the argument: A callable with no argument may be used
50             as callback.
51         \li It allows to use member function pointers as callbacks. These will be automatically
52             bound to the \a owner argument of \ref make().
53
54         The callbacks follow the same restrictions as <a href="">Boost.Function</a>: They must be
55         either function, member function pointers or callable objects defining the appropriate
56         typedef members.
57      */
58     template <class Arg=void>
59     struct Callback
60     {
61         typedef boost::function<void (Arg)> type;
62
63         template <class Owner, class FnClass>
64         static type make(void (FnClass::* memfn )(), Owner & owner);
65         template <class Owner, class FnClass, class FnArg>
66         static type make(void (FnClass::* memfn )(FnArg arg), Owner & owner);
67         template <class Owner>
68         static type make(type callable, Owner &);
69         template <class Owner>
70         static type make(boost::function<void()> callable, Owner &);
71     };
72
73 #ifndef DOXYGEN
74
75     template <>
76     struct Callback<void>
77     {
78         typedef boost::function<void ()> type;
79
80         template <class Owner, class FnClass>
81         static type make(void (FnClass::* memfn )(), Owner & owner);
82         template <class Owner>
83         static type make(type callable, Owner &);
84     };
85
86 #endif
87
88 }}}
89
90 //-/////////////////////////////////////////////////////////////////////////////////////////////////
91 //#include "Callback.cci"
92 //#include "Callback.ct"
93 #include "Callback.cti"
94 #endif
95
96 \f
97 // Local Variables:
98 // mode: c++
99 // fill-column: 100
100 // comment-column: 40
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u ../test"
105 // End: