import source from 1.3.40
[external/swig.git] / Examples / test-suite / template.i
1 /* File : example.i */
2 %module "template"
3
4 %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<int>;         /* Ruby, wrong class name */
5 %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<double>;      /* Ruby, wrong class name */
6 %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<int (*)[10]>; /* Ruby, wrong class name */
7
8 /* Let's just grab the original header file here */
9
10 %{
11 #ifdef max
12 #undef max
13 #endif
14 %}
15
16 %inline %{
17
18 template<class T> T max(const T a, const T b) { return  a>b ? a : b; }
19
20 template<class T> class vector {
21   T *v;
22   int sz;
23  public:
24   vector(int _sz) {
25     v = new T[_sz];
26     sz = _sz;
27   }
28   T &get(int index) {
29     return v[index];
30   }
31   void set(int index, T &val) {
32     v[index] = val;
33   }
34   // This really doesn't do anything except test const handling 
35   void testconst(const T x) { }
36 };
37
38 %}
39
40 /* Now instantiate some specific template declarations */
41
42 %template(maxint) max<int>;
43 %template(maxdouble) max<double>;
44 %template(vecint) vector<int>;
45 %template(vecdouble) vector<double>;
46
47 /* Now try to break constness */
48
49 %template(maxintp) max<int (*)[10]>;
50 %template(vecintp) vector<int (*)[10]>;
51
52