8c69a1c46707a2298248c8ecdf22412b4e91606f
[senf.git] / senf / Utils / impl / 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 // NEVER INCLUDE DIRECTLY !! INCLUDE senf/membind.hh
24
25 #if !BOOST_PP_IS_ITERATING
26
27 #include <boost/preprocessor/cat.hpp>
28 #include <boost/preprocessor/repetition/enum_shifted.hpp>
29 #include <boost/preprocessor/iteration/iterate.hpp>
30
31 template <typename R, typename T1, typename T2>
32 boost::function<R()> membind(R (T1::* fn)(),T2 scOBTYPE ob)
33 {
34     return boost::bind(fn,static_cast<T1 scOBTYPE>(ob));
35 }
36
37 template <typename R, typename T1, typename T2>
38 boost::function<R()> membind(R (T1::* fn)() const, T2 const scOBTYPE ob)
39 {
40     return boost::bind(fn,static_cast<T1 const scOBTYPE>(ob));
41 }
42
43 template <typename R, typename T1, typename T2>
44 boost::function<R()> membind(R (T1::* fn)() const, T2 scOBTYPE ob)
45 {
46     return boost::bind(fn,static_cast<T1 const scOBTYPE>(ob));
47 }
48
49 // for BOOST_PP_ITERATION() in 2..9 do
50 #define BOOST_PP_ITERATION_PARAMS_1 (4, (2, 9, SENF_ABSOLUTE_INCLUDE_PATH(Utils/impl/membind.hh), 1))
51 #include BOOST_PP_ITERATE()
52 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==1
53 // {{
54
55 #define scARG(z,n,d) BOOST_PP_CAT(d,n)
56 #define scPARAMS(d) BOOST_PP_ENUM_SHIFTED(BOOST_PP_ITERATION(),scARG,d)
57
58 template < typename R, typename T1, typename T2, scPARAMS(typename A) >
59 boost::function<R ( scPARAMS(A) )>
60 membind(R (T1::* fn)( scPARAMS(A) ), T2 scOBTYPE ob)
61 {
62     return boost::bind(fn, static_cast<T1 scOBTYPE>(ob), scPARAMS(_) );
63 }
64
65 template < typename R, typename T1, typename T2, scPARAMS(typename A) >
66 boost::function<R ( scPARAMS(A) )>
67 membind(R (T1::* fn)( scPARAMS(A) ) const, T2 const scOBTYPE ob)
68 {
69     return boost::bind(fn, static_cast<T1 const scOBTYPE>(ob), scPARAMS(_) );
70 }
71
72 template < typename R, typename T1, typename T2, scPARAMS(typename A) >
73 boost::function<R ( scPARAMS(A) )>
74 membind(R (T1::* fn)( scPARAMS(A) ) const, T2 scOBTYPE ob)
75 {
76     return boost::bind(fn, static_cast<T1 const scOBTYPE>(ob), scPARAMS(_) );
77 }
78
79 #undef scPARAMS
80 #undef scARG
81
82 // }
83 #endif
84 // done
85
86 \f
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // comment-column: 40
95 // End: