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
|
%module li_attribute_template
%include <exception.i>
//#define SWIG_ATTRIBUTE_TEMPLATE
%include <attribute.i>
%include <std_string.i>
%inline
{
class Foo {
public:
Foo( int _value ) { value = _value; }
int value;
};
template< class T1, class T2>
struct pair{
pair( T1 t1, T2 t2 ):
first(t1), second(t2) {;}
T1 first;
T2 second;
};
template< class T1, class T2>
struct C
{
C(int a, int b, int c) :
a(a), b(b), c(c), d(a), _e(b),
_f(a,b), _g(b,c)
{
/*
_f.first = a;
_f.second = b;
_g.first = b;
_g.second = c;
*/
}
int get_value() const
{
return a;
}
void set_value(int aa)
{
a = aa;
}
/* only one ref method */
int& get_ref()
{
return b;
}
Foo get_class_value() const { return d; }
void set_class_value( Foo foo) { d = foo; }
const Foo& get_class_ref() const { return _e; }
void set_class_ref( const Foo& foo ) { _e = foo; }
pair<T1,T2> get_template_value() const { return _f; }
void set_template_value( const pair<T1,T2> f ) { _f = f; }
const pair<T1,T2>& get_template_ref() const { return _g; }
void set_template_ref( const pair<T1,T2>& g ) { _g = g; }
std::string get_string() { return str; }
void set_string(std::string other) { str = other; }
private:
int a;
int b;
int c;
Foo d;
Foo _e;
pair<T1,T2> _f;
pair<T1,T2> _g;
std::string str;
};
}
%define %instantiate_C( T1, T2 )
%template (pair_ ## T1 ## T2 ) pair<T1,T2>;
// Primitive types
%attribute( %arg(C<T1,T2>), int, a, get_value, set_value );
%attributeref( %arg(C<T1,T2>), int, b, get_ref );
// Strings
%attributestring(%arg(C<T1,T2>), std::string, str, get_string, set_string);
// Class types
%attributeval( %arg(C<T1,T2>), Foo, d, get_class_value, set_class_value );
%attribute2( %arg(C<T1,T2>), Foo, e, get_class_ref, set_class_ref );
// Moderately templated types
%attributeval( %arg(C<T1,T2>), %arg(pair<T1,T2>), f, get_template_value, set_template_value );
%attribute2( %arg(C<T1,T2>), %arg(pair<T1,T2>), g, get_template_ref, set_template_ref );
%template (C ## T1 ## T2) C<T1,T2>;
%enddef
%instantiate_C(int,int);
|