From: Dana Jansens Date: Mon, 17 Feb 2003 11:49:35 +0000 (+0000) Subject: return a Python list of Client*'s when a std::list is returned X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=a7d17188a4d98ec9a30bf980079fd12f8313d9b3;p=chaz%2Fopenbox return a Python list of Client*'s when a std::list is returned --- diff --git a/wrap/ob.i b/wrap/ob.i index ba59d4d3..fa2d020e 100644 --- a/wrap/ob.i +++ b/wrap/ob.i @@ -16,8 +16,6 @@ %} %include "stl.i" -//%include std_list.i -//%template(ClientList) std::list; %include "callback.i" %immutable ob::openbox; @@ -28,23 +26,19 @@ %}; */ -%ignore ob::Screen::clients; -%{ - #include -%} -%extend ob::Screen { - Client *client(int i) { - if (i < 0 || i >= (int)self->clients.size()) - return NULL; - ob::Client::List::iterator it = self->clients.begin(); - std::advance(it,i); - return *it; - } - int clientCount() const { - return (int) self->clients.size(); - } -}; - +%typemap(python,out) std::list { + unsigned int s = $1.size(); + PyObject *l = PyList_New(s); + + std::list::const_iterator it = $1.begin(), end = $1.end(); + for (unsigned int i = 0; i < s; ++i, ++it) { + PyObject *pdata = SWIG_NewPointerObj((void *) *it, + SWIGTYPE_p_ob__Client, 0); + PyList_SET_ITEM(l, i, pdata); + } + $result = l; +} + // do this through events %ignore ob::Screen::showDesktop(bool);