c++ - Swig: SWIG_NewPointerObj and Typemaps -


i'm working on qt-application , use swig generate python bindings public api.

i trying implement signal/slots in swig , embedding python final app. in end boils down simple function, swig seems miss or haven't found yet:

pyobject* createpyobject(qstring typename, bool passownership, void* obj)

requirements

the function should create pyobject passed obj. whereas typename type of instance obj points , passownership specifies whether or not object should owned python interpreter afterwards. function should:

  1. apply out-typemap passed type, if exists
  2. otherwise wrap object "swig proxy object of type ..." if possible
  3. and if that's not possible should return "swig object of type ..."

example

let's have 3 classes:

  • class a1 have out-typemap convert instances of class python-integers.
  • class a2 have out-typemap convert instances of class python-tuples.
  • class b have wrapped using swig interface file
  • class c unknown swig.

then createpyobject should

  • return pyintobject* if it's invoked createpyobj("a1",true,new a1())
  • return pytupleobject* if it's invoked createpyobj("a2",true,new a2())
  • return proxy of <swig object of type 'b*'> if it's invoked createpyobj("b",true,new b())
  • return swig object of type 'c*' if it's invoked createpyobj("c",true,new c())

so summarize: want returned pyobject constructed if return value of function wrapped using swig interface file.

my current implementation

pyobject* createpyobject(qstring typename, bool passownership, void* obj) {      typename += " *"; //pointer symbol     swig_type_info* info = swig_typequery(typename.tostdstring().c_str());      if (info == nullptr) return nullptr;      return swig_newpointerobj(obj, info, passownership ? swig_pointer_own : 0); } 

this works fine types require no typemap , known swig (point 2 in requirements). doesn't work types require typemap.

could provide me correct implementation of createpyobject ? correct mean, 1 meets requirements listed above.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -