1 %module li_attribute_template 2 3 %include <exception.i> 4 5 //#define SWIG_ATTRIBUTE_TEMPLATE 6 %include <attribute.i> 7 %include <std_string.i> 8 9 %inline 10 { 11 class Foo { 12 public: Foo(int _value)13 Foo( int _value ) { value = _value; } 14 int value; 15 }; 16 17 template< class T1, class T2> 18 struct pair{ pairpair19 pair( T1 t1, T2 t2 ): 20 first(t1), second(t2) {;} 21 22 T1 first; 23 T2 second; 24 }; 25 26 template< class T1, class T2> 27 struct C 28 { CC29 C(int a, int b, int c) : 30 a(a), b(b), c(c), d(a), _e(b), 31 _f(a,b), _g(b,c) 32 { 33 34 /* 35 _f.first = a; 36 _f.second = b; 37 38 _g.first = b; 39 _g.second = c; 40 */ 41 42 } 43 get_valueC44 int get_value() const 45 { 46 return a; 47 } 48 set_valueC49 void set_value(int aa) 50 { 51 a = aa; 52 } 53 54 /* only one ref method */ get_refC55 int& get_ref() 56 { 57 return b; 58 } 59 get_class_valueC60 Foo get_class_value() const { return d; } set_class_valueC61 void set_class_value( Foo foo) { d = foo; } 62 get_class_refC63 const Foo& get_class_ref() const { return _e; } set_class_refC64 void set_class_ref( const Foo& foo ) { _e = foo; } 65 get_template_valueC66 pair<T1,T2> get_template_value() const { return _f; } set_template_valueC67 void set_template_value( const pair<T1,T2> f ) { _f = f; } 68 get_template_refC69 const pair<T1,T2>& get_template_ref() const { return _g; } set_template_refC70 void set_template_ref( const pair<T1,T2>& g ) { _g = g; } 71 get_stringC72 std::string get_string() { return str; } set_stringC73 void set_string(std::string other) { str = other; } 74 75 private: 76 int a; 77 int b; 78 int c; 79 Foo d; 80 Foo _e; 81 pair<T1,T2> _f; 82 pair<T1,T2> _g; 83 84 std::string str; 85 }; 86 87 } 88 89 %define %instantiate_C( T1, T2 ) 90 %template (pair_ ## T1 ## T2 ) pair<T1,T2>; 91 // Primitive types 92 %attribute( %arg(C<T1,T2>), int, a, get_value, set_value ); 93 %attributeref( %arg(C<T1,T2>), int, b, get_ref ); 94 95 // Strings 96 %attributestring(%arg(C<T1,T2>), std::string, str, get_string, set_string); 97 98 // Class types 99 %attributeval( %arg(C<T1,T2>), Foo, d, get_class_value, set_class_value ); 100 %attribute2( %arg(C<T1,T2>), Foo, e, get_class_ref, set_class_ref ); 101 102 // Moderately templated types 103 %attributeval( %arg(C<T1,T2>), %arg(pair<T1,T2>), f, get_template_value, set_template_value ); 104 %attribute2( %arg(C<T1,T2>), %arg(pair<T1,T2>), g, get_template_ref, set_template_ref ); 105 106 %template (C ## T1 ## T2) C<T1,T2>; 107 %enddef 108 109 110 %instantiate_C(int,int); 111