NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / Utils / membind.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
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 membind  public header */
25
26 /** \defgroup membind Bound Member Functions
27
28     The membind() family of function templates simplifies the creation
29     of simple bound member function pointers:
30
31     \code
32       struct Foo {
33           int test(int x);
34       };
35
36       Foo * foo = ...;
37       boost::function<int (int)> f = senf::membind(&Foo::test,foo);
38       int rv = f(1); // Calls foo->test(1)
39     \endcode
40
41     \idea Make the \a ob argument type an additional P template
42     parameter (using call_traits for the exact arg type? Probably
43     we'll get deduction problems then) . The only operation this
44     object must support is ob->*fn. This would allow the use of
45     smart pointers. We should keep the T & version to still support
46     ob.*fn use.
47  */
48
49 #ifndef HH_membind_
50 #define HH_membind_ 1
51
52 // Custom includes
53 #include <boost/bind.hpp>
54 #include <boost/function.hpp>
55
56 ///////////////////////////////hh.p////////////////////////////////////////
57
58 namespace senf {
59
60 #define scOBTYPE T *
61 #include "../Utils/impl/membind.hh"
62 #undef scOBTYPE
63
64 #define scOBTYPE T &
65 #include "../Utils/impl/membind.hh"
66 #undef scOBTYPE
67
68 #ifdef DOXYGEN
69
70     /// \addtogroup membind
71     /// @{
72
73     /** \brief Build bound member function object
74
75         membind() supports up to 9 function parameters (represented as
76         \a Args here). The \a ob argument can be either a pointer or a
77         reference to \a T
78         \param[in] fn member function pointer
79         \param[in] ob object instance to bind this pointer to
80         \returns Boost.Function object representing a bound call of \a
81             fn on \a ob
82      */
83     template <typename R, typename T, typename Args>
84     boost::function<R (Args)> membind(R (T::* fn)( Args ), T * ob);
85
86     /// @}
87
88 #endif
89
90 }
91
92 ///////////////////////////////hh.e////////////////////////////////////////
93 //#include "membind.cci"
94 //#include "membind.ct"
95 //#include "membind.cti"
96 #endif
97
98 \f
99 // Local Variables:
100 // mode: c++
101 // fill-column: 100
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // comment-column: 40
107 // End: