4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief membind public header */
26 /** \defgroup membind Bound Member Functions
28 The membind() family of function templates simplifies the creation of simple bound member
37 boost::function<int (int)> f = senf::membind(&Foo::test,foo);
38 int rv = f(1); // Calls foo->test(1)
41 senf::membind() takes either a pointer or an object as second argument. When passing an object,
42 <em>that object will be copied into the bound member function returned.</em>
44 \idea Make the \a ob argument type an additional P template parameter (using call_traits for the
45 exact arg type? Probably we'll get deduction problems then) . The only operation this object
46 must support is ob->*fn. This would allow the use of smart pointers. We should keep the T &
47 version to still support ob.*fn use.
50 #ifndef HH_SENF_Utils_membind_
51 #define HH_SENF_Utils_membind_ 1
54 #include <boost/bind.hpp>
55 #include <boost/function.hpp>
56 #include "../config.hh"
58 ///////////////////////////////hh.p////////////////////////////////////////
60 #define SENF_FNP(ret, fn, args) \
61 static_cast<ret (*) args>(& fn)
63 #define SENF_MEMFNP(ret, cls, fn, args) \
64 static_cast<ret (cls::*) args>(& cls :: fn)
66 #define SENF_MEMBINDFNP(ret, cls, fn, args) \
67 senf::membind(SENF_MEMFNP(ret, cls, fn, args), this)
72 #include "../Utils/impl/membind.hh"
76 #include "../Utils/impl/membind.hh"
81 /// \addtogroup membind
84 /** \brief Build bound member function object
86 membind() supports up to 9 function parameters (represented as
87 \a Args here). The \a ob argument can be either a pointer or a
89 \param[in] fn member function pointer
90 \param[in] ob object instance to bind this pointer to
91 \returns Boost.Function object representing a bound call of \a
94 template <typename R, typename T, typename Args>
95 boost::function<R (Args)> membind(R (T::* fn)( Args ), T * ob);
103 ///////////////////////////////hh.e////////////////////////////////////////
104 //#include "membind.cci"
105 //#include "membind.ct"
106 //#include "membind.cti"
113 // c-file-style: "senf"
114 // indent-tabs-mode: nil
115 // ispell-local-dictionary: "american"
116 // compile-command: "scons -u test"
117 // comment-column: 40