1 %module(directors="1") director_stl 2 #pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR 3 4 %include "std_string.i" 5 %include "std_pair.i" 6 %include "std_vector.i" 7 8 #ifndef SWIG_STD_DEFAULT_INSTANTIATION 9 %template() std::vector<double>; 10 %template() std::vector<int>; 11 %template() std::vector<std::string>; 12 %template() std::pair<std::string, int>; 13 %template() std::pair<int,double>; 14 %template() std::pair<double,int>; 15 #endif 16 17 %feature("director") Foo; 18 19 %feature("director:except") { 20 #ifndef SWIGPHP 21 if ($error != NULL) { 22 #else 23 if ($error == FAILURE) { 24 #endif 25 throw Swig::DirectorMethodException(); 26 } 27 } 28 29 %exception { 30 try { $action } catch(...)31 catch (...) { SWIG_fail; } 32 } 33 34 %inline 35 { 36 class Foo { 37 public: ~Foo()38 virtual ~Foo() {} 39 bar(std::string & s)40 virtual std::string& bar(std::string& s) 41 { 42 return s; 43 } 44 45 46 virtual std::string ping(std::string s) = 0; pong(const std::string & s)47 virtual std::string pong(const std::string& s) 48 { return std::string("Foo::pong:") + s + ":" + ping(s); } 49 tping(std::string s)50 std::string tping(std::string s) { return ping(s); } tpong(const std::string & s)51 std::string tpong(const std::string& s) { return pong(s); } 52 53 virtual std::pair<double, int> pident(const std::pair<double,int> & p)54 pident(const std::pair<double, int>& p) { return p; } 55 56 virtual std::vector<int> vident(const std::vector<int> & p)57 vident(const std::vector<int>& p) { return p; } 58 59 virtual std::vector<int> vsecond(const std::vector<int> & p,const std::vector<int> & s)60 vsecond(const std::vector<int>& p, const std::vector<int>& s) { return s; } 61 62 std::pair<double, int> tpident(const std::pair<double,int> & p)63 tpident(const std::pair<double, int>& p) { return pident(p); } 64 65 std::vector<int> tvident(const std::vector<int> & p)66 tvident(const std::vector<int>& p) { return vident(p); } 67 68 virtual std::vector<int> tvsecond(const std::vector<int> & p,const std::vector<int> & s)69 tvsecond(const std::vector<int>& p, const std::vector<int>& s) { return vsecond(p,s); } 70 71 72 virtual std::vector<std::string> vidents(const std::vector<std::string> & p)73 vidents(const std::vector<std::string>& p) { return p; } 74 75 std::vector<std::string> tvidents(const std::vector<std::string> & p)76 tvidents(const std::vector<std::string>& p) { return vidents(p); } 77 78 }; 79 80 } 81