From: charlie <cha...@gm...> - 2009-04-17 00:24:46
|
Hi, William Thanks for replying. I may made some typos and omitted some part of the interface file when I am making up the example. I do have a %include in "test.h". so maybe just let me explain the thing accurately again and paste all contents of all files of this simple example here below: --test.i-- *%module test %{ #include "test.h" %} %include "test.h" %template(u1A) A<UUM1>; %template(v1A) A<VOM1>; %template(u2A) A<UUM2>;* --test.h-- *#include <vector> #include <map> #include <tr1/unordered_map> using namespace std; //using namespace std::tr1; // would cause 'nothing known about namespace std::tr' error typedef tr1::unordered_map<int, double> UM; typedef tr1::unordered_map<int, UM> UUM1; // nested way(1), this doesn't work typedef tr1::unordered_map<int, tr1::unordered_map<int, double> > UUM2; // nested way(2), this works typedef map<int, double> OM; typedef vector<OM> VOM1; // nested way(1), here this works UUM1 get_UUM1(){ return UUM1(); }; UUM2 get_UUM2(){ return UUM2(); }; VOM1 get_VOM1(){ return VOM1(); }; template <class M> class A{ public: M a; A( M m ): a(m){ }; ~A() { }; };* -- in python -- >>> import test >>> uum1=test.get_UUM1() >>> uum2=test.get_UUM2() >>> vom1=test.get_VOM1() >>> print uum1 <Swig Object of type 'UUM1 *' at 0xb7ba4440> >>> print uum2 <Swig Object of type 'tr1::unordered_map< int,tr1::unordered_map< int,double > > *' at 0xb7ba43e0> >>> print vom1 <Swig Object of type 'VOM1 *' at 0xb7ba4440> >>> a=test.u1A(uum1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "test.py", line 95, in __init__ this = _test.new_u1A(*args) TypeError: in method 'new_u1A', argument 1 of type 'tr1::unordered_map< int,tr1::unordered_map< int,double > >' >>> a=test.v1A(vom1) >>> a=test.u2A(uum2) -- compling with namespace std::tr1 used -- *python setup.py build_ext --inplace --force running build_ext building '_test' extension swigging test.i to test_wrap.cpp swig -python -c++ -modern -o test_wrap.cpp test.i test.h:5: Error: Nothing known about namespace 'std::tr1' error: command 'swig' failed with exit status 1* I think you can reproduce the error by using the above two files. Did you mean I shall include the <tr1/unordered_map> file like in the %{ #include "tr1/unordered_map.h" %} and then %include "tr1/unordered_map.h"? Is this the correct way to do? Thanks Charlie On Wed, Apr 15, 2009 at 4:28 PM, William S Fulton <ws...@fu...>wrote: |