portable way to define new stream classes?
From: Frank Buss (fb_at_frank-buss.de)
Date: 02/21/05
- Previous message: Andreas Thiele: "Re: MCL for OS X worth the price?"
- Next in thread: Steven M. Haflich: "Re: portable way to define new stream classes?"
- Reply: Steven M. Haflich: "Re: portable way to define new stream classes?"
- Reply: Steven E. Harris: "Re: portable way to define new stream classes?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Feb 2005 00:51:13 +0000 (UTC)
I use a framework, which expects streams. But sometimes I need
in-memory streams, because I don't want to create temporary files.
In Lispworks I can define my own stream classes (see below), but how can
I implement this in Common Lisp?
I have the source code of the framework and can change it. One idea
would be to use a stream-wrapper class, which defines my-write-byte and
my-read-byte methods and derived classes for my memory streams and a
derived class for delegating it to a system stream, but this doesn't
sound very elegant.
(defclass byte-output-stream (stream:fundamental-character-output-stream)
((content :initform (make-array 0
:element-type '(unsigned-byte 8)
:adjustable t
:fill-pointer t)))
(:documentation
"A byte output stream, which writes to an adjustable array."))
(defmethod stream:stream-write-byte ((self byte-output-stream) byte)
(vector-push-extend byte (slot-value self 'content)))
(defmethod stream-element-type ((stream byte-output-stream)) '(unsigned-byte 8))
(defclass byte-input-stream (stream:fundamental-character-input-stream)
((content :initarg :content)
(position :initform 0))
(:documentation
"A byte input stream, which reads from an array."))
(defmethod stream:stream-read-byte ((self byte-input-stream))
(with-slots (content position) self
(let ((result (aref content position)))
(incf position)
result)))
(defmethod stream-element-type ((stream byte-input-stream)) '(unsigned-byte 8))
-- Frank Buß, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
- Previous message: Andreas Thiele: "Re: MCL for OS X worth the price?"
- Next in thread: Steven M. Haflich: "Re: portable way to define new stream classes?"
- Reply: Steven M. Haflich: "Re: portable way to define new stream classes?"
- Reply: Steven E. Harris: "Re: portable way to define new stream classes?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|