2908
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2009 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
2362
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
Stream subclass:#SelectingReadStream
|
|
15 |
instanceVariableNames:'selectBlock hasReadAhead readAhead inStream'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
2366
|
18 |
category:'Streams-Misc'
|
2362
|
19 |
!
|
|
20 |
|
|
21 |
!SelectingReadStream class methodsFor:'documentation'!
|
|
22 |
|
2908
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2009 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
2362
|
38 |
documentation
|
|
39 |
"
|
|
40 |
A stream which only delivers elements for which a select block returns true
|
|
41 |
from an underlying stream.
|
|
42 |
|
|
43 |
Needs readAhead for proper atEnd handling.
|
|
44 |
|
3271
|
45 |
[Author:]
|
|
46 |
Claus Gittinger
|
|
47 |
|
2362
|
48 |
[instance variables:]
|
|
49 |
hasReadAhead - because nil is a valid read-element,
|
|
50 |
this is used to know if readAhead is valid.
|
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
examples
|
|
55 |
"
|
|
56 |
|s|
|
|
57 |
|
|
58 |
s := SelectingReadStream
|
|
59 |
on:#(1 2 3 4 5 6 7 8) readStream
|
|
60 |
selecting:[:each | each even].
|
|
61 |
s upToEnd
|
|
62 |
"
|
|
63 |
! !
|
|
64 |
|
|
65 |
!SelectingReadStream class methodsFor:'instance creation'!
|
|
66 |
|
|
67 |
on:aStream selecting:aBlock
|
|
68 |
^ self basicNew on:aStream selecting:aBlock
|
|
69 |
! !
|
|
70 |
|
|
71 |
!SelectingReadStream methodsFor:'instance creation'!
|
|
72 |
|
|
73 |
on:aStream selecting:aBlock
|
|
74 |
inStream := aStream.
|
|
75 |
selectBlock := aBlock.
|
|
76 |
hasReadAhead := false.
|
|
77 |
! !
|
|
78 |
|
|
79 |
!SelectingReadStream methodsFor:'queries'!
|
|
80 |
|
|
81 |
atEnd
|
|
82 |
|el|
|
|
83 |
|
|
84 |
hasReadAhead ifTrue:[^ false].
|
|
85 |
|
|
86 |
[
|
|
87 |
inStream atEnd ifTrue:[
|
|
88 |
^ true
|
|
89 |
].
|
|
90 |
el := inStream next.
|
|
91 |
(selectBlock value:el)
|
|
92 |
] whileFalse.
|
|
93 |
readAhead := el.
|
|
94 |
hasReadAhead := true.
|
|
95 |
^ false.
|
3091
|
96 |
!
|
|
97 |
|
|
98 |
contentsSpecies
|
|
99 |
"return a class of which instances will be returned, when
|
|
100 |
parts of the collection are asked for.
|
|
101 |
(see upTo-kind of methods in Stream)"
|
|
102 |
|
|
103 |
^ inStream contentsSpecies.
|
2362
|
104 |
! !
|
|
105 |
|
|
106 |
!SelectingReadStream methodsFor:'reading'!
|
|
107 |
|
|
108 |
next
|
|
109 |
|el|
|
|
110 |
|
|
111 |
hasReadAhead ifTrue:[
|
|
112 |
hasReadAhead := false.
|
|
113 |
^ readAhead
|
|
114 |
].
|
|
115 |
[
|
|
116 |
inStream atEnd ifTrue:[
|
|
117 |
^ self pastEndRead
|
|
118 |
].
|
|
119 |
el := inStream next.
|
|
120 |
(selectBlock value:el)
|
|
121 |
] whileFalse.
|
|
122 |
^ el
|
|
123 |
! !
|
|
124 |
|
|
125 |
!SelectingReadStream class methodsFor:'documentation'!
|
|
126 |
|
|
127 |
version_CVS
|
3271
|
128 |
^ '$Header: /cvs/stx/stx/libbasic2/SelectingReadStream.st,v 1.5 2014-04-30 18:20:55 cg Exp $'
|
2362
|
129 |
! !
|
2908
|
130 |
|