PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/callback.i

#
Swig | 72 lines | 54 code | 18 blank | 0 comment | 0 complexity | 9fc86356adfa1138b2a00c4d20fa34a7 MD5 | raw file
 1%module callback
 2
 3%callback(1) foo;
 4%callback(1) foof;
 5%callback(1) A::bar;
 6%callback(1) A::foom;
 7%callback("%s_Cb_Ptr") foo_T;  // old style, still works.
 8
 9%inline %{
10
11  int foo(int a) {
12    return a;
13  }
14  
15  int foof(int a) {
16    return 3*a;
17  }  
18  
19  struct A 
20  {
21    static int bar(int a) {
22      return 2*a;
23    }
24
25    int foom(int a) 
26    {
27      return -a;
28    }
29
30    //friend int foof(int a);
31  };
32
33
34  extern "C" int foobar(int a, int (*pf)(int a)) {
35    return pf(a);
36  }
37
38  extern "C" int foobarm(int a, A ap, int (A::*pf)(int a)) {
39    return (ap.*pf)(a);
40  }
41
42  template <class T>
43    T foo_T(T a) 
44    {
45      return a;
46    }
47
48  template <class T>
49    T foo_T(T a, T b) 
50    {
51      return a + b;
52    }
53
54
55  template <class T>
56  T foobar_T(T a, T (*pf)(T a)) {
57    return pf(a);
58  }
59
60  template <class T>
61  const T& ident(const T& x) {
62    return x;
63  }
64%}
65
66%template(foo_i) foo_T<int>;
67%template(foobar_i) foobar_T<int>;
68
69%template(foo_d) foo_T<double>;
70%template(foobar_d) foobar_T<double>;
71
72%template(ident_d) ident<double>;