]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/cppbind/detail/functor_templates.hxx
Make old gcc happy
[simgear.git] / simgear / nasal / cppbind / detail / functor_templates.hxx
1 #ifndef SG_NASAL_GHOST_HXX_
2 # error Nasal cppbind - do not include this file!
3 #endif
4
5 #define n BOOST_PP_ITERATION()
6
7 #define SG_GHOST_FUNC_TYPE\
8   boost::function<Ret (raw_type& BOOST_PP_COMMA_IF(n)BOOST_PP_ENUM_PARAMS(n,A))>
9
10   /**
11    * Bind any callable entity accepting an instance of raw_type and an arbitrary
12    * number of arguments as method.
13    */
14   template<
15     class Ret
16     BOOST_PP_COMMA_IF(n)
17     BOOST_PP_ENUM_PARAMS(n, class A)
18   >
19   Ghost& method(const std::string& name, const SG_GHOST_FUNC_TYPE& func)
20   {
21 #if defined(GCC_VERSION) && GCC_VERSION < 40407
22     // The old version of g++ used on Jenkins (16.11.2012) only compiles this
23     // version.
24 # define SG_GHOST_REQUIRE_ARG(z, n, dummy)\
25     boost::bind(&arg_from_nasal<A##n>, _2, n)
26 #else
27     // VS (2008, 2010, ... ?) only allow this version.
28 # define SG_GHOST_REQUIRE_ARG(z, n, dummy)\
29     boost::bind(&Ghost::arg_from_nasal<A##n>, _2, n)
30 #endif
31
32     return method<Ret>
33     (
34       name,
35       typename boost::function<Ret (raw_type&, const CallContext&)>
36       ( boost::bind(
37         func,
38         _1
39         BOOST_PP_COMMA_IF(n)
40         BOOST_PP_ENUM(n, SG_GHOST_REQUIRE_ARG,)
41       ))
42     );
43
44 #undef SG_GHOST_REQUIRE_ARG
45   }
46
47 #define SG_GHOST_MEM_FN(cv)\
48   /**\
49    * Bind a member function with an arbitrary number of arguments as method.\
50    */\
51   template<\
52     class Ret\
53     BOOST_PP_COMMA_IF(n)\
54     BOOST_PP_ENUM_PARAMS(n, class A)\
55   >\
56   Ghost& method\
57   (\
58     const std::string& name,\
59     Ret (raw_type::*fn)(BOOST_PP_ENUM_PARAMS(n,A)) cv\
60   )\
61   {\
62     return method<\
63       Ret\
64       BOOST_PP_COMMA_IF(n)\
65       BOOST_PP_ENUM_PARAMS(n,A)\
66     >(name, SG_GHOST_FUNC_TYPE(fn));\
67   }
68
69
70   SG_GHOST_MEM_FN()
71   SG_GHOST_MEM_FN(const)
72
73 #undef SG_GHOST_MEM_FN
74
75   /**
76    * Bind free function accepting an instance of raw_type and an arbitrary
77    * number of arguments as method.
78    */
79   template<
80     class Ret,
81     class Type
82     BOOST_PP_COMMA_IF(n)
83     BOOST_PP_ENUM_PARAMS(n, class A)
84   >
85   Ghost& method
86   (
87     const std::string& name,
88     Ret (*fn)(Type BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,A))
89   )
90   {
91     BOOST_STATIC_ASSERT
92     (( boost::is_convertible<raw_type&, Type>::value
93     //|| boost::is_convertible<raw_type*, Type>::value
94     // TODO check how to do it with pointer...
95     ));
96     return method<Ret>(name, SG_GHOST_FUNC_TYPE(fn));
97   }
98
99 #undef n
100 #undef SG_GHOST_TYPEDEF_FUNC_TYPE