summaryrefslogtreecommitdiff
path: root/tnslc/iterator.tnsl
blob: 19dda8cea7b994a0309f503c46cbbe99da332564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
struct Iterator {
	~void data,
	int size,
		current,
		_elsz
}

/; method Iterator
	
	/; init (~void data, int count, int elsz)
		self.data = data
		self.size = size
		self._elsz = elsz
		self.current = 0
	;/

	/; next (int count)
		self.current = self.current + count
		/; if (self.current >= self.size)
			self.current = self.size
		;/
	;/

	/; prev (int count)
		self.current = self.current - count
		/; if (self.current < 0)
			self.current = 0
		;/
	;/

	/; get [~void]
		return self.data + current * _elsz
	;/

	/; end [bool]
		return self.current >= self.size
	;/

;/