2012-03-19 11:21:29 +00:00
|
|
|
/* DLIST python iteration code, to allow standard iteration over DLIST */
|
|
|
|
|
|
|
|
%extend DLIST
|
|
|
|
{
|
|
|
|
%pythoncode
|
|
|
|
{
|
|
|
|
class DLISTIter:
|
|
|
|
def __init__(self,aList):
|
2012-07-06 19:10:55 +00:00
|
|
|
self.last = aList # last item is the start of list
|
2012-03-19 11:21:29 +00:00
|
|
|
|
2012-07-06 19:10:55 +00:00
|
|
|
def next(self): # get the next item
|
2012-03-19 11:21:29 +00:00
|
|
|
|
|
|
|
item = self.last
|
|
|
|
try:
|
|
|
|
item = item.Get()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2012-07-06 19:10:55 +00:00
|
|
|
if item is None: # if the item is None, then finish the iteration
|
2012-03-19 11:21:29 +00:00
|
|
|
raise StopIteration
|
|
|
|
else:
|
|
|
|
ret = None
|
|
|
|
|
|
|
|
# first item in list has "Get" as a DLIST
|
|
|
|
try:
|
|
|
|
ret = self.last.Get()
|
|
|
|
except:
|
2012-07-06 19:10:55 +00:00
|
|
|
ret = self.last # next items do not..
|
2012-03-19 11:21:29 +00:00
|
|
|
|
|
|
|
self.last = self.last.Next()
|
|
|
|
|
|
|
|
# when the iterated object can be casted down in inheritance, just do it..
|
2012-07-06 19:10:55 +00:00
|
|
|
|
2012-03-19 11:21:29 +00:00
|
|
|
if 'Cast' in dir(ret):
|
|
|
|
ret = ret.Cast()
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self.DLISTIter(self)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|