home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / MYSTREAM.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  95 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. // Mystream.h
  4. // iostream interface for class Myio
  5. // Defines the following classes:
  6. //  Mystreambuf     derived from streambuf - buffer management & I/O interface
  7. //  Mystreambase    base class used for initialisation & object reference
  8. //  Myiostream      customised iostream, derived from iostream/Mystreambase
  9. //
  10. // Written by David L Nugent, June 1993
  11. //
  12.  
  13. # if !defined(_Mystream_h)
  14. # define _Mystream_h 1
  15. # include <iostream.h>
  16. # include "Myio.h"
  17.  
  18.     //
  19.     // Mystreambuf
  20.     // This is the class which does all the actual I/O
  21.     // handling and (optional) buffer management
  22.     //
  23.  
  24. class Mystreambuf : public streambuf
  25. {
  26.  
  27.   public:
  28.  
  29.     Mystreambuf (Myio * mPtr);
  30.  
  31.   protected:
  32.  
  33.     virtual int overflow (int = EOF);
  34.     virtual int underflow ();
  35.     virtual int sync ();
  36.  
  37.   private:
  38.  
  39.     Myio * mptr;    // Points to the Myio instance to
  40.                     // which this stream is attached
  41.     char _back[2];  // Holder for putback
  42.  
  43. };
  44.  
  45.  
  46. class Mystreambase : public virtual ios
  47. {
  48.  
  49.   public:
  50.  
  51.     Mystreambase (Myio * mPtr);
  52.     Mystreambuf * rdbuf (void);
  53.  
  54.   protected:
  55.  
  56.     Mystreambuf mystreambuf;
  57.  
  58. };
  59.  
  60. inline
  61. Mystreambase::Mystreambase (Myio * mPtr)
  62.     : mystreambuf (mPtr)
  63. {}
  64.  
  65. inline Mystreambuf *
  66. Mystreambase::rdbuf (void)
  67.     {   return &mystreambuf;    }
  68.  
  69.  
  70. class Mystream : public Mystreambase, public iostream
  71. {
  72.  
  73.   public:
  74.  
  75.     Mystream (Myio * mPtr);
  76.     ~Mystream (void);
  77. };
  78.  
  79.     //
  80.     // class Mystream constructor
  81.     // This uses Mystreambase to set up the Mystreambuf
  82.     // which can then be used to initialise iostream.
  83.     //
  84.  
  85. inline
  86. Mystream::Mystream (Myio * m)
  87.     : Mystreambase (m), iostream (rdbuf())
  88. {}
  89.  
  90. inline
  91. Mystream::~Mystream (void)
  92.     {}
  93.  
  94. # endif     // _Mystream_h
  95.