1 %module simutry 2 3 %include "std_vector.i" 4 5 %inline { 6 7 namespace simuPOP 8 { 9 // some simple pop class 10 template <class Type> 11 struct Population { 12 int m_a; PopulationPopulation13 Population(int a):m_a(a){} 14 }; 15 16 // base operator, output pop.m_a 17 template<class Pop> 18 struct Operator 19 { 20 Pop m_pop; OperatorOperator21 Operator(int a):m_pop(a){} ~OperatorOperator22 virtual ~Operator() 23 { 24 } 25 funkOperator26 virtual int funk() const 27 { return m_pop.m_a; } 28 }; 29 30 // derived operator, output double of pop.m_a 31 template<class Pop> 32 struct DerivedOperator: public Operator<Pop> 33 { DerivedOperatorDerivedOperator34 DerivedOperator(int a):Operator<Pop>(a){} funkDerivedOperator35 virtual int funk() const 36 { return 2*this->m_pop.m_a; } 37 }; 38 39 } 40 41 } 42 43 #if 1 44 namespace simuPOP 45 { 46 %template(population) Population< std::pair<unsigned long,unsigned long> >; 47 } 48 49 %inline 50 { 51 namespace simuPOP 52 { 53 typedef Population< std::pair<unsigned long,unsigned long> > pop; 54 } 55 } 56 #else 57 %inline 58 { 59 namespace simuPOP 60 { 61 // %template(population) Population< std::pair<unsigned long,unsigned long> >; 62 63 struct pop { 64 int m_a; poppop65 pop(int a):m_a(a){} 66 }; 67 } 68 } 69 #endif 70 71 72 namespace simuPOP 73 { 74 %template(baseOperator) Operator< pop >; 75 %template(derivedOperator) DerivedOperator< pop >; 76 } 77 78 79 80 namespace std 81 { 82 %template(vectorop) vector< simuPOP::Operator<simuPOP::pop> * >; 83 } 84 85 %inline 86 { 87 namespace simuPOP 88 { 89 // test function, use of a vector of Operator* test(const std::vector<Operator<pop> * > & para)90 void test( const std::vector< Operator<pop>*>& para) 91 { 92 for( size_t i =0; i < para.size(); ++i) 93 para[i]->funk(); 94 } 95 } 96 } 97 98 99