WriteStream.st
author Claus Gittinger <cg@exept.de>
Fri, 09 Nov 2001 16:18:46 +0100
changeset 6172 a3c88ea5efe9
parent 5888 64d077a702c7
child 6325 6ea71ffec923
permissions -rw-r--r--
comment and iso8601 (time/date formats) fixes
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
252
claus
parents: 95
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
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
    13
"{ Package: 'stx:libbasic' }"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
PositionableStream subclass:#WriteStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    16
	instanceVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    17
	classVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    18
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    19
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
    22
!WriteStream class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
252
claus
parents: 95
diff changeset
    27
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    38
documentation
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    39
"
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    40
    Streams for writing into.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    41
    WriteStreams are especially useful, if big strings are to be constructed
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    42
    from pieces - create a writeStream, add the pieces (with #nextPut or
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    43
    #nextPutAll) and finally fetch the concatenated string via #contents.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    44
    This is much better than constructing the big string by concatenating via
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    45
    the comma (,) operator, since less intermediate garbage objects are created.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    46
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    47
    This implementation currently DOES change the 
261
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    48
    identity if the streamed-upon collection IF it cannot grow easily. 
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    49
    Collections which cannot grow easily are for example: Array, ByteArray and String.
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
    Thus it is slightly incompatible to ST-80 since 'aStream contents' does 
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    51
    not always return the original collection. This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    52
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    53
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    54
        Claus Gittinger
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    55
"
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    56
!
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    57
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    58
examples
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    59
"
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    60
                                                                [exBegin]
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    61
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    62
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    63
     s := WriteStream on:''.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    64
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    65
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    66
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    67
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    68
     s contents inspect
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    69
                                                                [exEnd]
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    70
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    71
                                                                [exBegin]
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    72
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    73
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    74
     s := WriteStream on:''.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    75
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    76
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    77
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    78
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    79
     Transcript nextPutLine:(s contents)
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    80
                                                                [exEnd]
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    81
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    82
                                                                [exBegin]
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    83
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    84
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    85
     s := '' writeStream.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    86
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    87
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    88
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    89
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    90
     Transcript nextPutLine:(s contents)
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    91
                                                                [exEnd]
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    92
"
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    93
345
claus
parents: 329
diff changeset
    94
! !
claus
parents: 329
diff changeset
    95
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
!WriteStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
contents
345
claus
parents: 329
diff changeset
    99
    "return the current contents (a collection) of the stream.
claus
parents: 329
diff changeset
   100
     Currently, this returns the actual collection if possible
claus
parents: 329
diff changeset
   101
     (and reset is implemented to create a new one) in contrast to
claus
parents: 329
diff changeset
   102
     ST80, where contents returns a copy and reset only sets the writePointer.
claus
parents: 329
diff changeset
   103
     The ST/X behavior creates less temporary garbage in the normal case
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   104
     (where things are written for the contents only) but may be incompatible
345
claus
parents: 329
diff changeset
   105
     with some applications. Time will show, if this is to be changed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   107
    |lastIndex|
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   108
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   109
    lastIndex := position - 1.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   110
    collection size == lastIndex ifFalse:[
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   111
        collection isFixedSize ifTrue:[
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   112
            "
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   113
             grow is expensive - return a copy.
3087
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   114
             (is this what users of writeStream expect ?)
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   115
            "
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   116
            collection := collection copyFrom:1 to:lastIndex
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   117
        ] ifFalse:[
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   118
            collection grow:lastIndex
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   119
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
    ^ collection
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   122
3087
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   123
    "Modified: / 19.2.1997 / 08:57:28 / stefan"
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   124
    "Modified: / 30.10.1997 / 16:21:23 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   127
last
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   128
    "return the last element - report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   129
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   130
    ^ collection at:(position - 1).
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   131
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   132
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   133
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   134
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   135
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   136
     s nextPut:$a.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   137
     s last.       
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   138
     s nextPut:$b.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   139
     s last.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   140
     s nextPut:$c.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   141
     s last.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   142
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   143
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   144
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   145
last:n
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   146
    "return the last n elements as species of the underlying collection;
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   147
     Report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   148
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   149
    ^ collection copyFrom:(position - n) to:(position - 1).
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   150
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   151
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   152
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   153
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   154
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   155
     s nextPut:$a.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   156
     s last:1.       
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   157
     s nextPut:$b.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   158
     s last:1.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   159
     s last:2.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   160
     s nextPut:$c.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   161
     s last:1.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   162
     s last:2.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   163
     s last:3.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   164
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   165
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   166
329
claus
parents: 293
diff changeset
   167
reset
345
claus
parents: 329
diff changeset
   168
    "reset the stream; write anew.
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   169
     See the comment in WriteStream>>contents"
329
claus
parents: 293
diff changeset
   170
claus
parents: 293
diff changeset
   171
    collection := collection species new:(collection size).
claus
parents: 293
diff changeset
   172
    super reset
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   173
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   174
    "Modified: 19.2.1997 / 08:57:00 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
!WriteStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
position:index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
    "redefined to allow positioning past the readLimit"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
4406
f78222b250b2 added ZeroPosition;
Claus Gittinger <cg@exept.de>
parents: 3098
diff changeset
   182
    ((index > (collection size + 1)) or:[index < ZeroPosition]) ifTrue: [^ self positionError].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
    position := index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   184
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
!WriteStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   188
growCollection
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   189
    "grow the streamed collection to at least 10 elements"
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   190
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
    self growCollection:10
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   192
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   193
    "Modified: 19.8.1997 / 17:53:28 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
growCollection:minNewSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
    "grow the streamed collection to at least minNewSize"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   199
    |oldSize newSize newColl|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
    oldSize := collection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   202
    (oldSize == 0) ifTrue:[
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   203
        newSize := minNewSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
    ] ifFalse:[
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   205
        newSize := oldSize * 2.
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   206
        (newSize < minNewSize) ifTrue:[newSize := minNewSize].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   207
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   208
    collection isFixedSize ifTrue:[
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   209
        newColl := collection species new:newSize.
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   210
        newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   211
        collection := newColl
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
    ] ifFalse:[
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   213
        collection grow:newSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
    ].
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   215
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   216
    "Modified: 19.8.1997 / 17:53:11 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
!WriteStream methodsFor:'private accessing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
on:aCollection from:start to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    "create and return a new stream for writing onto aCollection, where
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   223
     writing is limited to the elements in the range start to last."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
    super on:aCollection from:start to:last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
    writeLimit := last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   229
!WriteStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   230
3098
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   231
isReadable 
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   232
    "return true if the receiver supports reading - thats not true"
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   233
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   234
    ^ false
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   235
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   236
    "Created: / 8.11.1997 / 14:06:07 / cg"
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   237
!
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   238
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
isWritable
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   240
    "return true, if writing is supported by the recevier.
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   241
     Always return true here"
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   242
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   243
    ^ true
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   244
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   245
    "Modified: 16.5.1996 / 14:44:49 / cg"
3031
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   246
!
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   247
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   248
size
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   249
    "return the current size"
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   250
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   251
    ^ position - 1.
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   252
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   253
    "Created: 14.10.1997 / 20:43:49 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   254
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   255
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   256
!WriteStream methodsFor:'reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   257
a27a279701f8 Initial revision
claus
parents:
diff changeset
   258
next
10
claus
parents: 5
diff changeset
   259
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   260
10
claus
parents: 5
diff changeset
   261
    self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
peek
10
claus
parents: 5
diff changeset
   265
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
10
claus
parents: 5
diff changeset
   267
    self shouldNotImplement
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   268
! !
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   269
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   270
!WriteStream methodsFor:'testing'!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   271
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   272
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   273
    "return true, if the contents of the stream is empty"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   274
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   275
    ^ position == 1
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   276
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   277
    "Created: 14.10.1997 / 20:44:37 / cg"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   278
! !
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   279
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
!WriteStream methodsFor:'writing'!
369
claus
parents: 359
diff changeset
   281
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
    "append anObject count times to the receiver.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   284
     Redefined to avoid count grows of the underlying collection -
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
     instead a single grow on the final size is performed."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
    |final|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
    (collection isNil or:[writeLimit notNil]) ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
	^ super next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
    ].
369
claus
parents: 359
diff changeset
   292
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
    final := position + count - 1.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
    (final > collection size) ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
	self growCollection:final
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
    ].
369
claus
parents: 359
diff changeset
   297
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
    position to:final do:[:index |
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
	collection at:index put:anObject.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
    position := position + count.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
    (position > readLimit) ifTrue:[readLimit := position - 1].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
    ^ anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
5198
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   306
next:n putAll:aCollection startingAt:pos1
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   307
    "append some elements of the argument, aCollection to the stream."
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   308
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   309
    ^ self nextPutAll:aCollection startingAt:pos1 to:pos1+n-1
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   310
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   311
    "
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   312
     |s|
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   313
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   314
     s := '' writeStream.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   315
     s nextPutAll:'hello '.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   316
     s next:5 putAll:'1234world012345' startingAt:5.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   317
     s contents   
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   318
    "
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   319
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   320
    "Modified: 12.7.1996 / 10:31:36 / cg"
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   321
!
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   322
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   323
nextPut:anObject
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   324
    "append the argument, anObject to the stream.
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   325
     Specially tuned for appending to String, ByteArray and Array streams."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   326
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   327
%{  /* NOCONTEXT */
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   328
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   329
    REGISTER int pos;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   330
    unsigned ch;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   331
    OBJ coll;
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   332
    OBJ p, wL, rL;
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   333
    int __readLimit = -1;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   334
1136
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   335
    coll = __INST(collection);
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   336
    p = __INST(position);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   337
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2883
diff changeset
   338
#ifndef NO_PRIM_STREAM
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   339
    if (__isNonNilObject(coll) && __isSmallInteger(p)) {
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   340
        pos = __intVal(p);
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   341
        wL = __INST(writeLimit);
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
   342
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   343
        if ((wL == nil)
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   344
         || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   345
            OBJ cls;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   346
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   347
            cls = __qClass(coll);
252
claus
parents: 95
diff changeset
   348
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   349
            rL = __INST(readLimit);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   350
            if (__isSmallInteger(rL)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   351
                __readLimit = __intVal(rL);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   352
            }
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   353
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   354
            if (cls == @global(String)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   355
                if (__isCharacter(anObject) 
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   356
                 && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   357
                 && (pos <= __stringSize(coll))) {
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   358
                    __StringInstPtr(coll)->s_element[pos-1] = ch;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   359
                    __INST(position) = __MKSMALLINT(pos + 1);
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   360
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   361
                        __INST(readLimit) = __MKSMALLINT(pos);
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   362
                    }
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   363
                    RETURN ( anObject );
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   364
                }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   365
            } else if (cls == @global(ByteArray)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   366
                if (__isSmallInteger(anObject) 
2864
328b52ecd339 no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2863
diff changeset
   367
                 && ((ch = __intVal(anObject)) <= 255) /* ch is unsigned */
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   368
                 && (pos <= __byteArraySize(coll))) {
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   369
                    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   370
                    __INST(position) = __MKSMALLINT(pos + 1);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   371
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   372
                        __INST(readLimit) = __MKSMALLINT(pos);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   373
                    }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   374
                    RETURN ( anObject );
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   375
                }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   376
            } else if (cls == @global(Array)) {
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   377
                if (pos <= __arraySize(coll)) {
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   378
                     __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   379
                    __STORE(coll, anObject);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   380
                    __INST(position) = __MKSMALLINT(pos + 1);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   381
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   382
                        __INST(readLimit) = __MKSMALLINT(pos);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   383
                    }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   384
                    RETURN ( anObject );
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   385
                }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   386
            }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   387
        }
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   388
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2883
diff changeset
   389
#endif
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   390
%}.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   391
    (writeLimit isNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   392
    or:[position <= writeLimit]) ifTrue:[
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   393
        (position > collection size) ifTrue:[self growCollection].
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   394
        collection at:position put:anObject.
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   395
        (position > readLimit) ifTrue:[readLimit := position].
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   396
        position := position + 1.
838
67a53cceaab1 no global refs
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   397
    ] ifFalse:[
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
   398
        WriteErrorSignal raiseErrorString:'write beyond writeLimit'
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   399
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
    ^anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   402
a27a279701f8 Initial revision
claus
parents:
diff changeset
   403
nextPutAll:aCollection
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   404
    "append all elements of the argument, aCollection to the stream.
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   405
     Redefined to avoid count grows of the underlying collection -
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   406
     instead a single grow on the final size is performed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   407
a27a279701f8 Initial revision
claus
parents:
diff changeset
   408
    |nMore final|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   409
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   410
    collection isNil ifTrue:[
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   411
	^ super nextPutAll:aCollection
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   412
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   413
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   414
    nMore := aCollection size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   415
    final := position + nMore - 1.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   416
    (writeLimit notNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   417
    and:[final > writeLimit]) ifTrue:[
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   418
	final := writeLimit.
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   419
	nMore := final - position + 1
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   420
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   421
    (final > collection size) ifTrue:[
252
claus
parents: 95
diff changeset
   422
	self growCollection:final
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   423
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   424
    collection replaceFrom:position
252
claus
parents: 95
diff changeset
   425
			to:final
claus
parents: 95
diff changeset
   426
		      with:aCollection 
claus
parents: 95
diff changeset
   427
		startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
a27a279701f8 Initial revision
claus
parents:
diff changeset
   429
    position := position + nMore.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   430
    (position > readLimit) ifTrue:[readLimit := position - 1].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   431
    ^ aCollection
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   432
!
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   433
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   434
nextPutAll:aCollection startingAt:pos1 to:pos2
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   435
    "append some elements of the argument, aCollection to the stream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   436
     Redefined to avoid count grows of the underlying collection -
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   437
     instead a single grow on the final size is performed."
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   438
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   439
    |nMore final|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   440
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   441
    collection isNil ifTrue:[
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   442
        ^ super nextPutAll:aCollection startingAt:pos1 to:pos2
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   443
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   444
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   445
    nMore := pos2 - pos1 + 1.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   446
    final := position + nMore - 1.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   447
    (writeLimit notNil
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   448
    and:[final > writeLimit]) ifTrue:[
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   449
        final := writeLimit.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   450
        nMore := final - position + 1
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   451
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   452
    (final > collection size) ifTrue:[
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   453
        self growCollection:final
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   454
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   455
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   456
    collection replaceFrom:position
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   457
                        to:final
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   458
                      with:aCollection 
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   459
                startingAt:pos1.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   460
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   461
    position := position + nMore.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   462
    (position > readLimit) ifTrue:[readLimit := position - 1].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   463
    ^ aCollection
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   464
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   465
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   466
     |s|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   467
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   468
     s := '' writeStream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   469
     s nextPutAll:'hello '.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   470
     s nextPutAll:'1234world012345' startingAt:5 to:9.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   471
     s contents
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   472
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   473
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   474
    "Modified: 12.7.1996 / 10:31:36 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
   477
!WriteStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   478
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   479
version
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   480
    ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.45 2001-07-10 10:06:56 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   481
! !