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