home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / STREAMBU.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  20.1 KB  |  805 lines

  1. #ifndef __STREAMBU_H
  2. #define __STREAMBU_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __STD_STREAMBUF__
  6. #define __STD_STREAMBUF__
  7.  
  8. /***************************************************************************
  9.  *
  10.  * streambuf - Declarations for the Standard Library stream buffers
  11.  *
  12.  ***************************************************************************
  13.  *
  14.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  15.  * ALL RIGHTS RESERVED
  16.  *
  17.  * The software and information contained herein are proprietary to, and
  18.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  19.  * intends to preserve as trade secrets such software and information.
  20.  * This software is furnished pursuant to a written license agreement and
  21.  * may be used, copied, transmitted, and stored only in accordance with
  22.  * the terms of such license and with the inclusion of the above copyright
  23.  * notice.  This software and information or any other copies thereof may
  24.  * not be provided or otherwise made available to any other person.
  25.  *
  26.  * Notwithstanding any other lease or license that may pertain to, or
  27.  * accompany the delivery of, this computer software and information, the
  28.  * rights of the Government regarding its use, reproduction and disclosure
  29.  * are as set forth in Section 52.227-19 of the FARS Computer
  30.  * Software-Restricted Rights clause.
  31.  * 
  32.  * Use, duplication, or disclosure by the Government is subject to
  33.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  34.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  35.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  36.  * P.O. Box 2328, Corvallis, Oregon 97339.
  37.  *
  38.  * This computer software and information is distributed with "restricted
  39.  * rights."  Use, duplication or disclosure is subject to restrictions as
  40.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  41.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  42.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  43.  * then the "Alternate III" clause applies.
  44.  *
  45.  **************************************************************************/
  46.  
  47. #include <stdcomp.h>
  48.  
  49. #ifndef _RWSTD_NO_NEW_HEADER
  50. #include <cstdlib>
  51. #else
  52. #include <stdlib.h>
  53. #endif
  54.  
  55. #include <ios>
  56.  
  57. #ifndef _RWSTD_NO_NAMESPACE
  58. namespace std {
  59. #endif
  60.  
  61.   template<class charT, class traits>
  62.   class _RWSTDExportTemplate basic_streambuf {
  63.  
  64.   public:
  65.     //
  66.     // Types:
  67.     //
  68.     typedef charT                                       char_type;
  69.     typedef _TYPENAME traits::int_type                  int_type;
  70.     typedef _TYPENAME traits::pos_type                  pos_type;
  71.     typedef _TYPENAME traits::off_type                  off_type;
  72.     typedef traits                                      traits_type;
  73.  
  74.     virtual ~basic_streambuf();
  75.  
  76.     locale pubimbue( const locale& loc);
  77.     locale getloc() const; 
  78.  
  79.     inline  basic_streambuf<char_type, traits> *
  80.     pubsetbuf(char_type *s, streamsize n);
  81.  
  82.     inline pos_type pubseekoff(off_type off, ios_base::seekdir way,
  83.                                ios_base::openmode which =
  84.                                ios_base::in | ios_base::out);
  85.  
  86.     inline pos_type pubseekpos(pos_type sp, ios_base::openmode which =
  87.                                ios_base::in | ios_base::out);
  88.  
  89.     inline int pubsync( );
  90.     inline ios_base::openmode which_open_mode();
  91.     inline streamsize   in_avail();
  92.  
  93.     inline int_type snextc();
  94.     inline int_type sbumpc();
  95.     inline int_type sgetc();
  96.     inline streamsize sgetn(char_type *s, streamsize n);
  97.  
  98.     inline int_type sputbackc(char_type c);
  99.     inline int_type sungetc();
  100.  
  101.     inline int_type sputc(char_type c);
  102.     inline streamsize sputn(const char_type *s, streamsize n);
  103.  
  104. #ifdef _RWSTD_MULTI_THREAD
  105.     _RWSTDMutex buffer_mutex_;
  106.  
  107.     void _RW_lock_buffer()
  108.     {
  109.       _RWSTDGuard* tmp = new _RWSTDGuard(buffer_mutex_);
  110.       if ( tmp )
  111.         __buffer_guard = tmp;
  112.       else
  113.         __buffer_guard = 0;
  114.     }
  115.  
  116.     void _RW_unlock_buffer()
  117.     {
  118.       if ( __buffer_guard )
  119.       {
  120. #ifdef __BORLANDC__  // RW_BUG (fix for bts-40618)
  121.         _RWSTDGuard* tmp = __buffer_guard;
  122.         __buffer_guard = 0;
  123.         delete tmp;
  124. #else
  125.         delete __buffer_guard;
  126.         __buffer_guard = 0;
  127. #endif
  128.       }
  129.     }
  130. #endif // _RWSTD_MULTI_THREAD
  131.  
  132.   protected:
  133.     basic_streambuf();
  134.  
  135.     ios_base::openmode mode_;
  136.      
  137.     inline char_type *eback() const;  
  138.     inline char_type *gptr() const;
  139.     inline char_type *egptr() const;
  140.     inline void gbump(int n);
  141.     inline void setg(char_type *gbeg_arg,char_type *gnext_arg,char_type *gend_arg);
  142.  
  143.     inline char_type *pbase() const;  
  144.     inline char_type *pptr() const;   
  145.     inline char_type *epptr() const;
  146.     inline void pbump(int n);
  147.     inline void setp(char_type *pbeg_arg,char_type *pend_arg);
  148.  
  149.     virtual void imbue( const locale& loc);
  150.  
  151.     virtual basic_streambuf<charT, traits> *
  152.     setbuf(char_type *s, streamsize n);
  153.  
  154.     virtual pos_type seekoff(off_type off,
  155.                              ios_base::seekdir way, ios_base::openmode which = 
  156.                              ios_base::in | ios_base::out);
  157.  
  158.     virtual pos_type seekpos(pos_type sp,
  159.                              ios_base::openmode which = 
  160.                              ios_base::in | ios_base::out);
  161.  
  162.     virtual int showmanyc();
  163.     virtual streamsize xsgetn(char_type *s, streamsize n);
  164.     virtual int_type underflow();
  165.     virtual int_type uflow();
  166.     virtual int_type overflow(int_type c = traits::eof());
  167.       
  168.     virtual int_type pbackfail(int_type c = traits::eof());      
  169.     virtual streamsize xsputn(const char_type *s, streamsize n);
  170.  
  171.     virtual int sync( );
  172.     void streambuf_init(bool set_mode= true);
  173.  
  174.   private:
  175.  
  176.     char_type       *__gbeg;    
  177.     char_type       *__gnext;  
  178.     char_type       *__gend;    
  179.  
  180.     char_type       *__pbeg;   
  181.     char_type       *__pnext;   
  182.     char_type       *__pend;  
  183.  
  184.     locale          __loc_buf; 
  185.  
  186. #ifdef _RWSTD_MULTI_THREAD
  187.     _RWSTDGuard *__buffer_guard; 
  188. #endif // _RWSTD_MULTI_THREAD
  189.   };
  190.   /* 
  191.    * inline functions
  192.    */
  193.  
  194.   /*
  195.    * int_type snextc()
  196.    * returns the next character
  197.    */
  198.  
  199.   template<class charT, class traits>
  200.   inline _TYPENAME basic_streambuf<charT, traits>::int_type
  201.   basic_streambuf<charT, traits>::snextc()
  202.   {
  203.     if( traits::eq_int_type(sbumpc(),traits::eof()) )
  204.       return traits::eof();
  205.  
  206.     return sgetc();
  207.   }
  208.  
  209.   /*
  210.    * int_type sbumpc()
  211.    * returns the current character and increments the pointer
  212.    */
  213.  
  214.   template<class charT, class traits>
  215.   inline _TYPENAME basic_streambuf<charT, traits>::int_type
  216.   basic_streambuf<charT, traits>::sbumpc()
  217.   { 
  218.     char_type c;
  219.  
  220.     if( gptr()>= egptr()) {
  221.       return uflow();
  222.     } 
  223.     c=*gptr();  
  224.     gbump(1); 
  225.     return traits::to_int_type(c);
  226.   }
  227.  
  228.   /*
  229.    * int_type sgetc()
  230.    * returns the current character
  231.    */
  232.  
  233.   template<class charT, class traits>
  234.   inline _TYPENAME basic_streambuf<charT, traits>::int_type
  235.   basic_streambuf<charT, traits>::sgetc()
  236.   {
  237.  
  238.     if(gptr() >= egptr()) {  
  239.       return underflow();
  240.     }
  241.  
  242.     return traits::to_int_type(*gptr());
  243.   }
  244.  
  245.   /*
  246.    * streamsize sgetn(char_type *, streamsize)
  247.    * reads in 'n' characters into 's'
  248.    */
  249.  
  250.   template<class charT, class traits>
  251.   inline streamsize basic_streambuf<charT, traits>::
  252.   sgetn(char_type *s, streamsize n)
  253.   {
  254.     return xsgetn(s, n);
  255.   }
  256.  
  257.   /*
  258.    * int_type sputbackc(char_type)
  259.    * puts the character back into the sequence if possible
  260.    */
  261.  
  262.   template<class charT, class traits>
  263.   inline _TYPENAME basic_streambuf<charT, traits>::int_type
  264.   basic_streambuf<charT, traits>::sputbackc(char_type c)
  265.   {
  266.     if( gptr() > eback())
  267.     { 
  268.       gbump(-1);
  269.       if( !traits::eq(*gptr(),c) )
  270.       { 
  271.         gbump(1); 
  272.         return pbackfail(traits::to_int_type(c));
  273.       }
  274.  
  275.       return traits::to_int_type(*gptr());
  276.     }
  277.  
  278.     return pbackfail(traits::to_int_type(c)); 
  279.   }
  280.  
  281.   /*
  282.    * int sungetc()
  283.    * puts the character back into the sequence. The putback character doesn't
  284.    * have to already be there.  Similar to sputbackc(...)
  285.    */
  286.  
  287.   template<class charT, class traits>
  288.   inline _TYPENAME basic_streambuf<charT, traits>::int_type
  289.   basic_streambuf<charT, traits>::sungetc()
  290.   {
  291.     if(gptr() > eback())
  292.     {
  293.       gbump(-1);
  294.       return traits::to_int_type(*gptr());
  295.     } 
  296.     return pbackfail();
  297.   }
  298.  
  299.   /*
  300.    * int sputc(char_type)
  301.    * puts the character into the sequence
  302.    */
  303.  
  304.   template<class charT, class traits>
  305.   inline _TYPENAME basic_streambuf<charT, traits>::int_type
  306.   basic_streambuf<charT, traits>::sputc(char_type c)
  307.   {
  308.   
  309.     if( pptr() >= epptr() )
  310.     {
  311.       return overflow(traits::to_int_type(c));
  312.     }
  313.     *__pnext++ =c; 
  314.     return traits::to_int_type(c);
  315.   }
  316.  
  317.   /*
  318.    * streamsize sputn(const char_type *, streamsize)
  319.    * writes n characters from s into the sequence
  320.    */
  321.  
  322.   template<class charT, class traits>
  323.   inline streamsize
  324.   basic_streambuf<charT, traits>::sputn(const char_type *s, streamsize n)
  325.   {
  326.     return xsputn(s, n);
  327.   }
  328.  
  329.   /*
  330.    * void gbump(int)
  331.    * increments the get pointer by n.  Does no checking to see if this
  332.    * is a valid operation
  333.    */
  334.  
  335.   template<class charT, class traits>
  336.   inline void 
  337.   basic_streambuf<charT, traits>::gbump(int n)
  338.   {
  339.     __gnext += n;
  340.   }
  341.  
  342.   /*
  343.    * void setg(char_type *, char_type *, char_type *)
  344.    * sets the get pointers
  345.    */
  346.  
  347.   template<class charT, class traits>
  348.   inline void 
  349.   basic_streambuf<charT, traits>::
  350.   setg(char_type *gbeg, char_type *gnext, char_type *gend)
  351.   {
  352.     __gbeg  = gbeg;
  353.     __gnext = gnext;
  354.     __gend  = gend;
  355.   }
  356.  
  357.   /*
  358.    * void pbump(int)
  359.    * increments the put pointer.  No checking to see if this is valid
  360.    */
  361.  
  362.   template<class charT, class traits>
  363.   inline void 
  364.   basic_streambuf<charT, traits>::pbump(int n)
  365.   {
  366.     __pnext += n;
  367.   }
  368.  
  369.   /*
  370.    * void setp(char_type *, char_type *)
  371.    * sets up the put pointers
  372.    */
  373.  
  374.   template<class charT, class traits>
  375.   inline void 
  376.   basic_streambuf<charT, traits>::
  377.   setp(char_type *pbeg, char_type *pend)
  378.   {
  379.     __pbeg = pbeg;
  380.     __pnext = pbeg;
  381.     __pend = pend;
  382.   }
  383.  
  384.   /*
  385.    * char_type *eback() const
  386.    * returns the beginning of the get sequence
  387.    */
  388.  
  389.   template<class charT, class traits>
  390.   inline _TYPENAME basic_streambuf<charT, traits>::char_type *
  391.   basic_streambuf<charT, traits>::eback() const
  392.   {
  393.     return __gbeg;
  394.   }
  395.  
  396.   /*
  397.    * char_type *gptr() const
  398.    */
  399.  
  400.   template<class charT, class traits>
  401.   inline _TYPENAME basic_streambuf<charT, traits>::char_type *
  402.   basic_streambuf<charT, traits>::gptr() const
  403.   {
  404.     return __gnext;
  405.   }
  406.  
  407.   /*
  408.    * char_type *egptr() const
  409.    */
  410.  
  411.   template<class charT, class traits>
  412.   inline _TYPENAME basic_streambuf<charT, traits>::char_type *
  413.   basic_streambuf<charT, traits>::egptr() const
  414.   {
  415.     return __gend;
  416.   }
  417.  
  418.   /*
  419.    * char_type *pbase() const
  420.    */
  421.  
  422.   template<class charT, class traits>
  423.   inline _TYPENAME basic_streambuf<charT, traits>::char_type *
  424.   basic_streambuf<charT, traits>::pbase() const
  425.   {
  426.     return __pbeg;
  427.   }
  428.  
  429.   /*
  430.    * char_type *pptr() const
  431.    */
  432.  
  433.   template<class charT, class traits>
  434.   inline _TYPENAME basic_streambuf<charT, traits>::char_type *
  435.   basic_streambuf<charT, traits>::pptr() const
  436.   {
  437.     return __pnext;
  438.   }
  439.  
  440.   /*
  441.    * char_type *epptr() const
  442.    */
  443.  
  444.   template<class charT, class traits>
  445.   inline _TYPENAME basic_streambuf<charT, traits>::char_type *
  446.   basic_streambuf<charT, traits>::epptr() const
  447.   {
  448.     return __pend;
  449.   }
  450.  
  451.   /*
  452.    * streamsize in_avail()
  453.    * returns how many characters are available
  454.    */
  455.  
  456.   template<class charT, class traits>
  457.   inline streamsize 
  458.   basic_streambuf<charT, traits>::in_avail()
  459.   {
  460.     if(gptr() >= egptr())
  461.       return showmanyc();
  462.  
  463.     return ( (streamsize)(egptr() - gptr()) );
  464.   }
  465.  
  466.   /*
  467.    * int pubsync()
  468.    */
  469.  
  470.   template<class charT, class traits>
  471.   inline int 
  472.   basic_streambuf<charT, traits>::pubsync()
  473.   {
  474.     return sync();
  475.   }
  476.  
  477.   /*
  478.    * pos_type pubseekoff(off_type, ios_base::seekdir, ios_base::openmode)
  479.    */
  480.  
  481.   template<class charT, class traits>
  482.   inline _TYPENAME basic_streambuf<charT, traits>::pos_type
  483.   basic_streambuf<charT, traits>::
  484.   pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
  485.   {
  486.     return seekoff(off, way, which);
  487.   }
  488.  
  489.   /*
  490.    * pos_type pubseekpos(pos_type, ios_base::openmode)
  491.    */
  492.  
  493.   template<class charT, class traits>
  494.   inline _TYPENAME basic_streambuf<charT, traits>::pos_type
  495.   basic_streambuf<charT, traits>::
  496.   pubseekpos(pos_type sp,
  497.              ios_base::openmode which)
  498.   {
  499.     return seekpos(sp, which);
  500.   }
  501.  
  502.   /*
  503.    * basic_streambuf *pubsetbuf(char_type *, streamsize)
  504.    */
  505.  
  506.   template<class charT, class traits>
  507.   inline  basic_streambuf<charT, traits> *
  508.   basic_streambuf<charT, traits>::
  509.   pubsetbuf(char_type *s, streamsize n)
  510.   {
  511.     return setbuf(s, n);
  512.   }
  513.  
  514.   /*
  515.    * ios_base::openmode which_open_mode()
  516.    */
  517.  
  518.   template<class charT, class traits>
  519.   inline ios_base::openmode
  520.   basic_streambuf<charT, traits>::which_open_mode()
  521.   {
  522.     return mode_; 
  523.   }
  524.  
  525.   /*
  526.    *   streambuf iterators
  527.    */
  528.  
  529.   /*
  530.    *  ostreambuf_iterator
  531.    */
  532.  
  533.   template<class charT, class traits >
  534.   class _RWSTDExportTemplate ostreambuf_iterator 
  535.     : public iterator<output_iterator_tag,charT, 
  536.   _TYPENAME traits::off_type,charT*,charT&>
  537.   {
  538.  
  539.   public:
  540.     //
  541.     // Types:
  542.     //
  543.     typedef charT                          char_type;
  544.     typedef traits                         traits_type;
  545.     typedef basic_streambuf<charT, traits> streambuf_type;
  546.     typedef basic_ostream<charT, traits>   ostream_type;
  547.  
  548.     ostreambuf_iterator(ostream_type& s) _RWSTD_INLINE_NO_THROW
  549.     : __sbuf(s.rdbuf())
  550.     {
  551.       if ( s.rdbuf() ) __failed_flag = false;
  552.       else 
  553.         __failed_flag = true; 
  554.     }
  555.  
  556.     ostreambuf_iterator(streambuf_type *s) _RWSTD_INLINE_NO_THROW
  557.     : __sbuf(s)
  558.     { 
  559.       if ( s ) __failed_flag = false;
  560.       else 
  561.         __failed_flag = true;
  562.     }
  563.  
  564.     ostreambuf_iterator<charT,traits>& operator*()
  565.     { return *this; }
  566.     ostreambuf_iterator<charT,traits>& operator++()
  567.     { return *this; }
  568.     ostreambuf_iterator<charT,traits> operator++(int)
  569.     { return *this; }
  570.  
  571.     ostreambuf_iterator<charT,traits>& operator=(charT c)
  572.     { 
  573.       if ( !__failed_flag )
  574.       {
  575.         if ( traits::eq_int_type(__sbuf->sputc(c),traits::eof()) )
  576.           __failed_flag=true;
  577.       }
  578.       return *this;
  579.     }
  580.  
  581.     bool failed( ) const _RWSTD_INLINE_NO_THROW
  582.     { return __failed_flag; }
  583.  
  584.   protected:
  585.  
  586.   private:
  587.     streambuf_type        *__sbuf;
  588.     bool                   __failed_flag;
  589.   };
  590.  
  591.   /*
  592.    * istreambuf_iterator 
  593.    */
  594.  
  595.   template<class charT, class traits >
  596.   class _RWSTDExportTemplate istreambuf_iterator
  597.     : public iterator<input_iterator_tag,charT,
  598.   _TYPENAME traits::off_type,charT*,charT&>
  599.   {
  600.  
  601.   public:
  602.     //
  603.     // Types:
  604.     //
  605.     typedef charT                          char_type;
  606.     typedef _TYPENAME traits::int_type      int_type;
  607.     typedef traits                         traits_type;
  608.  
  609.     typedef basic_streambuf<charT, traits> streambuf_type;
  610.     typedef basic_istream<charT, traits>   istream_type;
  611.  
  612.     // class to maintain a character and an associated streambuf
  613.     class proxy {
  614.       char_type                       __keep;
  615.       streambuf_type                  *__sbuf;
  616.  
  617.       proxy(char_type c, streambuf_type *sbuf)
  618.         : __keep(c), __sbuf(sbuf)
  619.       { ; }
  620.  
  621.     public:
  622.  
  623.       char_type operator*()
  624.       { return __keep; }
  625.  
  626.       friend class istreambuf_iterator<charT, traits>;
  627.     };
  628.  
  629.   public:
  630.  
  631.     istreambuf_iterator()  _RWSTD_INLINE_NO_THROW
  632.     : __sbuf(0)
  633.     { __failed_flag = true; }
  634.     istreambuf_iterator(istream_type& s)  _RWSTD_INLINE_NO_THROW
  635.     : __sbuf(s.rdbuf())
  636.     { 
  637.       if ( s.rdbuf() ) __failed_flag = false;
  638.       else 
  639.         __failed_flag = true; 
  640.     }
  641.     istreambuf_iterator(streambuf_type *s) _RWSTD_INLINE_NO_THROW
  642.     : __sbuf(s)
  643.     {
  644.       if ( s ) __failed_flag = false;
  645.       else 
  646.         __failed_flag = true;
  647.     }
  648.     istreambuf_iterator(const proxy& p) _RWSTD_INLINE_NO_THROW
  649.     : __sbuf(p.__sbuf)
  650.     { ; }
  651.     inline char_type operator*();
  652.     inline istreambuf_iterator<charT, traits>& operator++();
  653.     inline proxy operator++(int);
  654.     inline bool equal(istreambuf_iterator<charT, traits>& b);
  655.  
  656.     bool failed( ) const _RWSTD_INLINE_NO_THROW
  657.     { return __failed_flag; }
  658.  
  659.   protected:
  660.  
  661.   private:
  662.     streambuf_type     *__sbuf;
  663.     bool                __failed_flag;
  664.   };
  665.  
  666.   /*
  667.    * inline functions
  668.    */
  669.  
  670.   /*
  671.    * char_type operator*()
  672.    */
  673.  
  674.   template<class charT, class traits>
  675.   inline _TYPENAME istreambuf_iterator<charT, traits>::char_type
  676.   istreambuf_iterator<charT, traits>::operator*()
  677.   {
  678.     int_type c;
  679.  
  680.     if ( __sbuf && !__failed_flag )
  681.     {
  682.       c= __sbuf->sgetc();
  683.       if ( traits::eq_int_type(c,traits::eof()) ) 
  684.       {
  685.         __sbuf = 0;
  686.         __failed_flag = true;
  687.       }
  688.     }
  689.     else return traits::eof();
  690.  
  691.     return traits::to_char_type(c);
  692.   }
  693.  
  694.   /*
  695.    * istreambuf_iterator& operator++()
  696.    */
  697.  
  698.   template<class charT, class traits>
  699.   inline istreambuf_iterator<charT, traits>&
  700.   istreambuf_iterator<charT, traits>::operator++()
  701.   {
  702.     if (__sbuf && !__failed_flag )
  703.     { 
  704.       __sbuf->sbumpc();
  705.       if ( traits::eq_int_type(__sbuf->sgetc(),traits::eof()) ) 
  706.       {
  707.         __sbuf = 0;
  708.         __failed_flag = true;
  709.       } 
  710.     }
  711.     return *this;
  712.   }
  713.  
  714.   /*
  715.    * proxy operator++(int)
  716.    */
  717.  
  718.   template<class charT, class traits>
  719.   inline _TYPENAME istreambuf_iterator<charT, traits>::proxy 
  720.   istreambuf_iterator<charT, traits>::operator++(int)
  721.   {
  722.  
  723.     if (__sbuf && !__failed_flag )
  724.     {
  725.       proxy     prev(__sbuf->sgetc(), __sbuf);
  726.       __sbuf->sbumpc();
  727.       if ( traits::eq_int_type(__sbuf->sgetc(),traits::eof()) ) 
  728.       {
  729.         __sbuf = 0;
  730.         __failed_flag = true;
  731.       }  
  732.       return prev;
  733.     }
  734.     
  735.     charT     c=traits::to_char_type(traits::eof());
  736.     return proxy(c, __sbuf);
  737.   }
  738.  
  739.   /*
  740.    * bool equal(istreambuf_iterator&)
  741.    */
  742.  
  743.   template<class charT, class traits>
  744.   inline bool
  745.   istreambuf_iterator<charT, traits>::
  746.   equal(istreambuf_iterator<charT, traits>& b)
  747.   {
  748.     if( ((__sbuf ==0) && (b.__sbuf==0)) || ((__sbuf !=0) && (b.__sbuf !=0)) )
  749.       return true;  
  750.     else
  751.       return false;
  752.   }
  753.  
  754.   /*
  755.    * bool operator==(istreambuf_iterator& a, istreambuf_iterator& b)
  756.    */
  757.  
  758.   template<class charT, class traits>
  759.   inline bool _RWSTDExportTemplate operator==(istreambuf_iterator<charT, traits>& a,
  760.                                               istreambuf_iterator<charT, traits>& b)
  761.   {
  762.     return a.equal(b);
  763.   }
  764.  
  765.   /*
  766.    * bool operator!=(istreambuf_iterator& a, istreambuf_iterator& b)
  767.    */
  768.  
  769.   template<class charT, class traits>
  770.   inline bool _RWSTDExportTemplate operator!=(istreambuf_iterator<charT, traits>& a,
  771.                                               istreambuf_iterator<charT, traits>& b)
  772.   {
  773.     return !(a.equal(b));
  774.   }
  775.  
  776.   // end inlining
  777. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  778.   typedef basic_streambuf<char>                             streambuf;
  779. #else
  780.   typedef basic_streambuf<char, char_traits<char> >         streambuf;
  781. #endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  782.  
  783. #ifndef _RWSTD_NO_WIDE_CHAR
  784. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  785.   typedef basic_streambuf<wchar_t>                          wstreambuf;
  786. #else
  787.   typedef basic_streambuf<wchar_t, char_traits<wchar_t> >   wstreambuf;
  788. #endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  789. #endif // _RWSTD_NO_WIDE_CHAR
  790. #ifndef _RWSTD_NO_NAMESPACE
  791. }
  792. #endif
  793.  
  794. #ifdef _RWSTD_COMPILE_INSTANTIATE
  795. #include <streambu.cc> 
  796. #endif
  797.  
  798. #endif // __STD_STREAMBUF__ 
  799.  
  800. #ifndef __USING_STD_NAMES__
  801.   using namespace std;
  802. #endif
  803. #pragma option pop
  804. #endif /* __STREAMBU_H */
  805.