WriteStream.st
author Claus Gittinger <cg@exept.de>
Fri, 19 Jul 1996 12:26:56 +0200
changeset 1584 cad4f2c515c7
parent 1541 6ed5feddc4ed
child 1965 4ca38574df3b
permissions -rw-r--r--
nextPut: slightly modified
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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
PositionableStream subclass:#WriteStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    14
	instanceVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    15
	classVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    16
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    17
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
    20
!WriteStream  class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
252
claus
parents: 95
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    36
documentation
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    37
"
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
    Streams for writing into - this implementation currently DOES change the 
261
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    39
    identity if the streamed-upon collection IF it cannot grow easily. 
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    40
    Collections which cannot grow easily are for example: Array, ByteArray and String.
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    Thus it is slightly incompatible to ST-80 since 'aStream contents' does 
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    not always return the original collection. This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    43
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    44
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    45
        Claus Gittinger
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    46
"
345
claus
parents: 329
diff changeset
    47
! !
claus
parents: 329
diff changeset
    48
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    49
!WriteStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    50
a27a279701f8 Initial revision
claus
parents:
diff changeset
    51
contents
345
claus
parents: 329
diff changeset
    52
    "return the current contents (a collection) of the stream.
claus
parents: 329
diff changeset
    53
     Currently, this returns the actual collection if possible
claus
parents: 329
diff changeset
    54
     (and reset is implemented to create a new one) in contrast to
claus
parents: 329
diff changeset
    55
     ST80, where contents returns a copy and reset only sets the writePointer.
claus
parents: 329
diff changeset
    56
     The ST/X behavior creates less temporary garbage in the normal case
claus
parents: 329
diff changeset
    57
     (whre things are written for the contents only) but may be incompatible
claus
parents: 329
diff changeset
    58
     with some applications. Time will show, if this is to be changed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    59
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    60
    |lastIndex|
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    61
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    62
    lastIndex := position - 1.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    63
    collection size == lastIndex ifFalse:[
252
claus
parents: 95
diff changeset
    64
	collection isFixedSize ifTrue:[
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    65
	    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    66
	     grow is expensive - return a copy.
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    67
	     (is this what users of writeStream expect ?
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    68
	    "
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    69
	    collection := collection copyFrom:1 to:lastIndex
252
claus
parents: 95
diff changeset
    70
	] ifFalse:[
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
    71
	    collection grow:lastIndex
252
claus
parents: 95
diff changeset
    72
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
    ^ collection
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
329
claus
parents: 293
diff changeset
    77
reset
345
claus
parents: 329
diff changeset
    78
    "reset the stream; write anew.
claus
parents: 329
diff changeset
    79
     See the comment in WriteStream>>contnts"
329
claus
parents: 293
diff changeset
    80
claus
parents: 293
diff changeset
    81
    collection := collection species new:(collection size).
claus
parents: 293
diff changeset
    82
    super reset
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
!WriteStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
position:index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
    "redefined to allow positioning past the readLimit"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
    ((index > (collection size + 1)) or:[index < 0]) ifTrue: [^ self positionError].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
    position := index
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
!WriteStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
growCollection
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    97
    self growCollection:10
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    98
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    99
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
growCollection:minNewSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
    "grow the streamed collection to at least minNewSize"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
    |oldSize newSize newColl|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   104
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
    oldSize := collection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
    (oldSize == 0) ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
	newSize := minNewSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
    ] ifFalse:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
	newSize := oldSize * 2.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
	[newSize < minNewSize] whileTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
	    newSize := newSize * 2
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
	]
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
    collection isFixedSize ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
	newColl := collection species new:newSize.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   116
	newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   117
	collection := newColl
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   118
    ] ifFalse:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   119
	collection grow:newSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   123
!WriteStream methodsFor:'private accessing'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
on:aCollection from:start to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   126
    "create and return a new stream for writing onto aCollection, where
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   127
     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
   128
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
    super on:aCollection from:start to:last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
    writeLimit := last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   131
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   132
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   133
!WriteStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   134
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   135
isWritable
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   136
    "return true, if writing is supported by the recevier.
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   137
     Always return true here"
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   138
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   139
    ^ true
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   140
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   141
    "Modified: 16.5.1996 / 14:44:49 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   142
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   143
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   144
!WriteStream methodsFor:'reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
next
10
claus
parents: 5
diff changeset
   147
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
10
claus
parents: 5
diff changeset
   149
    self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   151
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
peek
10
claus
parents: 5
diff changeset
   153
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
10
claus
parents: 5
diff changeset
   155
    self shouldNotImplement
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   156
! !
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   157
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   158
!WriteStream methodsFor:'writing'!
369
claus
parents: 359
diff changeset
   159
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   160
next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   161
    "append anObject count times to the receiver.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   162
     Redefined to avoid count grows of the underlying collection -
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   163
     instead a single grow on the final size is performed."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   165
    |final|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   166
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   167
    (collection isNil or:[writeLimit notNil]) ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   168
	^ super next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
    ].
369
claus
parents: 359
diff changeset
   170
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
    final := position + count - 1.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   172
    (final > collection size) ifTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
	self growCollection:final
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
    ].
369
claus
parents: 359
diff changeset
   175
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
    position to:final do:[:index |
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
	collection at:index put:anObject.
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 := position + count.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
    (position > readLimit) ifTrue:[readLimit := position - 1].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
    ^ anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
nextPut:anObject
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   185
    "append the argument, anObject to the stream.
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   186
     Special tuned for appending to String, ByteArray and Array streams."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   188
%{  /* NOCONTEXT */
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   189
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   190
    REGISTER int pos;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   191
    unsigned ch;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   192
    OBJ coll;
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   193
    OBJ p, l, rL;
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   194
    int __readLimit = -1;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   195
1136
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   196
    coll = __INST(collection);
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   197
    p = __INST(position);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   198
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   199
    if (__isNonNilObject(coll) && __isSmallInteger(p)) {
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   200
        pos = __intVal(p);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   201
        l = __INST(writeLimit);
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
   202
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   203
        if ((l == nil)
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   204
         || (__isSmallInteger(l) && (pos <= __intVal(l)))) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   205
            OBJ cls;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   206
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   207
            cls = __qClass(coll);
252
claus
parents: 95
diff changeset
   208
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   209
            rL = __INST(readLimit);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   210
            if (__isSmallInteger(rL)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   211
                __readLimit = __intVal(rL);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   212
            }
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   213
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   214
            if (cls == @global(String)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   215
                if (__isCharacter(anObject) 
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   216
                 && (pos <= __stringSize(coll))) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   217
                    ch = __intVal(_characterVal(anObject));
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   218
                    if ((ch >= 0) && (ch <= 255)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   219
                        __StringInstPtr(coll)->s_element[pos-1] = ch;
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   220
                        __INST(position) = __MKSMALLINT(pos + 1);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   221
                        if ((__readLimit >= 0) && (pos >= __readLimit)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   222
                            __INST(readLimit) = __MKSMALLINT(pos);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   223
                        }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   224
                        RETURN ( anObject );
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   225
                    }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   226
                }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   227
            } else if (cls == @global(ByteArray)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   228
                if (__isSmallInteger(anObject) 
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   229
                 && ((ch = __intVal(anObject)) >= 0)
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   230
                 && (ch <= 255)
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   231
                 && (pos <= _byteArraySize(coll))) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   232
                    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   233
                    __INST(position) = __MKSMALLINT(pos + 1);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   234
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   235
                        __INST(readLimit) = __MKSMALLINT(pos);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   236
                    }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   237
                    RETURN ( anObject );
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   238
                }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   239
            } else if (cls == @global(Array)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   240
                if (pos <= _arraySize(coll)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   241
                     __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   242
                    __STORE(coll, anObject);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   243
                    __INST(position) = __MKSMALLINT(pos + 1);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   244
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   245
                        __INST(readLimit) = __MKSMALLINT(pos);
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   246
                    }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   247
                    RETURN ( anObject );
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   248
                }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   249
            }
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   250
        }
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   251
    }
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   252
%}.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   253
    (writeLimit isNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   254
    or:[position <= writeLimit]) ifTrue:[
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   255
        (position > collection size) ifTrue:[self growCollection].
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   256
        collection at:position put:anObject.
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   257
        (position > readLimit) ifTrue:[readLimit := position].
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   258
        position := position + 1.
838
67a53cceaab1 no global refs
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   259
    ] ifFalse:[
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   260
        WriteErrorSignal raiseErrorString:'write behond writeLimit'
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   261
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
    ^anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
nextPutAll:aCollection
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   266
    "append all elements of the argument, aCollection to the stream.
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   267
     Redefined to avoid count grows of the underlying collection -
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   268
     instead a single grow on the final size is performed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
    |nMore final|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   272
    collection isNil ifTrue:[
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   273
	^ super nextPutAll:aCollection
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   274
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   275
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
    nMore := aCollection size.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
    final := position + nMore - 1.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   278
    (writeLimit notNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   279
    and:[final > writeLimit]) ifTrue:[
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   280
	final := writeLimit.
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   281
	nMore := final - position + 1
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   282
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   283
    (final > collection size) ifTrue:[
252
claus
parents: 95
diff changeset
   284
	self growCollection:final
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   285
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   286
    collection replaceFrom:position
252
claus
parents: 95
diff changeset
   287
			to:final
claus
parents: 95
diff changeset
   288
		      with:aCollection 
claus
parents: 95
diff changeset
   289
		startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
a27a279701f8 Initial revision
claus
parents:
diff changeset
   291
    position := position + nMore.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
    (position > readLimit) ifTrue:[readLimit := position - 1].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
    ^ aCollection
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   294
!
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   295
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   296
nextPutAll:aCollection startingAt:pos1 to:pos2
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   297
    "append some elements of the argument, aCollection to the stream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   298
     Redefined to avoid count grows of the underlying collection -
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   299
     instead a single grow on the final size is performed."
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   300
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   301
    |nMore final|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   302
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   303
    collection isNil ifTrue:[
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   304
        ^ super nextPutAll:aCollection startingAt:pos1 to:pos2
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   305
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   306
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   307
    nMore := pos2 - pos1 + 1.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   308
    final := position + nMore - 1.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   309
    (writeLimit notNil
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   310
    and:[final > writeLimit]) ifTrue:[
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   311
        final := writeLimit.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   312
        nMore := final - position + 1
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   313
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   314
    (final > collection size) ifTrue:[
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   315
        self growCollection:final
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   316
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   317
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   318
    collection replaceFrom:position
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   319
                        to:final
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   320
                      with:aCollection 
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   321
                startingAt:pos1.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   322
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   323
    position := position + nMore.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   324
    (position > readLimit) ifTrue:[readLimit := position - 1].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   325
    ^ aCollection
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   326
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   327
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   328
     |s|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   329
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   330
     s := '' writeStream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   331
     s nextPutAll:'hello '.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   332
     s nextPutAll:'1234world012345' startingAt:5 to:9.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   333
     s contents
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   334
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   335
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   336
    "Modified: 12.7.1996 / 10:31:36 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   337
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   338
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   339
!WriteStream  class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   340
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   341
version
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   342
    ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.31 1996-07-19 10:26:56 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   343
! !