allows local list:TListF = new TListF for blah = eachin list.From(start:TLink,howMany:int)
SuperStrict
Type TListF Extends TList
Method From:TEnumerator( start:TLink, howMany:Int )
Local e:TFromEnum = New TFromEnum
e._link = start
e._howMany = howMany
Local enum:TEnumerator = New TEnumerator
enum.enumerator = e
Return enum
End Method
End Type
Type TFromEnum
Field _link:TLink
Field _howMany:Int
Method HasNext:Int()
Return (_link._value<>_link) And _howMany
End Method
Method NextObject:Object()
Local value:Object=_link._value
Assert value<>_link
_link=_link._succ
_howMany:-1
Return value
End Method
End Type
Type TEnumerator
Field enumerator:TFromEnum
Method ObjectEnumerator:TFromEnum()
Return enumerator
End Method
End Type
' TEST PROGRAM
'Rem
Type t
Global gid:Int = 0
Global list:TListF = New TListF
Field id:Int
Field link:TLink
Method New()
id = gid
gid :+ 1
link = list.AddLast(Self)
End Method
End Type
Local start:TLink
'create 16 of type t and record one in 'start'
For Local i:Int=0 To 15
Local tmp:t = New t
If tmp.id = 5 Then start=tmp.link
Next
Print "~nthe whole list the normal way"
For Local i:t = EachIn t.list
Print i.id
Next
Print "~n5 from the start TLink "
For Local i:t = EachIn t.list.From(start,5)
Print ">"+i.id
Next
Print "~nall from the start TLink "
For Local i:t = EachIn t.list.From(start,-1)
Print ">"+i.id
Next
'end rem
|