python - How to use SWIG to wrap a C++ operator[] in a template class inside a namespace? -
i'm using swig wrap existing c++ library using header files. library uses namespace , template class create arrays of custom objects. i'm running problems trying wrap subscript operator (operator[]) used access elements inside wrapped arrays. swig tells me operator[] ignored , should use %extend instead:
small.i:18: warning 389: operator[] ignored (consider using %extend)
so i'm trying use extend no matter syntax i've tried, can't inserted code show in _wrap.cxx file. here's swig input file:
%module tltest %{ ... %} namespace nite { template <class t> class array { public: %rename(__getitem__) operator[]; const t& operator[](int index) const {return m_data[index];} %rename(__len__) getsize; int getsize() const {return m_size;} }; class userdata : private niteuserdata { public: }; %template(userdataarray) array<userdata>; }; %extend array<userdata> { userdata& __getitem__(unsigned int i) { return $self[i]; } }
i know want define __getitem__
function python able index array class. note __len__
function renamed correctly, , works python interface.
however, %extend block added define __getitem__
call not ever seem injected small_wrap.cxx wrapper file. can see i'm doing wrong?
aha! discovered need qualify types using namespace in %extend block, follows:
%extend nite::array<nite::userdata> { nite::userdata __getitem__(unsigned int i) { return (*($self))[i]; } }
Comments
Post a Comment