import source from 1.3.40
[external/swig.git] / Examples / test-suite / csharp_typemaps.i
1 %module csharp_typemaps
2
3 // Test the C# types customisation by modifying the default char * typemaps to return a single char
4
5 %typemap(ctype, out="char /*ctype out override*/") char * "char *"
6 %typemap(imtype, out="char /*imtype out override*/") char * "string"
7 %typemap(cstype, out="char /*cstype out override*/") char * "string"
8
9 %typemap(out) char * %{
10   // return the 0th element rather than the whole string
11   $result = SWIG_csharp_string_callback($1)[0];
12 %}
13
14 %typemap(csout, excode=SWIGEXCODE) char * {
15     char ret = $imcall;$excode
16     return ret;
17   }
18
19 %typemap(csvarout, excode=SWIGEXCODE2) char * %{
20     get {
21       char ret = $imcall;$excode
22       return ret;
23     } %}
24
25 %inline %{
26 namespace Space {
27     class Things {
28     public:
29         char* start(char *val) { return val; }
30         static char* stop(char *val) { return val; }
31     };
32     char* partyon(char *val) { return val; }
33 }
34 %}
35
36
37 // Test variables when ref is used in the cstype typemap - the variable name should come from the out attribute if specified
38 %typemap(cstype) MKVector, const MKVector& "MKVector"
39 %typemap(cstype, out="MKVector") MKVector &, MKVector * "ref MKVector"
40
41 %inline %{
42 struct MKVector {
43 };
44 struct MKRenderGameVector {
45   MKVector memberValue;
46   static MKVector staticValue;
47 };
48 MKVector MKRenderGameVector::staticValue;
49 MKVector globalValue;
50 %}
51
52
53 // Number and Obj are for the eager garbage collector runtime test
54 %inline %{
55 struct Number {
56   Number(double value) : Value(value) {}
57   double Value;
58 };
59
60 class Obj {
61 public:
62   Number triple(Number n) {
63     n.Value *= 3;
64     return n;
65   }
66   Number times6(const Number& num) {
67     Number n(num);
68     n.Value *= 6;
69     return n;
70   }
71   Number times9(const Number* num) {
72     Number n(*num);
73     n.Value *= 9;
74     return n;
75   }
76 };
77 Number quadruple(Number n) {
78     n.Value *= 4;
79     return n;
80 };
81 Number times8(const Number& num) {
82     Number n(num);
83     n.Value *= 8;
84     return n;
85 };
86 Number times12(const Number* num) {
87     Number n(*num);
88     n.Value *= 12;
89     return n;
90 };
91 %}
92
93 // Test $csinput expansion
94 %typemap(csvarin, excode=SWIGEXCODE2) int %{
95     set {
96       if ($csinput < 0)
97         throw new ApplicationException("number too small!");
98       $imcall;$excode
99     } %}
100
101 %inline %{
102 int myInt = 0;
103 %}