add case of vector + pointer +templates from Bo Peng
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7047 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d7a45cd7a1
commit
60a06a78d9
1 changed files with 64 additions and 0 deletions
64
SWIG/Examples/test-suite/python/simutry.i
Normal file
64
SWIG/Examples/test-suite/python/simutry.i
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
%module simutry
|
||||
|
||||
%include "std_vector.i"
|
||||
|
||||
%inline
|
||||
{
|
||||
#include <iostream>
|
||||
|
||||
namespace simuPOP
|
||||
{
|
||||
// some simple pop class
|
||||
struct pop {
|
||||
int m_a;
|
||||
pop(int a):m_a(a){}
|
||||
};
|
||||
|
||||
// base operator, output pop.m_a
|
||||
template<class Pop>
|
||||
struct Operator
|
||||
{
|
||||
Pop m_pop;
|
||||
Operator(int a):m_pop(a){}
|
||||
virtual void func() const
|
||||
{ std::cout << m_pop.m_a << std::endl; }
|
||||
};
|
||||
|
||||
// derived operator, output double of pop.m_a
|
||||
template<class Pop>
|
||||
struct DerivedOperator: public Operator<Pop>
|
||||
{
|
||||
DerivedOperator(int a):Operator<Pop>(a){}
|
||||
virtual void func() const
|
||||
{ std::cout << 2*this->m_pop.m_a << std::endl; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace simuPOP
|
||||
{
|
||||
%template(baseOperator) Operator< pop >;
|
||||
%template(derivedOperator) DerivedOperator< pop >;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(vectorop) vector< simuPOP::Operator<simuPOP::pop> * >;
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
namespace simuPOP
|
||||
{
|
||||
// test function, use of a vector of Operator*
|
||||
void test( const std::vector< Operator<pop>*>& para)
|
||||
{
|
||||
for( size_t i =0; i < para.size(); ++i)
|
||||
para[i]->func();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue