118 (where things are written for the contents only) but may be incompatible |
118 (where things are written for the contents only) but may be incompatible |
119 with some applications. Time will show, if this is to be changed." |
119 with some applications. Time will show, if this is to be changed." |
120 |
120 |
121 |lastIndex| |
121 |lastIndex| |
122 |
122 |
123 lastIndex := position - ZeroPosition. |
123 lastIndex := position. |
124 collection size == lastIndex ifFalse:[ |
124 collection size == lastIndex ifFalse:[ |
125 collection isFixedSize ifTrue:[ |
125 collection isFixedSize ifTrue:[ |
126 " |
126 " |
127 grow is expensive - return a copy. |
127 grow is expensive - return a copy. |
128 (is this what users of writeStream expect ?) |
128 (is this what users of writeStream expect ?) |
129 " |
129 " |
130 collection := collection copyFrom:1 to:lastIndex |
130 collection := collection copyFrom:1 to:lastIndex |
131 ] ifFalse:[ |
131 ] ifFalse:[ |
132 collection grow:lastIndex |
132 collection grow:lastIndex |
133 ] |
133 ] |
134 ]. |
134 ]. |
135 ^ collection |
135 ^ collection |
136 |
136 |
137 "Modified: / 19.2.1997 / 08:57:28 / stefan" |
137 "Modified: / 19.2.1997 / 08:57:28 / stefan" |
138 "Modified: / 30.10.1997 / 16:21:23 / cg" |
138 "Modified: / 30.10.1997 / 16:21:23 / cg" |
198 |
198 |
199 position0Based:index0Based |
199 position0Based:index0Based |
200 "redefined to allow positioning past the readLimit" |
200 "redefined to allow positioning past the readLimit" |
201 |
201 |
202 ((index0Based > collection size) or:[index0Based < 0]) ifTrue: [^ self positionError]. |
202 ((index0Based > collection size) or:[index0Based < 0]) ifTrue: [^ self positionError]. |
203 position := index0Based + ZeroPosition |
203 position := index0Based |
204 ! ! |
204 ! ! |
205 |
205 |
206 !WriteStream methodsFor:'private'! |
206 !WriteStream methodsFor:'private'! |
207 |
207 |
208 growCollection |
208 growCollection |
293 !WriteStream methodsFor:'testing'! |
293 !WriteStream methodsFor:'testing'! |
294 |
294 |
295 isEmpty |
295 isEmpty |
296 "return true, if the contents of the stream is empty" |
296 "return true, if the contents of the stream is empty" |
297 |
297 |
298 ^ self position0Based == ZeroPosition |
298 ^ self position0Based == 0 |
299 |
299 |
300 "Created: 14.10.1997 / 20:44:37 / cg" |
300 "Created: 14.10.1997 / 20:44:37 / cg" |
301 ! ! |
301 ! ! |
302 |
302 |
303 !WriteStream methodsFor:'writing'! |
303 !WriteStream methodsFor:'writing'! |
312 (collection isNil or:[writeLimit notNil]) ifTrue:[ |
312 (collection isNil or:[writeLimit notNil]) ifTrue:[ |
313 super next:count put:anObject. |
313 super next:count put:anObject. |
314 ^ self. |
314 ^ self. |
315 ]. |
315 ]. |
316 |
316 |
317 position1Based := position - ZeroPosition + 1. |
317 position1Based := position + 1. |
318 final := position1Based + count - 1. |
318 final := position1Based + count - 1. |
319 (final > collection size) ifTrue:[ |
319 (final > collection size) ifTrue:[ |
320 self growCollection:final |
320 self growCollection:final |
321 ]. |
321 ]. |
322 |
322 |
323 position1Based to:final do:[:index | |
323 position1Based to:final do:[:index | |
324 collection at:index put:anObject. |
324 collection at:index put:anObject. |
325 ]. |
325 ]. |
326 position1Based := position1Based + count. |
326 position1Based := position1Based + count. |
327 (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
327 (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
328 position := position1Based - 1 + ZeroPosition. |
328 position := position1Based - 1. |
329 "/ ^ anObject -- return self |
329 "/ ^ anObject -- return self |
330 ! |
330 ! |
331 |
331 |
332 next:n putAll:aCollection startingAt:pos1 |
332 next:n putAll:aCollection startingAt:pos1 |
333 "append some elements of the argument, aCollection to the stream." |
333 "append some elements of the argument, aCollection to the stream." |
421 } |
421 } |
422 } |
422 } |
423 #endif |
423 #endif |
424 %}. |
424 %}. |
425 (writeLimit isNil |
425 (writeLimit isNil |
426 or:[(position + 1 - ZeroPosition) <= writeLimit]) ifTrue:[ |
426 or:[(position + 1) <= writeLimit]) ifTrue:[ |
427 ((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection]. |
427 (position >= collection size) ifTrue:[self growCollection]. |
428 collection at:(position + 1 - ZeroPosition) put:anObject. |
428 collection at:(position + 1) put:anObject. |
429 ((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)]. |
429 (position >= readLimit) ifTrue:[readLimit := (position + 1)]. |
430 position := position + 1. |
430 position := position + 1. |
431 ] ifFalse:[ |
431 ] ifFalse:[ |
432 WriteError raiseErrorString:'write beyond writeLimit' |
432 WriteError raiseErrorString:'write beyond writeLimit' |
433 ]. |
433 ]. |
434 ^anObject |
434 ^anObject |
448 aCollection isSequenceable ifFalse:[ |
448 aCollection isSequenceable ifFalse:[ |
449 super nextPutAll:aCollection. |
449 super nextPutAll:aCollection. |
450 ^ self. |
450 ^ self. |
451 ]. |
451 ]. |
452 |
452 |
453 position1Based := position - ZeroPosition + 1. |
453 position1Based := position + 1. |
454 |
454 |
455 nMore := aCollection size. |
455 nMore := aCollection size. |
456 nMore == 0 ifTrue:[ |
456 nMore == 0 ifTrue:[ |
457 "/ for the programmer.. |
457 "/ for the programmer.. |
458 aCollection isCollection ifFalse:[ |
458 aCollection isCollection ifFalse:[ |
475 with:aCollection |
475 with:aCollection |
476 startingAt:1. |
476 startingAt:1. |
477 |
477 |
478 position1Based := position1Based + nMore. |
478 position1Based := position1Based + nMore. |
479 (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
479 (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1]. |
480 position := position1Based - 1 + ZeroPosition. |
480 position := position1Based - 1. |
481 "/ ^ aCollection -- self |
481 "/ ^ aCollection -- self |
482 |
482 |
483 "Modified: / 04-09-2011 / 20:03:32 / cg" |
483 "Modified: / 04-09-2011 / 20:03:32 / cg" |
484 ! |
484 ! |
485 |
485 |
492 |
492 |
493 collection isNil ifTrue:[ |
493 collection isNil ifTrue:[ |
494 ^ super nextPutAll:aCollection startingAt:pos1 to:pos2 |
494 ^ super nextPutAll:aCollection startingAt:pos1 to:pos2 |
495 ]. |
495 ]. |
496 |
496 |
497 position1Based := position - ZeroPosition + 1. |
497 position1Based := position + 1. |
498 nMore := pos2 - pos1 + 1. |
498 nMore := pos2 - pos1 + 1. |
499 final := position1Based + nMore - 1. |
499 final := position1Based + nMore - 1. |
500 (writeLimit notNil |
500 (writeLimit notNil |
501 and:[final > writeLimit]) ifTrue:[ |
501 and:[final > writeLimit]) ifTrue:[ |
502 final := writeLimit. |
502 final := writeLimit. |