From: Eric S. <ras...@ce...> - 2005-12-06 14:19:48
|
Searching the net I found some old posts (had to use Google cache) about std_list for c#. I have managed to convert std_vector to use std::list, and got it to work. Only had a problem with std_vector, and had to make a change. It uses =93const CTYPE&=94 in a few places, I had to change that to just =93CTYPE= =94. The const & is giving me problems when I have a vector of pointers, like std::vector<cVal*>. I want to know if this is a bug or maybe a problem with my pointer typemape. But the changes to std_vector and my std_list work. Here is the typemape: //pointer reference typemaps: %define PTR_REF_TYPEMAPS(CSTYPE, CTYPE) #if defined(SWIGCSHARP) %typemap(ctype) CTYPE *, CTYPE & "void *" %typemap(imtype) CTYPE *, CTYPE & "IntPtr" %typemap(cstype) CTYPE *, CTYPE & "CSTYPE" %typemap(csin) CTYPE *, CTYPE & "CSTYPE.getCPtr($csinput)" %typemap(csout) CTYPE *, CTYPE & { IntPtr cPtr =3D $imcall; return (cPtr =3D=3D IntPtr.Zero) ? null : new CSTYPE(cPtr, $owner); } %typemap(in) CTYPE *, CTYPE & %{ $1 =3D (CTYPE *)$input; %} %typemap(out) CTYPE *, CTYPE & %{ $result =3D (void *)$1; %} #endif %enddef Defining the template: PTR_REF_TYPEMAPS(cVal, eTestLib::cVal*) SWIG_STD_VECTOR_SPECIALIZE(cVal, eTestLib::cVal*) %template(VectorcVal) std::vector< eTestLib::cVal* >; What I=92m Swigging: namespace eTestLib { class _LibExport cVal { protected: int mMyVal; public: cVal(int n); int getMyVal(); void setMyVal(int newval); }; typedef std::list<cVal*> cValList; typedef std::vector<cVal*> cValVec; class _LibExport cTest { protected: cValList mList; cValVec mVec; public: cTest(); ~cTest(); void addListItem (int v); int getListItem(int index); cValList& getListList(); void addVectorItem (int v); int getVectorItem(int index); cValVec& getVectorVector(); }; } And the Compile errors with unmodified std_vector.i : c:\ericTemp\ogre\ogreaddons\eric\swig\test2\Swigdll2\test_wrap.cxx(389) : error C2440: '=3D' : cannot convert from 'const eTestLib::cVal *' to 'std::allocator<_Ty>::value_type' with [ _Ty=3DeTestLib::cVal * ] Conversion loses qualifiers c:\ericTemp\ogre\ogreaddons\eric\swig\test2\Swigdll2\test_wrap.cxx(407) : error C2664: 'std::vector<_Ty>::iterator std::vector<_Ty>::insert(std::vector<_Ty>::iterator,const _Ty & )' : cannot convert parameter 2 from 'const eTestLib::cVal *' to 'eTestLib::cVal *const & ' with [ _Ty=3DeTestLib::cVal * ] Conversion loses qualifiers c:\ericTemp\ogre\ogreaddons\eric\swig\test2\Swigdll2\test_wrap.cxx(435) : error C2664: 'std::vector<_Ty>::vector(std::vector<_Ty>::size_type,const _Ty & )' : cannot convert parameter 2 from 'const eTestLib::cVal *' to 'eTestLib::cVal *const & ' with [ _Ty=3DeTestLib::cVal * ] Conversion loses qualifiers c:\ericTemp\ogre\ogreaddons\eric\swig\test2\Swigdll2\test_wrap.cxx(999) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'const eTestLib::cVal *' to 'eTestLib::cVal *const & ' with [ _Ty=3DeTestLib::cVal * ] Conversion loses qualifiers |