WriteStream.st
author Claus Gittinger <cg@exept.de>
Wed, 07 May 2003 16:15:41 +0200
changeset 7260 edfa8d6a6046
parent 7113 23182ef346a5
child 7261 f35fc9cee675
permissions -rw-r--r--
method category rename
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:]
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
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
"
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    60
								[exBegin]
2883
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
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    69
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    70
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    71
								[exBegin]
2883
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)
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    80
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    81
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    82
								[exBegin]
2883
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)
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    91
								[exEnd]
2883
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
6325
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
    96
!WriteStream methodsFor:'Compatibility - Dolphin'!
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
    97
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
    98
display:someObject
6871
1c4a799a048c display: use printOn instead of printString.
Claus Gittinger <cg@exept.de>
parents: 6326
diff changeset
    99
    someObject printOn:self.
1c4a799a048c display: use printOn instead of printString.
Claus Gittinger <cg@exept.de>
parents: 6326
diff changeset
   100
    "/ self nextPutAll:someObject printString
6325
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
   101
! !
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
   102
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   103
!WriteStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
contents
345
claus
parents: 329
diff changeset
   106
    "return the current contents (a collection) of the stream.
claus
parents: 329
diff changeset
   107
     Currently, this returns the actual collection if possible
claus
parents: 329
diff changeset
   108
     (and reset is implemented to create a new one) in contrast to
claus
parents: 329
diff changeset
   109
     ST80, where contents returns a copy and reset only sets the writePointer.
claus
parents: 329
diff changeset
   110
     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
   111
     (where things are written for the contents only) but may be incompatible
345
claus
parents: 329
diff changeset
   112
     with some applications. Time will show, if this is to be changed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   114
    |lastIndex|
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   115
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   116
    lastIndex := position - ZeroPosition.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   117
    collection size == lastIndex ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   118
	collection isFixedSize ifTrue:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   119
	    "
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   120
	     grow is expensive - return a copy.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   121
	     (is this what users of writeStream expect ?)
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   122
	    "
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   123
	    collection := collection copyFrom:1 to:lastIndex
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   124
	] ifFalse:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   125
	    collection grow:lastIndex
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   126
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
    ^ collection
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   129
3087
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   130
    "Modified: / 19.2.1997 / 08:57:28 / stefan"
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   131
    "Modified: / 30.10.1997 / 16:21:23 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   134
last
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   135
    "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
   136
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   137
    |position1Based|
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   138
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   139
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   140
    ^ collection at:(position1Based - 1).
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   141
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
     |s|
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
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   146
     s nextPut:$a.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   147
     s last.       
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   148
     s nextPut:$b.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   149
     s last.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   150
     s nextPut:$c.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   151
     s last.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   152
    "
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
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   155
last:n
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   156
    "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
   157
     Report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   158
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   159
    |position1Based|
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   160
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   161
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   162
    ^ collection copyFrom:(position1Based - n) to:(position1Based - 1).
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   163
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
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   166
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   167
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   168
     s nextPut:$a.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   169
     s last:1.       
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   170
     s nextPut:$b.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   171
     s last:1.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   172
     s last:2.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   173
     s nextPut:$c.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   174
     s last:1.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   175
     s last:2.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   176
     s last:3.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   177
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   178
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   179
329
claus
parents: 293
diff changeset
   180
reset
345
claus
parents: 329
diff changeset
   181
    "reset the stream; write anew.
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   182
     See the comment in WriteStream>>contents"
329
claus
parents: 293
diff changeset
   183
claus
parents: 293
diff changeset
   184
    collection := collection species new:(collection size).
claus
parents: 293
diff changeset
   185
    super reset
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   186
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   187
    "Modified: 19.2.1997 / 08:57:00 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
!WriteStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   192
position0Based:index0Based
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
    "redefined to allow positioning past the readLimit"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   195
    ((index0Based > collection size) or:[index0Based < 0]) ifTrue: [^ self positionError].
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   196
    position := index0Based + ZeroPosition
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
! !
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
!WriteStream methodsFor:'private'!
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
growCollection
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   202
    "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
   203
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
    self growCollection:10
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   205
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   206
    "Modified: 19.8.1997 / 17:53:28 / cg"
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
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   209
growCollection:minNewSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   210
    "grow the streamed collection to at least minNewSize"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
    |oldSize newSize newColl|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
    oldSize := collection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
    (oldSize == 0) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   216
	newSize := minNewSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   218
	newSize := oldSize * 2.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   219
	(newSize < minNewSize) ifTrue:[newSize := minNewSize].
611
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
    collection isFixedSize ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   222
	newColl := collection species new:newSize.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   223
	newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   224
	collection := newColl
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   226
	collection grow:newSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
    ].
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   228
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   229
    "Modified: 19.8.1997 / 17:53:11 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   230
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   231
7260
edfa8d6a6046 method category rename
Claus Gittinger <cg@exept.de>
parents: 7113
diff changeset
   232
!WriteStream methodsFor:'private-accessing'!
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   233
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
on:aCollection from:start to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
    "create and return a new stream for writing onto aCollection, where
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
     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
   237
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
    super on:aCollection from:start to:last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
    writeLimit := last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   241
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   242
!WriteStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   243
3098
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   244
isReadable 
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   245
    "return true if the receiver supports reading - thats not true"
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   246
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   247
    ^ false
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   248
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   249
    "Created: / 8.11.1997 / 14:06:07 / cg"
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   250
!
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   251
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   252
isWritable
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   253
    "return true, if writing is supported by the recevier.
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   254
     Always return true here"
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   255
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   256
    ^ true
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   257
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   258
    "Modified: 16.5.1996 / 14:44:49 / cg"
3031
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   259
!
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   260
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   261
size
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   262
    "return the current size"
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   263
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   264
    |position1Based|
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   265
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   266
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   267
    ^ position1Based - 1.
3031
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   268
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   269
    "Created: 14.10.1997 / 20:43:49 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   272
!WriteStream methodsFor:'reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
next
10
claus
parents: 5
diff changeset
   275
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
10
claus
parents: 5
diff changeset
   277
    self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
peek
10
claus
parents: 5
diff changeset
   281
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
10
claus
parents: 5
diff changeset
   283
    self shouldNotImplement
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   284
! !
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   285
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   286
!WriteStream methodsFor:'testing'!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   287
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   288
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   289
    "return true, if the contents of the stream is empty"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   290
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   291
    ^ position == ZeroPosition
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   292
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   293
    "Created: 14.10.1997 / 20:44:37 / cg"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   294
! !
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   295
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
!WriteStream methodsFor:'writing'!
369
claus
parents: 359
diff changeset
   297
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
    "append anObject count times to the receiver.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
     Redefined to avoid count grows of the underlying collection -
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
     instead a single grow on the final size is performed."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   303
    |final position1Based|
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
    (collection isNil or:[writeLimit notNil]) ifTrue:[
7113
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   306
        ^ super next:count put:anObject
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
    ].
369
claus
parents: 359
diff changeset
   308
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   309
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   310
    final := position1Based + count - 1.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    (final > collection size) ifTrue:[
7113
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   312
        self growCollection:final
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
    ].
369
claus
parents: 359
diff changeset
   314
7113
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   315
    position1Based to:final do:[:index |
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   316
        collection at:index put:anObject.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
    ].
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   318
    position1Based := position1Based + count.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   319
    (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   320
    position := position1Based - 1 + ZeroPosition.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    ^ anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   323
5198
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   324
next:n putAll:aCollection startingAt:pos1
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   325
    "append some elements of the argument, aCollection to the stream."
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   326
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   327
    ^ self nextPutAll:aCollection startingAt:pos1 to:pos1+n-1
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   328
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   329
    "
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   330
     |s|
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   331
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   332
     s := '' writeStream.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   333
     s nextPutAll:'hello '.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   334
     s next:5 putAll:'1234world012345' startingAt:5.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   335
     s contents   
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   336
    "
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   337
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   338
    "Modified: 12.7.1996 / 10:31:36 / cg"
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   339
!
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   340
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   341
nextPut:anObject
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   342
    "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
   343
     Specially tuned for appending to String, ByteArray and Array streams."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   344
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   345
%{  /* NOCONTEXT */
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   346
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   347
    REGISTER int pos;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   348
    unsigned ch;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   349
    OBJ coll;
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   350
    OBJ p, wL, rL;
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   351
    int __readLimit = -1;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   352
1136
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   353
    coll = __INST(collection);
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   354
    p = __INST(position);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   355
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2883
diff changeset
   356
#ifndef NO_PRIM_STREAM
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   357
    if (__isNonNilObject(coll) && __isSmallInteger(p)) {
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   358
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   359
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   360
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   361
	wL = __INST(writeLimit);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   362
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   363
	if ((wL == nil)
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   364
	 || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   365
	    OBJ cls;
252
claus
parents: 95
diff changeset
   366
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   367
	    cls = __qClass(coll);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   368
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   369
	    rL = __INST(readLimit);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   370
	    if (__isSmallInteger(rL)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   371
		__readLimit = __intVal(rL);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   372
	    }
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   373
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   374
	    if (cls == @global(String)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   375
		if (__isCharacter(anObject) 
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   376
		 && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   377
		 && (pos <= __stringSize(coll))) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   378
		    __StringInstPtr(coll)->s_element[pos-1] = ch;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   379
		    if ((__readLimit >= 0) && (pos >= __readLimit)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   380
			__INST(readLimit) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   381
		    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   382
		    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   383
		    RETURN ( anObject );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   384
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   385
	    } else if (cls == @global(ByteArray)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   386
		if (__isSmallInteger(anObject) 
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   387
		 && ((ch = __intVal(anObject)) <= 255) /* ch is unsigned */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   388
		 && (pos <= __byteArraySize(coll))) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   389
		    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   390
		    if ((__readLimit >= 0) && (pos >= __readLimit)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   391
			__INST(readLimit) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   392
		    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   393
		    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   394
		    RETURN ( anObject );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   395
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   396
	    } else if (cls == @global(Array)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   397
		if (pos <= __arraySize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   398
		     __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   399
		    __STORE(coll, anObject);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   400
		    if ((__readLimit >= 0) && (pos >= __readLimit)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   401
			__INST(readLimit) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   402
		    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   403
		    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   404
		    RETURN ( anObject );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   405
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   406
	    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   407
	}
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   408
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2883
diff changeset
   409
#endif
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   410
%}.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   411
    (writeLimit isNil
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   412
    or:[(position + 1 - ZeroPosition) <= writeLimit]) ifTrue:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   413
	((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   414
	collection at:(position + 1 - ZeroPosition) put:anObject.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   415
	((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   416
	position := position + 1.
838
67a53cceaab1 no global refs
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   417
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   418
	WriteErrorSignal raiseErrorString:'write beyond writeLimit'
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   419
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   420
    ^anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   421
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   422
a27a279701f8 Initial revision
claus
parents:
diff changeset
   423
nextPutAll:aCollection
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   424
    "append all elements of the argument, aCollection to the stream.
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   425
     Redefined to avoid count grows of the underlying collection -
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   426
     instead a single grow on the final size is performed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   428
    |nMore final position1Based|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   429
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   430
    collection isNil ifTrue:[
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   431
	^ super nextPutAll:aCollection
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   432
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   433
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   434
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   435
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   436
    nMore := aCollection size.
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   437
    final := position1Based + nMore - 1.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   438
    (writeLimit notNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   439
    and:[final > writeLimit]) ifTrue:[
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   440
	final := writeLimit.
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   441
	nMore := final - position1Based + 1
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   442
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   443
    (final > collection size) ifTrue:[
252
claus
parents: 95
diff changeset
   444
	self growCollection:final
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   445
    ].
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   446
    collection replaceFrom:position1Based
252
claus
parents: 95
diff changeset
   447
			to:final
claus
parents: 95
diff changeset
   448
		      with:aCollection 
claus
parents: 95
diff changeset
   449
		startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   451
    position1Based := position1Based + nMore.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   452
    (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   453
    position := position1Based - 1 + ZeroPosition.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   454
    ^ aCollection
1539
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
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   457
nextPutAll:aCollection startingAt:pos1 to:pos2
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   458
    "append some elements of the argument, aCollection to the stream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   459
     Redefined to avoid count grows of the underlying collection -
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   460
     instead a single grow on the final size is performed."
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   461
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   462
    |nMore final position1Based|
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   463
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   464
    collection isNil ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   465
	^ super nextPutAll:aCollection startingAt:pos1 to:pos2
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   466
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   467
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   468
    position1Based := position - ZeroPosition + 1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   469
    nMore := pos2 - pos1 + 1.
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   470
    final := position1Based + nMore - 1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   471
    (writeLimit notNil
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   472
    and:[final > writeLimit]) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   473
	final := writeLimit.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   474
	nMore := final - position1Based + 1
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   475
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   476
    (final > collection size) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   477
	self growCollection:final
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   478
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   479
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   480
    collection replaceFrom:position1Based
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   481
			to:final
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   482
		      with:aCollection 
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   483
		startingAt:pos1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   484
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   485
    position1Based := position1Based + nMore.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   486
    (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   487
    position := position1Based - 1 + ZeroPosition.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   488
    ^ aCollection
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   489
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   490
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   491
     |s|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   492
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   493
     s := '' writeStream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   494
     s nextPutAll:'hello '.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   495
     s nextPutAll:'1234world012345' startingAt:5 to:9.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   496
     s contents
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   497
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   498
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   499
    "Modified: 12.7.1996 / 10:31:36 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   500
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   501
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
   502
!WriteStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   503
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   504
version
7260
edfa8d6a6046 method category rename
Claus Gittinger <cg@exept.de>
parents: 7113
diff changeset
   505
    ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.52 2003-05-07 14:14:43 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   506
! !