diff -r e1b4369c61fb -r 1f0cdefb013f WriteStream.st --- a/WriteStream.st Fri Feb 25 14:05:47 1994 +0100 +++ b/WriteStream.st Fri Feb 25 14:07:09 1994 +0100 @@ -26,7 +26,7 @@ streamed-upon collection if it cannot grow. Thus its slightly incompatible to ST-80 since aStream contents does not always return the original collection. This will change soon. -$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.5 1993-11-08 02:32:41 claus Exp $ +$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.6 1994-02-25 13:07:09 claus Exp $ '! !WriteStream class methodsFor:'instance creation'! @@ -72,7 +72,7 @@ (aNumber < collection size) ifTrue:[writeLimit := aNumber] ! ! -!WriteStream methodsFor:'reading/writing'! +!WriteStream methodsFor:'reading'! next "catch read access to write stream - report an error" @@ -84,11 +84,75 @@ "catch read access to write stream - report an error" self shouldNotImplement -! +! ! + +!WriteStream methodsFor:'writing'! nextPut:anObject "append the argument, anObject to the stream" +%{ /* NOCONTEXT */ + +#ifdef NOTDEF + + REGISTER int pos; + unsigned ch; + OBJ coll; + + coll = _INST(collection); + if (_isNonNilObject(coll) + && _isSmallInteger(_INST(position))) { + + pos = _intVal(_INST(position)); + + if (_isSmallInteger(_INST(writeLimit)) + && (pos <= _intVal(_INST(writeLimit))) + && (pos > 0)) { + OBJ cls; + + cls = _qClass(coll); + if (cls == String) { + if (__isCharacter(anObject) + && (pos <= _stringSize(coll))) { + _StringInstPtr(coll)->s_element[pos-1] = _intVal(_characterVal(anObject)); + _INST(position) = _MKSMALLINT(pos + 1); + if (_isSmallInteger(_INST(readLimit)) + && (pos >= _intVal(_INST(readLimit)))) { + _INST(readLimit) = _MKSMALLINT(pos + 1); + } + RETURN ( anObject ); + } + } else if (cls == ByteArray) { + if (_isSmallInteger(anObject) + && ((ch = _intVal(anObject)) >= 0) + && (ch <= 255) + && (pos <= _byteArraySize(coll))) { + _ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; + _INST(position) = _MKSMALLINT(pos + 1); + if (_isSmallInteger(_INST(readLimit)) + && (pos >= _intVal(_INST(readLimit)))) { + _INST(readLimit) = _MKSMALLINT(pos + 1); + } + RETURN ( anObject ); + } + } else if (cls == Array) { + if (pos <= _arraySize(coll)) { + _ArrayInstPtr(coll)->a_element[pos-1] = anObject; + __STORE(coll, anObject); + _INST(position) = _MKSMALLINT(pos + 1); + if (_isSmallInteger(_INST(readLimit)) + && (pos >= _intVal(_INST(readLimit)))) { + _INST(readLimit) = _MKSMALLINT(pos + 1); + } + RETURN ( anObject ); + } + } + } + } +#endif + +%} +. (position > collection size) ifTrue:[self growCollection]. collection at:position put:anObject. (position > readLimit) ifTrue:[readLimit := position]. @@ -96,8 +160,28 @@ ^anObject ! +next:count put:anObject + "append anObject count times to the receiver. + Redefined to avoid count grows of the underlying collection - + instead a single grow on the final size is performed." + + |nMore final| + + final := position + count - 1. + (final > collection size) ifTrue:[ + self growCollection:final + ]. + collection atAll:(position to:final) put:anObject. + + position := position + count. + (position > readLimit) ifTrue:[readLimit := position - 1]. + ^ anObject +! + nextPutAll:aCollection - "append all elements of the argument, aCollection to the stream" + "append all elements of the argument, aCollection to the stream. + Redefined to avoid count grows of the underlying collection - + instead a single grow on the final size is performed." |nMore final| @@ -114,62 +198,23 @@ position := position + nMore. (position > readLimit) ifTrue:[readLimit := position - 1]. ^ aCollection -! - -cr - "append a carriage-return to the stream" - - self nextPut:(Character cr) -! - -tab - "append a tab-character to the stream" - - self nextPut:(Character tab) -! - -crTab - "append a carriage-return followed by a tab to the stream" - - self nextPut:(Character cr). - self nextPut:(Character tab) -! - -space - "append a space character to the receiver-stream" - - self nextPut:(Character space) -! - -spaces:count - "append count space-characters to the receiver-stream" - - 1 to:count do:[:dummy | - self nextPut:(Character space) - ] -! - -ff - "append a form-feed (new-pagee) to the receiver-stream" - - self nextPut:(Character ff) ! ! !WriteStream methodsFor:'ignored'! bold - "ignore font change - this allows WriteStreams to be compatible - to PrinterStreams" + "change font to bold - ignored here. + - this allows WriteStreams to be compatible to PrinterStreams" ! italic - "ignore font change - this allows WriteStreams to be compatible - to PrinterStreams" + "change font to italic - ignored here. + - this allows WriteStreams to be compatible to PrinterStreams" ! normal - "ignore font change - this allows WriteStreams to be compatible - to PrinterStreams" + "change font to normal - ignored here. + - this allows WriteStreams to be compatible to PrinterStreams" ! ! !WriteStream methodsFor:'private'!