home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / cplus261.zip / gcc2 / gppincl / indstream.h < prev    next >
C/C++ Source or Header  |  1994-11-03  |  3KB  |  75 lines

  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 GNU CC; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, 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. // An indirectbuf is one that forwards all of its I/O requests
  37. // to another streambuf.
  38. // All get-related requests are sent to get_stream().
  39. // All put-related requests are sent to put_stream().
  40.  
  41. // An indirectbuf can be used to implement Common Lisp
  42. // synonym-streams and two-way-streams.
  43. //
  44. // class synonymbuf : public indirectbuf {
  45. //    Symbol *sym;
  46. //    synonymbuf(Symbol *s) { sym = s; }
  47. //    virtual streambuf *lookup_stream(int mode) {
  48. //        return coerce_to_streambuf(lookup_value(sym)); }
  49. // };
  50.  
  51. class indirectbuf : public streambuf {
  52.   protected:
  53.     streambuf *_get_stream;  // Optional cache for get_stream().
  54.     streambuf *_put_stream;  // Optional cache for put_stream().
  55.     int _delete_flags;
  56.   public:
  57.     streambuf *get_stream()
  58.     { return _get_stream ? _get_stream : lookup_stream(ios::in); }
  59.     streambuf *put_stream()
  60.     { return _put_stream ? _put_stream : lookup_stream(ios::out); }
  61.     virtual streambuf *lookup_stream(int/*mode*/) { return NULL; } // ERROR!
  62.     indirectbuf(streambuf *get=NULL, streambuf *put=NULL, int delete_mode=0);
  63.     virtual ~indirectbuf();
  64.     virtual int xsputn(const char* s, int n);
  65.     virtual int xsgetn(char* s, int n);
  66.     virtual int underflow();
  67.     virtual int overflow(int c = EOF);
  68.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  69.     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
  70.     virtual int sync();
  71.     virtual int pbackfail(int c);
  72. };
  73.  
  74. #endif /* !_INDSTREAM_H */
  75.