Merge from vendor branch HEIMDAL:
[dragonfly.git] / contrib / libio / indstream.h
1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
3
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)
8 any later version.
9
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.
14
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.
18
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.
24
25 Written by Per Bothner (bothner@cygnus.com). */
26
27 #ifndef _INDSTREAM_H
28 #define _INDSTREAM_H
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
33
34 #include <iostream.h>
35
36 extern "C++" {
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().
41
42 // An indirectbuf can be used to implement Common Lisp
43 // synonym-streams and two-way-streams.
44 //
45 // class synonymbuf : public indirectbuf {
46 //    Symbol *sym;
47 //    synonymbuf(Symbol *s) { sym = s; }
48 //    virtual streambuf *lookup_stream(int mode) {
49 //        return coerce_to_streambuf(lookup_value(sym)); }
50 // };
51
52 class indirectbuf : public streambuf {
53   protected:
54     streambuf *_get_stream;  // Optional cache for get_stream().
55     streambuf *_put_stream;  // Optional cache for put_stream().
56     int _delete_flags;
57   public:
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();
68     virtual int uflow();
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);
72     virtual int sync();
73     virtual int pbackfail(int c);
74 };
75 } // extern "C++"
76
77 #endif /* !_INDSTREAM_H */