SWIG : unrecognized template type contained in vector
I can't manage to have a valid SWIG output from a definition like this :
std::vector< namespaceA::refPtr< namespaceB::myObj > >
First of all, I have a custom definition of std::vector
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef T value_type;
typedef value_type const& const_reference;
/*
....
*/
%rename(add) push_back;
void push_back( const_reference x);
%extend {
const_reference get(int i) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
return *((T*)NULL);
}
void set(int i, const_reference val) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
}
}
};
}
In the namespace A, there is a template to reference pointers. Let's call it refPtr
.
In the namespace B, there is a ref counted class, called MyObj
.
When I declare a template for a ref counted object, SWIG outputs the correct interface :
%template(MyOb开发者_运维技巧jRefPtr) namespaceA::refPtr< namespaceB::MyObj > // OK
Then I declare my vector :
%template(MyObjRefPtrVector) std::vector< MyObjRefPtr > > // compiles but inner types not resolved
It compiles and SWIG generates four types :
- SWIGTYPE_p_std_vectorTnamespaceA_refPtrTnamespaceB__MyObj_t_t
- SWIGTYPE_p_MyObjRefPtr
- MyObjRefPtr
- MyObjRefPtrVector
The generated class MyObjRefPtr
is ok.
The class MyObjRefPtrVector
was generated but the methods add
, set
and get
take a SWIGTYPE_p_MyObjRefPtr
as parameter, instead of MyObjRefPtr
.
Could someone show me where my code is wrong ? I just can't figure it out...
Instead of
%template(MyObjRefPtrVector) std::vector< MyObjRefPtr > >
the template declaration should be
%template(MyObjRefPtrVector) std::vector< namespaceA::refPtr< namespaceB::MyObj > >
精彩评论