author | Claus Gittinger <cg@exept.de> |
Tue, 21 Mar 2000 13:53:43 +0100 | |
changeset 5309 | fa0d92f438db |
parent 3081 | 4cd54c54ed78 |
child 5932 | 6041c11b3370 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
329 | 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 |
||
13 |
WriteStream subclass:#ReadWriteStream |
|
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
14 |
instanceVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
15 |
classVariableNames:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
16 |
poolDictionaries:'' |
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
17 |
category:'Streams' |
1 | 18 |
! |
19 |
||
611 | 20 |
!ReadWriteStream class methodsFor:'documentation'! |
88 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
329 | 25 |
All Rights Reserved |
88 | 26 |
|
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 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
ReadWriteStreams allow both read- and write-access to some collection. |
|
39 |
To allow this, they reenable some methods blocked in WriteStream. |
|
40 |
(being one of the seldom places, where multiple inheritance could be |
|
41 |
of good use in smalltalk). |
|
329 | 42 |
|
43 |
Claus: |
|
1295 | 44 |
I personally find the ReadStream - WriteStream - ReadWriteStream |
45 |
organization brain-damaged. It would be better to have an attribute |
|
46 |
(such as readOnly / writeOnly / readWrite) in an InternalStream subclass |
|
47 |
of Stream ... |
|
48 |
||
49 |
[author:] |
|
50 |
Claus Gittinger |
|
88 | 51 |
" |
5309 | 52 |
! |
53 |
||
54 |
examples |
|
55 |
" |
|
56 |
|s| |
|
57 |
||
58 |
s := ReadWriteStream with:'abcd'. |
|
59 |
s reset. |
|
60 |
s nextPut:$A. |
|
61 |
s contents |
|
62 |
" |
|
329 | 63 |
! ! |
64 |
||
345 | 65 |
!ReadWriteStream methodsFor:'access-reading'! |
1 | 66 |
|
67 |
next |
|
41 | 68 |
"return the next element; advance read position. |
69 |
If there are no more elements, nil is returned." |
|
70 |
||
71 |
|element| |
|
72 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
73 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
41 | 74 |
element := collection at:position. |
1 | 75 |
position := position + 1. |
41 | 76 |
^ element |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
77 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
78 |
"Modified: 5.2.1996 / 21:57:40 / stefan" |
611 | 79 |
! |
80 |
||
81 |
peek |
|
82 |
"return the element to be read next without advancing read position. |
|
83 |
If there are no more elements, nil is returned." |
|
84 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
85 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
611 | 86 |
^ collection at:position |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
87 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
88 |
"Modified: 5.2.1996 / 21:57:47 / stefan" |
1 | 89 |
! ! |
611 | 90 |
|
3081 | 91 |
!ReadWriteStream methodsFor:'accessing'! |
92 |
||
93 |
contents |
|
94 |
"return the contents as written so far; |
|
95 |
redefined to prevent confusion resulting due to |
|
96 |
my superclasses optimization. (see WriteStream contents). |
|
97 |
ST80 users if RWStream expect the contents array to remain |
|
98 |
unchanged." |
|
99 |
||
5309 | 100 |
readLimit := (readLimit ? 0) max:position-1. |
3081 | 101 |
^ collection copyFrom:1 to:readLimit |
102 |
||
103 |
"Created: / 30.10.1997 / 16:25:22 / cg" |
|
104 |
"Modified: / 30.10.1997 / 18:37:09 / cg" |
|
5309 | 105 |
! |
106 |
||
107 |
reset |
|
108 |
"set the read position to the beginning of the collection" |
|
109 |
||
110 |
self resetPosition |
|
111 |
||
3081 | 112 |
! ! |
113 |
||
677 | 114 |
!ReadWriteStream methodsFor:'converting'! |
115 |
||
116 |
readStream |
|
2927 | 117 |
"return the receiver as a readStream - thats myself" |
118 |
||
677 | 119 |
^ self |
120 |
||
121 |
"Created: 29.11.1995 / 22:04:23 / stefan" |
|
122 |
! ! |
|
123 |
||
5309 | 124 |
!ReadWriteStream methodsFor:'initialization'! |
3081 | 125 |
|
5309 | 126 |
on:initialCollection |
127 |
super on:initialCollection. |
|
128 |
readLimit := 0. |
|
129 |
! |
|
3081 | 130 |
|
5309 | 131 |
with:initialCollection |
132 |
super with:initialCollection. |
|
133 |
readLimit := initialCollection size. |
|
134 |
position := 1. |
|
3081 | 135 |
! ! |
136 |
||
611 | 137 |
!ReadWriteStream methodsFor:'queries'! |
138 |
||
139 |
isReadable |
|
2927 | 140 |
"return true if the receiver supports reading - thats true" |
141 |
||
611 | 142 |
^ true |
143 |
! ! |
|
144 |
||
677 | 145 |
!ReadWriteStream class methodsFor:'documentation'! |
146 |
||
147 |
version |
|
5309 | 148 |
^ '$Header: /cvs/stx/stx/libbasic/ReadWriteStream.st,v 1.20 2000-03-21 12:53:43 cg Exp $' |
677 | 149 |
! ! |