File: csharp_prepost.i

package info (click to toggle)
swig1.3 1.3.36-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 27,060 kB
  • ctags: 13,774
  • sloc: cpp: 40,816; ansic: 27,565; python: 9,069; java: 6,432; makefile: 5,065; yacc: 4,916; cs: 4,551; sh: 4,071; ruby: 3,760; perl: 3,562; lisp: 1,993; tcl: 1,266; php: 1,026; ml: 708
file content (90 lines) | stat: -rw-r--r-- 2,901 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
%module csharp_prepost

// Test the pre, post and cshin attributes for csin typemaps

%include "std_vector.i"

%define VECTOR_DOUBLE_CSIN_POST
"      int count$csinput = d$csinput.Count;
      $csinput = new double[count$csinput];
      for (int i=0; i<count$csinput; ++i) {
        $csinput[i] = d$csinput[i];
      }"
%enddef

// pre and post in csin typemaps
%typemap(cstype) std::vector<double> &v "out double[]"
%typemap(csin, pre="    DoubleVector d$csinput = new DoubleVector();", post=VECTOR_DOUBLE_CSIN_POST, cshin="out $csinput") std::vector<double> &v
  "$csclassname.getCPtr(d$csinput)"

%apply std::vector<double> & v { std::vector<double> & v2 }

// pre only in csin typemap
%typemap(cstype) std::vector<double> &vpre "ref double[]"
%typemap(csin, pre="    DoubleVector d$csinput = new DoubleVector();\n    foreach (double d in $csinput) {\n      d$csinput.Add(d);\n    }", cshin="ref $csinput") std::vector<double> &vpre
  "$csclassname.getCPtr(d$csinput)"

// post only in csin typemap
%typemap(csin, post="      int size = $csinput.Count;\n      for (int i=0; i<size; ++i) {\n        $csinput[i] /= 100;\n      }") std::vector<double> &vpost
  "$csclassname.getCPtr($csinput)"

%inline %{
bool globalfunction(std::vector<double> & v) {
  v.push_back(0.0);
  v.push_back(1.1);
  v.push_back(2.2);
  return true;
}
struct PrePostTest {
  PrePostTest() {
  }
  PrePostTest(std::vector<double> & v) {
    v.push_back(3.3);
    v.push_back(4.4);
  }
  bool method(std::vector<double> & v) {
    v.push_back(5.5);
    v.push_back(6.6);
    return true;
  }
  static bool staticmethod(std::vector<double> & v) {
    v.push_back(7.7);
    v.push_back(8.8);
    return true;
  }
};

// Check pre and post only typemaps and that they coexist okay and that the generated code line spacing looks okay
bool globalfunction2(std::vector<double> & v, std::vector<double> &v2, std::vector<double> & vpre, std::vector<double> & vpost) {
  return true;
}
struct PrePost2 {
  PrePost2() {
  }
  PrePost2(std::vector<double> & v, std::vector<double> &v2, std::vector<double> & vpre, std::vector<double> & vpost) {
  }
  bool method(std::vector<double> & v, std::vector<double> &v2, std::vector<double> & vpre, std::vector<double> & vpost) {
    return true;
  }
  static bool staticmethod(std::vector<double> & v, std::vector<double> &v2, std::vector<double> & vpre, std::vector<double> & vpost) {
    return true;
  }
};
%}

%template(DoubleVector) std::vector<double>;

// Check attributes in the typemaps
%typemap(cstype, inattributes="[CustomInt]") int val "int"
%typemap(csin, pre="    int tmp_$csinput = $csinput * 100;") int "tmp_$csinput"
%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/"

%inline %{
class CsinAttributes {
  int m_val;
public:
  CsinAttributes(int val) : m_val(val) {}
  int getVal() { return m_val; }
};
%}