Streams can be capable of input or output (or both), and may deal with characters or with binary elements. Thestream package provides a number of stream classes with different capabilities from which user defined streams can inherit. In our example the stream must be capable of input and output, and must read characters. The following code defines our stream class appropriately:
(defclass unicode-ls-stream
(stream:fundamental-character-input-stream
stream:fundamental-character-output-stream)
((file-stream :initform nil
:initarg :file-stream
:accessor ls-stream-file-stream)))
The new class,unicode-ls-stream, hasfundamental-character-input-stream andfundamental-character-output-stream as its superclasses, which means it inherits the relevant default character I/O methods. We shall be overriding some of these with more relevant and efficient implementations later.
Note that we have also provided a slot, calledfile-stream. This slot is a place holder for a Common Lisp file stream. When making an instance ofunicode-ls-stream we can create an instance of a file stream in this slot. This allows us to use the Common Lisp file stream functionality for reading from and writing to a file.
Class
fundamental-character-output-streamClass
stream fundamental-character-input-stream andfundamental-character-output-stream provide default methods for generic functions used for character input and character output respectively, and should therefore be included by stream classes concerned with these. The user can provide methods for these generic functions specialized on the user-defined classes.