converting a vector of C++ objects to a list of built-in python objects
"Langer, Stephen A. \(Fed\) via Swig-user" <[email protected]> Wed, 25 May 2022 20:55:30 +0000
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
Hi --
What's the best way to convert a vector of C++ objects to a list of built-in Python objects? When not using -builtin, I've been doing this:
%{
typedef std::vector<SomeClass> Vec;
%}
%typemap(out) Vec* {
Vec::size_type sz = $1->size();
$result = PyList_New((Py_ssize_t) sz);
for(Vec::size_type i=0; i<sz; i++) {
PyObject *tmp = SWIG_NewPointerObj(SWIG_as_voidptr((*$1)[i]),
$descriptor(SomeClass*),
SWIG_POINTER_OWN);
PyList_SET_ITEM($result, (Py_ssize_t) I, tmp);
}
}
That doesn’t work when using -builtin, because then the SWIG_NewPointerObj requires "self" to be defined.
Thanks for any suggestions.
-- Steve
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user