[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyKDE] Request for more SIP features
From: Gerard Vermeulen <gerard.vermeulen () grenoble ! cnrs ! fr>
Date: 2004-11-26 6:18:56
Message-ID: 20041126071856.4156c4a3.gerard.vermeulen () grenoble ! cnrs ! fr
[Download RAW message or body]
Easy ones first:
(1) an uninstall target in the Makefile to undo the work of the install target
(2) the enums wrapped by SIP are mutable, but Python has the facility to define real \
constants:
> > > import termios
> > > print termios.B110
3
> > > termios.B110 = 0
> > > print termios.B110
0
> > >
(3) support for iterators. Motivation: I started to experiment with SIP template \
files to wrap the STL. Of course, an iterator is not needed to traverse a \
std::vector, but a Python iterator can remember the C++ pointer into a more advanced \
container while returning a Python object. A naive approach does not work:
SIP file snippet:
class CellIterator
{
%TypeHeaderCode
#include <vector>
#include <sipIterCell.h>
class CellIterator
{
public:
CellIterator(Cell &cell): it(cell.begin()) {};
CellIterator * __iter__() { return this; }
int next() { return *it++; }
private:
Cell::iterator it;
};
%End
public:
CellIterator(Cell &);
int next();
CellIterator * __iter__();
};
Python interpreter (this would work for a Python class which implements __iter__() \
and next():
> > > import Iter
> > > c = Iter.Cell()
> > > c.push_back(0)
> > > c.push_back(1)
> > > for i in c: print i
...
0
1
> > > it = Iter.CellIterator(c)
> > > dir(it)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', \
'__iter__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', \
'__setattr__', '__str__', '__weakref__', 'next']
> > > for i in it: print i
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iteration over non-sequence
> > >
Gerard
_______________________________________________
PyKDE mailing list PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic