Next Previous Up Top Contents Index

5.11 The STREAMS module

<wrapper-stream>

Open instantiable class

Summary

The class of wrapper-streams.

Superclasses

<stream>

Init-keywords

inner-stream:
An instance of <stream>.

Library

io

Module

streams

Description

The class that implements the basic wrapper-stream functionality.

It takes a required init-keyword inner-stream:, which is used to specify the wrapped stream.

The <wrapper-stream> class implements default methods for all of the stream protocol functions described in this document. Each default method on <wrapper-stream> simply "trampolines" to its inner stream.

Operations

inner-stream

inner-stream-setter

outer-stream-setter

Example

In the example below, <io-wrapper-stream>, a subclass of <wrapper-stream>, "passes on" functions such as
read-element and write-element by simply delegating these operations to the inner stream:

define method read-element (ws :: <io-wrapper-stream>,
                            #key on-end-of-stream)
    => (element)
  read-element(ws.inner-stream)
end method;
define method write-element (ws :: <io-wrapper-stream>,
                             element)
    => ()
  write-element(ws.inner-stream,element)
end method;

Assuming that <io-wrapper-stream> delegates all other operations to its inner stream, the following is sufficient to implement a 16-bit Unicode character stream wrapping an 8-bit character stream.

define class <unicode-stream> (<io-wrapper-stream>) 
end class;
define method read-element (s :: <unicode-stream>,
                            #key on-end-of-stream)
    => (ch :: <unicode-character>)
  with-stream-locked (s)
    let first-char =  read-element(s.inner-stream, 
                                   on-end-of-stream);
    let second-char = read-element(s.inner-stream, 
                                   on-end-of-stream);
  end;
  convert-byte-pair-to-unicode(first-char, second-char)
end method;
define method write-element  (s :: <unicode-stream>, 
                              c :: <character>)
    => ()
  let (first-char, second-char) 
      = convert-unicode-to-byte-pair(c);
  with-stream-locked (s)
    write-element(s.inner-stream, first-char);
    write-element(s.inner-stream, second-char)
  end;
  c
end method;
define method stream-position (s :: <unicode-stream>) 
  =>  (p :: <integer>)
  truncate/(stream-position(s.inner-stream), 2)
end method;
define method stream-position-setter  (p :: <integer>, 
                                s :: <unicode-stream>);
  stream-position(s.inner-stream) := p * 2
end method;

System and I/O Reference - 31 MAR 2000

Next Previous Up Top Contents Index