RWStream.st
author Claus Gittinger <cg@exept.de>
Thu, 07 May 1998 20:02:53 +0200
changeset 3422 09c13ab58bb2
parent 3081 4cd54c54ed78
permissions -rw-r--r--
i386 can do unaligned accesses
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
329
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    20
!ReadWriteStream class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
329
claus
parents: 93
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    35
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    38
    ReadWriteStreams allow both read- and write-access to some collection.
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    39
    To allow this, they reenable some methods blocked in WriteStream.
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    40
    (being one of the seldom places, where multiple inheritance could be
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    41
     of good use in smalltalk).
329
claus
parents: 93
diff changeset
    42
claus
parents: 93
diff changeset
    43
    Claus:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    44
        I personally find the ReadStream - WriteStream - ReadWriteStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    45
        organization brain-damaged. It would be better to have an attribute
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    46
        (such as readOnly / writeOnly / readWrite) in an InternalStream subclass 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    47
        of Stream ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    48
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    49
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
    50
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 41
diff changeset
    51
"
329
claus
parents: 93
diff changeset
    52
! !
claus
parents: 93
diff changeset
    53
345
claus
parents: 329
diff changeset
    54
!ReadWriteStream methodsFor:'access-reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
a27a279701f8 Initial revision
claus
parents:
diff changeset
    56
next
41
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    57
    "return the next element; advance read position.
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    58
     If there are no more elements, nil is returned."
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    59
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    60
    |element|
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    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
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    63
    element := collection at:position.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
    position := position + 1.
41
a14247b04d03 *** empty log message ***
claus
parents: 5
diff changeset
    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
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
peek
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
    "return the element to be read next without advancing read position.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
     If there are no more elements, nil is returned."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    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
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
3081
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    80
!ReadWriteStream methodsFor:'accessing'!
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    81
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    82
contents
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    83
    "return the contents as written so far;
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    84
     redefined to prevent confusion resulting due to 
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    85
     my superclasses optimization. (see WriteStream contents).
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    86
     ST80 users if RWStream expect the contents array to remain
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    87
     unchanged."
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    88
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    89
    readLimit := readLimit max:position-1.
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    90
    ^ collection copyFrom:1 to:readLimit
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    91
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    92
    "Created: / 30.10.1997 / 16:25:22 / cg"
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    93
    "Modified: / 30.10.1997 / 18:37:09 / cg"
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    94
! !
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
    95
677
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
    96
!ReadWriteStream methodsFor:'converting'!
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
    97
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
    98
readStream
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    99
    "return the receiver as a readStream - thats myself"
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   100
677
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   101
    ^ self
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   102
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   103
    "Created: 29.11.1995 / 22:04:23 / stefan"
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   104
! !
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   105
3081
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   106
!ReadWriteStream methodsFor:'positioning'!
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   107
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   108
reset
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   109
    "set the read position to the beginning of the collection.
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   110
     Re-redefined to prevent the collection from being emptied."
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   111
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   112
    position := "0" 1
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   113
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   114
    "Created: / 30.10.1997 / 16:17:45 / cg"
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   115
! !
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   116
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
!ReadWriteStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
isReadable 
2927
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   120
    "return true if the receiver supports reading - thats true"
1434c3d7f78a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   121
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
    ^ true
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
677
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   125
!ReadWriteStream class methodsFor:'documentation'!
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   126
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   127
version
3081
4cd54c54ed78 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2927
diff changeset
   128
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/RWStream.st,v 1.19 1997-11-02 17:52:46 cg Exp $'
677
9ab491d2a2b4 Need methot readStream.
Stefan Vogel <sv@exept.de>
parents: 611
diff changeset
   129
! !