6b6681c9c07476593b3be91b0fffcc801e4f7136
[senf.git] / Utils / impl / membind.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 #include "../../config.hh"
31
32 template <typename R, typename T>
33 boost::function<R()> membind(R (T::* fn)(),scOBTYPE ob)
34 {
35     return boost::bind(fn,ob);
36 }
37
38 // for BOOST_PP_ITERATION() in 2..9 do
39 #define BOOST_PP_ITERATION_PARAMS_1 (4, (2, 9, SENF_ABSOLUTE_INCLUDE_PATH(Utils/impl/membind.hh), 1))
40 #include BOOST_PP_ITERATE()
41 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==1
42 // {{
43
44 #define scARG(z,n,d) BOOST_PP_CAT(d,n)
45 #define scPARAMS(d) BOOST_PP_ENUM_SHIFTED(BOOST_PP_ITERATION(),scARG,d)
46
47 template < typename R, typename T, scPARAMS(typename A) >
48 boost::function<R ( scPARAMS(A) )>
49 membind(R (T::* fn)( scPARAMS(A) ), scOBTYPE ob)
50 {
51     return boost::bind(fn, ob, scPARAMS(_) );
52 }
53
54 #undef scPARAMS
55 #undef scARG
56
57 // }
58 #endif
59 // done
60
61 \f
62 // Local Variables:
63 // mode: c++
64 // fill-column: 100
65 // c-file-style: "senf"
66 // indent-tabs-mode: nil
67 // ispell-local-dictionary: "american"
68 // compile-command: "scons -u test"
69 // comment-column: 40
70 // End: