author | Claus Gittinger <cg@exept.de> |
Thu, 07 May 1998 20:02:53 +0200 | |
changeset 3422 | 09c13ab58bb2 |
parent 3081 | 4cd54c54ed78 |
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 |
" |
329 | 52 |
! ! |
53 |
||
345 | 54 |
!ReadWriteStream methodsFor:'access-reading'! |
1 | 55 |
|
56 |
next |
|
41 | 57 |
"return the next element; advance read position. |
58 |
If there are no more elements, nil is returned." |
|
59 |
||
60 |
|element| |
|
61 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
62 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
41 | 63 |
element := collection at:position. |
1 | 64 |
position := position + 1. |
41 | 65 |
^ element |
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
66 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
67 |
"Modified: 5.2.1996 / 21:57:40 / stefan" |
611 | 68 |
! |
69 |
||
70 |
peek |
|
71 |
"return the element to be read next without advancing read position. |
|
72 |
If there are no more elements, nil is returned." |
|
73 |
||
970
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
74 |
(position > readLimit) ifTrue:[^ self pastEnd]. |
611 | 75 |
^ 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
|
76 |
|
3b59c9b38dbb
ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents:
701
diff
changeset
|
77 |
"Modified: 5.2.1996 / 21:57:47 / stefan" |
1 | 78 |
! ! |
611 | 79 |
|
3081 | 80 |
!ReadWriteStream methodsFor:'accessing'! |
81 |
||
82 |
contents |
|
83 |
"return the contents as written so far; |
|
84 |
redefined to prevent confusion resulting due to |
|
85 |
my superclasses optimization. (see WriteStream contents). |
|
86 |
ST80 users if RWStream expect the contents array to remain |
|
87 |
unchanged." |
|
88 |
||
89 |
readLimit := readLimit max:position-1. |
|
90 |
^ collection copyFrom:1 to:readLimit |
|
91 |
||
92 |
"Created: / 30.10.1997 / 16:25:22 / cg" |
|
93 |
"Modified: / 30.10.1997 / 18:37:09 / cg" |
|
94 |
! ! |
|
95 |
||
677 | 96 |
!ReadWriteStream methodsFor:'converting'! |
97 |
||
98 |
readStream |
|
2927 | 99 |
"return the receiver as a readStream - thats myself" |
100 |
||
677 | 101 |
^ self |
102 |
||
103 |
"Created: 29.11.1995 / 22:04:23 / stefan" |
|
104 |
! ! |
|
105 |
||
3081 | 106 |
!ReadWriteStream methodsFor:'positioning'! |
107 |
||
108 |
reset |
|
109 |
"set the read position to the beginning of the collection. |
|
110 |
Re-redefined to prevent the collection from being emptied." |
|
111 |
||
112 |
position := "0" 1 |
|
113 |
||
114 |
"Created: / 30.10.1997 / 16:17:45 / cg" |
|
115 |
! ! |
|
116 |
||
611 | 117 |
!ReadWriteStream methodsFor:'queries'! |
118 |
||
119 |
isReadable |
|
2927 | 120 |
"return true if the receiver supports reading - thats true" |
121 |
||
611 | 122 |
^ true |
123 |
! ! |
|
124 |
||
677 | 125 |
!ReadWriteStream class methodsFor:'documentation'! |
126 |
||
127 |
version |
|
3081 | 128 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/RWStream.st,v 1.19 1997-11-02 17:52:46 cg Exp $' |
677 | 129 |
! ! |