File: csharp_typemaps.i

package info (click to toggle)
swig2.0 2.0.7-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 31,260 kB
  • sloc: cpp: 49,839; ansic: 25,403; java: 8,412; python: 6,579; cs: 5,773; yacc: 5,158; makefile: 5,098; sh: 4,806; ruby: 3,673; perl: 2,384; lisp: 1,741; php: 1,701; tcl: 971; ml: 619; xml: 85
file content (119 lines) | stat: -rw-r--r-- 2,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
%module csharp_typemaps

// Test the C# types customisation by modifying the default char * typemaps to return a single char

%typemap(ctype, out="char /*ctype out override*/") char * "char *"
%typemap(imtype, out="char /*imtype out override*/") char * "string"
%typemap(cstype, out="char /*cstype out override*/") char * "string"

%typemap(out) char * %{
  // return the 0th element rather than the whole string
  $result = SWIG_csharp_string_callback($1)[0];
%}

%typemap(csout, excode=SWIGEXCODE) char * {
    char ret = $imcall;$excode
    return ret;
  }

%typemap(csvarout, excode=SWIGEXCODE2) char * %{
    get {
      char ret = $imcall;$excode
      return ret;
    } %}

%inline %{
namespace Space {
    class Things {
    public:
        char* start(char *val) { return val; }
        static char* stop(char *val) { return val; }
    };
    char* partyon(char *val) { return val; }
}
%}


// Test variables when ref is used in the cstype typemap - the variable name should come from the out attribute if specified
%typemap(cstype) MKVector, const MKVector& "MKVector"
%typemap(cstype, out="MKVector") MKVector &, MKVector * "ref MKVector"

%inline %{
struct MKVector {
};
struct MKRenderGameVector {
  MKVector memberValue;
  static MKVector staticValue;
};
MKVector MKRenderGameVector::staticValue;
MKVector globalValue;
%}


// Number and Obj are for the eager garbage collector runtime test
%inline %{
struct Number {
  Number(double value) : Value(value) {}
  double Value;
};

class Obj {
public:
  Number triple(Number n) {
    n.Value *= 3;
    return n;
  }
  Number times6(const Number& num) {
    Number n(num);
    n.Value *= 6;
    return n;
  }
  Number times9(const Number* num) {
    Number n(*num);
    n.Value *= 9;
    return n;
  }
};
Number quadruple(Number n) {
    n.Value *= 4;
    return n;
};
Number times8(const Number& num) {
    Number n(num);
    n.Value *= 8;
    return n;
};
Number times12(const Number* num) {
    Number n(*num);
    n.Value *= 12;
    return n;
};
%}

// Test $csinput expansion
%typemap(csvarin, excode=SWIGEXCODE2) int %{
    set {
      if ($csinput < 0)
        throw new ApplicationException("number too small!");
      $imcall;$excode
    } %}

%inline %{
int myInt = 0;
%}


// Illegal special variable crash
%typemap(cstype) WasCrashing "$csclassname /*cstype $*csclassname*/" // $*csclassname was causing crash
%inline %{
struct WasCrashing {};
void hoop(WasCrashing was) {}
%}


// Enum underlying type
%typemap(csbase) BigNumbers "uint"
%inline %{
enum BigNumbers { big=0x80000000, bigger };
%}