1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- GRAY stream mixin.
6 (in-package :iolib.base
)
8 (defclass trivial-gray-stream-mixin
() ())
10 (defgeneric stream-read-sequence
11 (stream sequence start end
&key
&allow-other-keys
))
12 (defgeneric stream-write-sequence
13 (stream sequence start end
&key
&allow-other-keys
))
15 (defgeneric stream-file-position
(stream))
16 (defgeneric (setf stream-file-position
) (newval stream
))
18 (defmethod stream-write-string
19 ((stream trivial-gray-stream-mixin
) seq
&optional start end
)
20 (stream-write-sequence stream seq
(or start
0) (or end
(length seq
))))
22 ;; Implementations should provide this default method, I believe, but
23 ;; at least sbcl and allegro don't.
24 (defmethod stream-terpri ((stream trivial-gray-stream-mixin
))
25 (write-char #\newline stream
))
27 (defmethod stream-file-position ((stream trivial-gray-stream-mixin
))
30 (defmethod (setf stream-file-position
)
31 (newval (stream trivial-gray-stream-mixin
))
32 (declare (ignore newval
))
37 (defmethod excl:stream-read-sequence
38 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
39 (stream-read-sequence s seq
(or start
0) (or end
(length seq
))))
40 (defmethod stream:stream-write-sequence
41 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
42 (stream-write-sequence s seq
(or start
0) (or end
(length seq
)))))
46 (defmethod ext:stream-read-sequence
47 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
48 (stream-read-sequence s seq
(or start
0) (or end
(length seq
))))
49 (defmethod ext:stream-write-sequence
50 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
51 (stream-write-sequence s seq
(or start
0) (or end
(length seq
)))))
55 (defmethod stream:stream-read-sequence
56 ((s trivial-gray-stream-mixin
) seq start end
)
57 (stream-read-sequence s seq start end
))
58 (defmethod stream:stream-write-sequence
59 ((s trivial-gray-stream-mixin
) seq start end
)
60 (stream-write-sequence s seq start end
))
62 (defmethod stream:stream-file-position
((stream trivial-gray-stream-mixin
))
63 (stream-file-position stream
))
64 (defmethod (setf stream
:stream-file-position
)
65 (newval (stream trivial-gray-stream-mixin
))
66 (setf (stream-file-position stream
) newval
)))
70 (defmethod ccl:stream-read-vector
71 ((s trivial-gray-stream-mixin
) seq start end
)
72 (stream-read-sequence s seq start end
))
73 (defmethod ccl:stream-write-vector
74 ((s trivial-gray-stream-mixin
) seq start end
)
75 (stream-write-sequence s seq start end
)))
79 (defmethod gray:stream-read-byte-sequence
80 ((s trivial-gray-stream-mixin
)
82 &optional start end no-hang interactive
)
84 (error "this stream does not support the NO-HANG argument"))
86 (error "this stream does not support the INTERACTIVE argument"))
87 (stream-read-sequence s seq start end
))
89 (defmethod gray:stream-write-byte-sequence
90 ((s trivial-gray-stream-mixin
)
92 &optional start end no-hang interactive
)
94 (error "this stream does not support the NO-HANG argument"))
96 (error "this stream does not support the INTERACTIVE argument"))
97 (stream-write-sequence s seq start end
))
99 (defmethod gray:stream-read-char-sequence
100 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
101 (stream-read-sequence s seq start end
))
103 (defmethod gray:stream-write-char-sequence
104 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
105 (stream-write-sequence s seq start end
))
107 (defmethod gray:stream-position
((stream trivial-gray-stream-mixin
) position
)
109 (setf (stream-file-position stream
) position
)
110 (stream-file-position stream
))))
114 (defmethod sb-gray:stream-read-sequence
115 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
116 (stream-read-sequence s seq
(or start
0) (or end
(length seq
))))
117 (defmethod sb-gray:stream-write-sequence
118 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
119 (stream-write-sequence s seq
(or start
0) (or end
(length seq
))))
121 (defmethod sb-gray:stream-line-length
((stream trivial-gray-stream-mixin
))
126 (defmethod gray:stream-read-sequence
127 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
128 (stream-read-sequence s seq
(or start
0) (or end
(length seq
))))
129 (defmethod gray:stream-write-sequence
130 ((s trivial-gray-stream-mixin
) seq
&optional start end
)
131 (stream-write-sequence s seq
(or start
0) (or end
(length seq
)))))