1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
4 This file is part of the GNU IO Library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License.
25 Written by Per Bothner (bothner@cygnus.com). */
37 // An indirectbuf is one that forwards all of its I/O requests
38 // to another streambuf.
39 // All get-related requests are sent to get_stream().
40 // All put-related requests are sent to put_stream().
42 // An indirectbuf can be used to implement Common Lisp
43 // synonym-streams and two-way-streams.
45 // class synonymbuf : public indirectbuf {
47 // synonymbuf(Symbol *s) { sym = s; }
48 // virtual streambuf *lookup_stream(int mode) {
49 // return coerce_to_streambuf(lookup_value(sym)); }
52 class indirectbuf
: public streambuf
{
54 streambuf
*_get_stream
; // Optional cache for get_stream().
55 streambuf
*_put_stream
; // Optional cache for put_stream().
58 streambuf
*get_stream()
59 { return _get_stream
? _get_stream
: lookup_stream(ios::in
); }
60 streambuf
*put_stream()
61 { return _put_stream
? _put_stream
: lookup_stream(ios::out
); }
62 virtual streambuf
*lookup_stream(int/*mode*/) { return NULL
; } // ERROR!
63 indirectbuf(streambuf
*get
=NULL
, streambuf
*put
=NULL
, int delete_mode
=0);
64 virtual ~indirectbuf();
65 virtual streamsize
xsputn(const char* s
, streamsize n
);
66 virtual streamsize
xsgetn(char* s
, streamsize n
);
67 virtual int underflow();
69 virtual int overflow(int c
= EOF
);
70 virtual streampos
seekoff(streamoff
, _seek_dir
, int mode
=ios::in
|ios::out
);
71 virtual streampos
seekpos(streampos pos
, int mode
= ios::in
|ios::out
);
73 virtual int pbackfail(int c
);
77 #endif /* !_INDSTREAM_H */