author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 15:23:19 +0100 | |
changeset 624 | f09ad5cf21d4 |
parent 611 | 80bb0f1a7bab |
child 701 | a309e3ef7faf |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
12 |
||
57 | 13 |
PeekableStream subclass:#PositionableStream |
611 | 14 |
instanceVariableNames:'collection position readLimit writeLimit' |
15 |
classVariableNames:'ErrorDuringFileInSignal ChunkSeparator' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Streams' |
|
1 | 18 |
! |
19 |
||
88 | 20 |
!PositionableStream class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
10 | 35 |
|
88 | 36 |
documentation |
37 |
" |
|
38 |
Instances of PositionableStream allow positioning the read pointer. |
|
39 |
The PositionableStream class also adds methods for source-chunk reading |
|
40 |
and writing, and for filing-in/out of source code. |
|
41 |
This is an abstract class. |
|
42 |
" |
|
611 | 43 |
! |
44 |
||
45 |
version |
|
46 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/PosStream.st,v 1.34 1995-11-23 01:31:22 cg Exp $' |
|
88 | 47 |
! ! |
1 | 48 |
|
10 | 49 |
!PositionableStream class methodsFor:'initialization'! |
1 | 50 |
|
10 | 51 |
initialize |
44 | 52 |
"setup the signal used to handle errors during fileIn" |
53 |
||
10 | 54 |
ErrorDuringFileInSignal isNil ifTrue:[ |
302 | 55 |
ErrorDuringFileInSignal := ErrorSignal newSignalMayProceed:true. |
159 | 56 |
ErrorDuringFileInSignal nameClass:self message:#errorDuringFileInSignal. |
57 |
ErrorDuringFileInSignal notifierString:'error during fileIn'. |
|
276 | 58 |
|
59 |
ChunkSeparator := $!! |
|
10 | 60 |
] |
61 |
! ! |
|
1 | 62 |
|
63 |
!PositionableStream class methodsFor:'instance creation'! |
|
64 |
||
65 |
on:aCollection |
|
66 |
"return a new PositionableStream streaming on aCollection" |
|
67 |
||
68 |
^ (self basicNew) on:aCollection |
|
69 |
! |
|
70 |
||
71 |
on:aCollection from:first to:last |
|
72 |
"return a new PositionableStream streaming on aCollection |
|
73 |
from first to last" |
|
74 |
||
369 | 75 |
^ (self basicNew) on:aCollection from:first to:last |
57 | 76 |
! |
77 |
||
78 |
with:aCollection |
|
79 |
"return a new PositionableStream streaming on aCollection, |
|
80 |
the stream is positioned to the end of the collection." |
|
81 |
||
362 | 82 |
^ (self basicNew) with:aCollection |
1 | 83 |
! ! |
84 |
||
611 | 85 |
!PositionableStream class methodsFor:'constants'! |
1 | 86 |
|
611 | 87 |
chunkSeparator |
88 |
"return the chunk-separation character" |
|
57 | 89 |
|
611 | 90 |
^ ChunkSeparator |
360 | 91 |
! ! |
92 |
||
1 | 93 |
!PositionableStream methodsFor:'accessing'! |
94 |
||
95 |
contents |
|
96 |
"return the entire contents of the stream" |
|
97 |
||
98 |
^ collection |
|
99 |
! |
|
100 |
||
101 |
peek |
|
102 |
"look ahead for and return the next element" |
|
103 |
||
104 |
|peekObject| |
|
105 |
||
106 |
peekObject := self next. |
|
10 | 107 |
self backStep. |
1 | 108 |
^ peekObject |
109 |
! |
|
110 |
||
111 |
peekFor:something |
|
10 | 112 |
"return true and move past if next == something; |
113 |
otherwise stay and let position unchanged" |
|
1 | 114 |
|
115 |
self next == something ifTrue:[ |
|
159 | 116 |
^ true |
1 | 117 |
]. |
10 | 118 |
self backStep. |
1 | 119 |
^ false |
120 |
! |
|
121 |
||
122 |
readLimit:aNumber |
|
369 | 123 |
"set the read-limit; thats the position at which EOF is returned" |
1 | 124 |
|
125 |
readLimit := aNumber |
|
369 | 126 |
! |
127 |
||
128 |
writeLimit:aNumber |
|
129 |
"set the writeLimit; thats the position after which writing is prohibited" |
|
130 |
||
131 |
writeLimit := aNumber |
|
1 | 132 |
! ! |
133 |
||
44 | 134 |
!PositionableStream methodsFor:'chunk input/output'! |
1 | 135 |
|
136 |
nextChunk |
|
137 |
"return the next chunk, i.e. all characters up to the next |
|
217 | 138 |
exclamation mark. Within the chunk, exclamation marks have to be doubled, |
139 |
they are undoubled here. |
|
140 |
Except for primitive code, in which doubling is not needed (allowed). |
|
141 |
This exception was added to make it easier to edit primitive code with |
|
142 |
external editors. However, this means, that other Smalltalks cannot always |
|
143 |
read chunks containing primitive code |
|
144 |
- but that doesnt really matter, since C-primitives are an ST/X feature anyway." |
|
1 | 145 |
|
146 |
|theString sep newString done thisChar nextChar inPrimitive |
|
147 |
index "{ Class:SmallInteger }" |
|
148 |
currSize "{ Class:SmallInteger }" | |
|
149 |
||
276 | 150 |
sep := ChunkSeparator. |
1 | 151 |
theString := String new:500. |
152 |
currSize := 500. |
|
153 |
thisChar := self skipSeparators. |
|
154 |
thisChar := self next. |
|
155 |
index := 0. |
|
156 |
done := false. |
|
157 |
inPrimitive := false. |
|
158 |
||
159 |
[done] whileFalse:[ |
|
159 | 160 |
((index + 2) <= currSize) ifFalse:[ |
161 |
newString := String new:(currSize * 2). |
|
162 |
newString replaceFrom:1 to:currSize with:theString. |
|
163 |
currSize := currSize * 2. |
|
164 |
theString := newString |
|
165 |
]. |
|
166 |
thisChar isNil ifTrue:[ |
|
167 |
done := true |
|
168 |
] ifFalse:[ |
|
169 |
(thisChar == $% ) ifTrue:[ |
|
170 |
nextChar := self peek. |
|
171 |
(nextChar == ${ ) ifTrue:[ |
|
172 |
inPrimitive := true. |
|
173 |
index := index + 1. |
|
174 |
theString at:index put:thisChar. |
|
175 |
thisChar := self next |
|
176 |
] ifFalse:[ |
|
177 |
(nextChar == $} ) ifTrue:[ |
|
178 |
inPrimitive := false. |
|
179 |
index := index + 1. |
|
180 |
theString at:index put:thisChar. |
|
181 |
thisChar := self next |
|
182 |
] |
|
183 |
] |
|
184 |
] ifFalse:[ |
|
185 |
inPrimitive ifFalse:[ |
|
186 |
(thisChar == sep) ifTrue:[ |
|
187 |
(self peek == sep) ifFalse:[ |
|
188 |
done := true |
|
189 |
] ifTrue:[ |
|
190 |
self next |
|
191 |
] |
|
192 |
] |
|
193 |
] |
|
194 |
] |
|
195 |
]. |
|
196 |
done ifFalse:[ |
|
197 |
index := index + 1. |
|
198 |
theString at:index put:thisChar. |
|
199 |
thisChar := self next |
|
200 |
] |
|
1 | 201 |
]. |
202 |
(index == 0) ifTrue:[^ '']. |
|
57 | 203 |
^ theString copyTo:index |
1 | 204 |
! |
205 |
||
206 |
nextChunkPut:aString |
|
207 |
"put aString as a chunk onto the receiver; |
|
217 | 208 |
double all exclamation marks except within primitives and append a |
276 | 209 |
single delimiting exclamation mark at the end. |
210 |
This modification of the chunk format was done to have primitive |
|
211 |
code more readable. (since it must be edited using the fileBrowser). |
|
212 |
Its no incompatibility, since inline primitives are an ST/X special |
|
213 |
anyway." |
|
1 | 214 |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
215 |
|sep stopChars inPrimitive character |
1 | 216 |
index "{ Class:SmallInteger }" |
217 |
endIndex "{ Class:SmallInteger }" |
|
217 | 218 |
stop "{ Class:SmallInteger }" |
253 | 219 |
next "{ Class:SmallInteger }"| |
1 | 220 |
|
276 | 221 |
sep := ChunkSeparator. |
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
222 |
stopChars := '{}' copyWith:sep. |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
223 |
|
1 | 224 |
inPrimitive := false. |
225 |
index := 1. |
|
226 |
endIndex := aString size. |
|
217 | 227 |
stop := endIndex + 1. |
1 | 228 |
|
229 |
[index <= endIndex] whileTrue:[ |
|
217 | 230 |
" |
231 |
find position of next interresting character; |
|
232 |
output stuff up to that one in one piece |
|
233 |
" |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
234 |
next := aString indexOfAny:stopChars startingAt:index ifAbsent:stop. |
1 | 235 |
|
217 | 236 |
((index == 1) and:[next == stop]) ifTrue:[ |
159 | 237 |
self nextPutAll:aString |
238 |
] ifFalse:[ |
|
217 | 239 |
self nextPutAll:aString startingAt:index to:(next - 1) |
159 | 240 |
]. |
1 | 241 |
|
159 | 242 |
index := next. |
243 |
(index <= endIndex) ifTrue:[ |
|
244 |
character := aString at:index. |
|
276 | 245 |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
246 |
(character == ${ ) ifTrue:[ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
247 |
"/ starts a primitive |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
248 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
249 |
inPrimitive := true |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
250 |
] |
159 | 251 |
] ifFalse:[ |
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
252 |
"/ ends a primitive |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
253 |
(character == $} ) ifTrue:[ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
254 |
((index > 1) and:[(aString at:index-1) == $%]) ifTrue:[ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
255 |
inPrimitive := false |
159 | 256 |
] |
257 |
] ifFalse:[ |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
258 |
"/ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
259 |
"/ exclas have to be doubled - except if within a primitive |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
260 |
"/ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
261 |
inPrimitive ifFalse:[ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
262 |
(character == sep) ifTrue:[ |
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
263 |
self nextPut:sep |
159 | 264 |
] |
265 |
] |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
266 |
] |
159 | 267 |
]. |
276 | 268 |
|
159 | 269 |
self nextPut:character. |
270 |
index := index + 1 |
|
271 |
] |
|
1 | 272 |
]. |
273 |
self nextPut:sep |
|
517
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
274 |
|
c8fae50c2cc5
fixed nextChunkPut: which sometimes doubled exclas within primitives
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
275 |
"Modified: 10.11.1995 / 16:04:49 / cg" |
611 | 276 |
! |
277 |
||
278 |
nextPutChunkSeparator |
|
279 |
"append a chunk separator character" |
|
280 |
||
281 |
self nextPut:ChunkSeparator |
|
282 |
||
283 |
"Created: 13.9.1995 / 17:39:26 / claus" |
|
44 | 284 |
! ! |
285 |
||
286 |
!PositionableStream methodsFor:'fileIn'! |
|
287 |
||
611 | 288 |
askForDebug:message |
289 |
"launch a box asking if a debugger is wanted - used when an error |
|
290 |
occurs while filing in" |
|
291 |
||
292 |
Smalltalk isInitialized ifFalse:[ |
|
293 |
'error during startup: ' errorPrint. message errorPrintNL. |
|
294 |
^ #debug |
|
295 |
]. |
|
296 |
^ OptionBox |
|
297 |
request:message |
|
298 |
label:'Error in fileIn' |
|
299 |
form:(WarningBox iconBitmap) |
|
300 |
buttonLabels:#('abort' 'debug' 'continue') |
|
301 |
values:#(#abort #debug #continue) |
|
302 |
default:#continue. |
|
303 |
! |
|
304 |
||
44 | 305 |
fileIn |
306 |
"file in from the receiver, i.e. read chunks and evaluate them - |
|
307 |
return the value of the last chunk." |
|
308 |
||
283 | 309 |
^ self fileInNotifying:(SourceFileLoader on:self) passChunk:true |
44 | 310 |
! |
311 |
||
1 | 312 |
fileInNextChunkNotifying:someone |
313 |
"read next chunk, evaluate it and return the result; |
|
276 | 314 |
someone (which is usually some codeView) is notified of errors. |
315 |
Filein is done as follows: |
|
316 |
read a chunk |
|
317 |
if it started with an excla, evaluate it, and let the resulting object |
|
318 |
fileIn more chunks. |
|
319 |
This is a nice trick, since the methodsFor: expression evaluates to |
|
320 |
a ClassCategoryReader which reads and compiles chunks for its class. |
|
321 |
However, other than methodsFor expressions are possible - you can |
|
322 |
(in theory) create readers for any syntax. |
|
323 |
" |
|
1 | 324 |
|
282 | 325 |
^ self fileInNextChunkNotifying:someone passChunk:false |
326 |
! |
|
327 |
||
328 |
fileInNextChunkNotifying:someone passChunk:passChunk |
|
329 |
"read next chunk, evaluate it and return the result; |
|
330 |
someone (which is usually some codeView) is notified of errors. |
|
331 |
Filein is done as follows: |
|
332 |
read a chunk |
|
333 |
if it started with an excla, evaluate it, and let the resulting object |
|
334 |
fileIn more chunks. |
|
335 |
This is a nice trick, since the methodsFor: expression evaluates to |
|
336 |
a ClassCategoryReader which reads and compiles chunks for its class. |
|
337 |
However, other than methodsFor expressions are possible - you can |
|
338 |
(in theory) create readers for any syntax. |
|
339 |
" |
|
340 |
||
276 | 341 |
|aString sawExcla rslt done| |
1 | 342 |
|
343 |
self skipSeparators. |
|
344 |
self atEnd ifFalse:[ |
|
276 | 345 |
sawExcla := self peekFor:ChunkSeparator. |
159 | 346 |
aString := self nextChunk. |
347 |
aString size ~~ 0 ifTrue:[ |
|
282 | 348 |
passChunk ifTrue:[ |
349 |
someone source:aString |
|
350 |
]. |
|
351 |
sawExcla ifFalse:[ |
|
352 |
rslt := Compiler evaluate:aString notifying:someone. |
|
353 |
] ifTrue:[ |
|
354 |
rslt := Compiler evaluate:aString notifying:someone compile:false. |
|
355 |
||
159 | 356 |
" |
357 |
usually, the above chunk consists of some methodsFor:-expression |
|
358 |
in this case, the returned value is a ClassCategoryReader, |
|
359 |
which is used to load & compile the methods ... |
|
360 |
" |
|
253 | 361 |
rslt isNil ifTrue:[ |
362 |
" |
|
363 |
however, if that was nil (i.e. some error), we skip chunks |
|
364 |
up to the next empty chunk. |
|
365 |
" |
|
366 |
Transcript showCr:'skipping chunks ...'. |
|
367 |
done := false. |
|
368 |
[done] whileFalse:[ |
|
369 |
aString := self nextChunk. |
|
276 | 370 |
done := (aString size == 0) or:[aString isEmpty]. |
253 | 371 |
] |
372 |
] ifFalse:[ |
|
329 | 373 |
rslt := rslt fileInFrom:self notifying:someone passChunk:passChunk |
253 | 374 |
] |
159 | 375 |
] |
376 |
] |
|
1 | 377 |
]. |
159 | 378 |
^ rslt |
1 | 379 |
! |
380 |
||
611 | 381 |
fileInNotifying:someone passChunk:passChunk |
382 |
"file in from the receiver, i.e. read chunks and evaluate them - |
|
383 |
return the value of the last chunk. |
|
384 |
Someone (which is usually some codeView) is notified of errors." |
|
385 |
||
386 |
|lastValue| |
|
387 |
||
388 |
" |
|
389 |
catch any errors during fileIn |
|
390 |
- offer debug/abort/continue choice |
|
391 |
" |
|
392 |
Object errorSignal handle:[:ex | |
|
393 |
|action what sender| |
|
394 |
||
395 |
what := ex errorString. |
|
396 |
what isNil ifTrue:[ |
|
397 |
what := ex signal notifierString. |
|
398 |
]. |
|
399 |
||
400 |
"handle the case where no GUI has been built in, |
|
401 |
just abort the fileIn with a notification" |
|
41 | 402 |
|
611 | 403 |
Display isNil ifTrue:[ |
404 |
sender := ex suspendedContext sender. |
|
405 |
self notify:(what , |
|
406 |
' in ' , sender receiver class name , |
|
407 |
'>>>' , sender selector). |
|
408 |
ex return |
|
409 |
]. |
|
410 |
||
411 |
"otherwise ask what should be done now and either |
|
412 |
continue or abort the fileIn" |
|
413 |
||
414 |
action := self askForDebug:('error in fileIn: ' , what) withCRs. |
|
415 |
action == #continue ifTrue:[ |
|
416 |
ex proceed |
|
417 |
]. |
|
418 |
action == #abort ifTrue:[ |
|
419 |
ex return |
|
420 |
]. |
|
421 |
"/ Debugger enter:ex suspendedContext |
|
422 |
(ex signal) enterDebuggerWith:ex message:what. |
|
423 |
ex reject |
|
424 |
] do:[ |
|
425 |
[self atEnd] whileFalse:[ |
|
426 |
lastValue := self fileInNextChunkNotifying:someone passChunk:passChunk |
|
427 |
] |
|
180 | 428 |
]. |
611 | 429 |
^ lastValue |
430 |
! ! |
|
431 |
||
432 |
!PositionableStream methodsFor:'positioning'! |
|
433 |
||
434 |
backStep |
|
435 |
"move backward read position by one" |
|
436 |
||
437 |
position <= 0 ifTrue: [^ self positionError]. |
|
438 |
position := position - 1 |
|
439 |
! |
|
440 |
||
441 |
position |
|
442 |
"return the read position" |
|
443 |
||
444 |
^ position |
|
445 |
! |
|
446 |
||
447 |
position:index |
|
448 |
"set the read position" |
|
449 |
||
450 |
"/ FIX: allow positioning right after last element of stream |
|
451 |
"/ ((index > readLimit) or:[index < 0]) ifTrue: [^ self positionError]. |
|
452 |
||
453 |
((index > (readLimit+1)) or:[index < 0]) ifTrue: [^ self positionError]. |
|
454 |
position := index |
|
455 |
! |
|
456 |
||
457 |
reset |
|
458 |
"set the read position to the beginning of the collection" |
|
459 |
||
460 |
position := "0" 1 |
|
461 |
! |
|
462 |
||
463 |
setToEnd |
|
464 |
"set the read position to the end of the collection" |
|
465 |
||
466 |
position := readLimit |
|
467 |
! |
|
468 |
||
469 |
skip:numberToSkip |
|
470 |
"skip the next numberToSkip elements" |
|
471 |
||
472 |
self position:(position + numberToSkip) |
|
44 | 473 |
! ! |
611 | 474 |
|
475 |
!PositionableStream methodsFor:'private'! |
|
476 |
||
477 |
contentsSpecies |
|
478 |
"return a class of which instances will be returned, when |
|
479 |
parts of the collection are asked for. |
|
480 |
(see upTo-kind of methods in subclasses)" |
|
481 |
||
482 |
^ collection species |
|
483 |
! |
|
484 |
||
485 |
on:aCollection |
|
486 |
"setup for streaming on aCollection" |
|
487 |
||
488 |
collection := aCollection. |
|
489 |
readLimit := aCollection size. |
|
490 |
position := "0" 1 |
|
491 |
! |
|
492 |
||
493 |
on:aCollection from:first to:last |
|
494 |
"setup for streaming on aCollection from first to last" |
|
495 |
||
496 |
collection := aCollection. |
|
497 |
position := first. |
|
498 |
readLimit := last |
|
499 |
! |
|
500 |
||
501 |
positionError |
|
502 |
"report an error when positioning past the end" |
|
503 |
||
504 |
^ self error:'cannot position past end of collection' |
|
505 |
! |
|
506 |
||
507 |
with:aCollection |
|
508 |
"setup for streaming to the end of aCollection" |
|
509 |
||
510 |
collection := aCollection. |
|
511 |
self setToEnd |
|
512 |
! ! |
|
513 |
||
514 |
!PositionableStream methodsFor:'queries'! |
|
515 |
||
516 |
isPositionable |
|
517 |
"return true, if the stream supports positioning (this one is)" |
|
518 |
||
519 |
^ true |
|
520 |
! ! |
|
521 |
||
522 |
!PositionableStream methodsFor:'testing'! |
|
523 |
||
524 |
atEnd |
|
525 |
"return true, if the read-position is at the end" |
|
526 |
||
527 |
^ position > readLimit |
|
528 |
! |
|
529 |
||
530 |
isEmpty |
|
531 |
"return true, if the contents of the stream is empty" |
|
532 |
||
533 |
^ readLimit == 0 |
|
534 |
! ! |
|
535 |
||
536 |
PositionableStream initialize! |