January 26, 2021, 12:50:24 PM

### Author Topic: [bmx] TListF by dmaz [ 1+ years ago ]  (Read 514 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bmx] TListF by dmaz [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : TListF
Author : dmaz
Posted : 1+ years ago

Description : it allows
Code: [Select]
`local list:TListF = new TListFfor blah:yourtype = eachin list.From(start:TLink,howMany:int=-1)`or
Code: [Select]
`for blah:yourtype = eachin list.ReverseFrom(start:TLink,howMany:int=-1)`or
Code: [Select]
`for blah:TLink = eachin list.LinksFrom(start:TLink,howMany:int=-1)`
if howMany is -1 then it will continue to the end or the begining as in the case of ReverseFrom. [/i]

Code :
Code: BlitzMax
1. SuperStrict
2.
3. Type TListF Extends TList
4.         Method From:TEnumerator( start:TLink, howMany:Int=-1 )
6.                 e._link = start
7.                 e._howMany = howMany
8.                 Local enum:TEnumerator = New TEnumerator
9.                 enum.enumerator = e
10.                 Return enum
11.         End Method
12.
13.         Method ReverseFrom:TEnumerator( start:TLink, howMany:Int=-1 )
15.                 e._link = start
16.                 e._howMany = howMany
17.                 Local enum:TEnumerator = New TEnumerator
18.                 enum.enumerator = e
19.                 Return enum
20.         End Method
21.
24.                 e._link = start
25.                 e._howMany = howMany
26.                 Local enum:TEnumerator = New TEnumerator
27.                 enum.enumerator = e
28.                 Return enum
29.         End Method
30.
31. End Type
32.
33. Type TEnumerator
35.
37.                 Return enumerator
38.         End Method
39. End Type
40.
43.         Field _howMany:Int
44.
45.         Method HasNext:Int()
47.         End Method
48.
49.         Method NextObject:Object()
53.                 _howMany:-1
54.                 Return value
55.         End Method
56. End Type
57.
59.         Method HasNext:Int()
61.         End Method
62.
63.         Method NextObject:Object()
67.                 _howMany:-1
68.                 Return value
69.         End Method
70. End Type
71.
72.
74.         Method NextObject:Object()
78.                 _howMany:-1
79.                 Return rtn
80.         End Method
81. End Type
82.
83.
84.
85.
86. ' TEST PROGRAM
87. Type t
88.         Global gid:Int  = 0
89.         Global list:TListF = New TListF
90.
91.         Field id:Int
93.
94.         Method New()
95.                 id = gid
96.                 gid :+ 1
98.         End Method
99.
100. End Type
101.
103.
104. 'create 16 of type t and record one in 'start'
105. For Local i:Int=0 To 15
106.         Local tmp:t = New t
107.         If tmp.id = 5 Then start=tmp.link
108. Next
109.
110. Print "~nthe whole list the normal way"
111. For Local i:t = EachIn t.list
112.         Print i.id
113. Next
114.
115. Print "~n5 from the start TLink "
116. For Local i:t = EachIn t.list.From(start,5)
117.         Print ">"+i.id
118. Next
119.
120. Print "~nall from the start TLink "
121. For Local i:t = EachIn t.list.From(start,-1)
122.         Print ">"+i.id
123. Next
124.
125. Print "~nall link from the begining"
127.         Print ">"+i.ToString()+": "+t(i._value).id
128. Next
129.
130. 't.list.Clear
131. Print "~nreverse from last TLink"
132. For Local i:t = EachIn t.list.ReverseFrom(t.list.LastLink())
133.         Print ">"+i.id
134. Next