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

  1. #ifndef __STREAMBU_CC
  2. #define __STREAMBU_CC
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. /***************************************************************************
  5.  *
  6.  * streambuf.cc - Definitions for the Standard Library stream buffers
  7.  *
  8.  ***************************************************************************
  9.  *
  10.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  11.  * ALL RIGHTS RESERVED
  12.  *
  13.  * The software and information contained herein are proprietary to, and
  14.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  15.  * intends to preserve as trade secrets such software and information.
  16.  * This software is furnished pursuant to a written license agreement and
  17.  * may be used, copied, transmitted, and stored only in accordance with
  18.  * the terms of such license and with the inclusion of the above copyright
  19.  * notice.  This software and information or any other copies thereof may
  20.  * not be provided or otherwise made available to any other person.
  21.  *
  22.  * Notwithstanding any other lease or license that may pertain to, or
  23.  * accompany the delivery of, this computer software and information, the
  24.  * rights of the Government regarding its use, reproduction and disclosure
  25.  * are as set forth in Section 52.227-19 of the FARS Computer
  26.  * Software-Restricted Rights clause.
  27.  * 
  28.  * Use, duplication, or disclosure by the Government is subject to
  29.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  30.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  31.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  32.  * P.O. Box 2328, Corvallis, Oregon 97339.
  33.  *
  34.  * This computer software and information is distributed with "restricted
  35.  * rights."  Use, duplication or disclosure is subject to restrictions as
  36.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  37.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  38.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  39.  * then the "Alternate III" clause applies.
  40.  *
  41.  **************************************************************************/
  42.  
  43. #ifndef _RWSTD_NO_NAMESPACE
  44. namespace std {
  45. #endif
  46.  
  47.   /*
  48.    * class basic_streambuf<charT, traits>
  49.    */
  50.  
  51.   /*
  52.    * ~basic_streambuf()
  53.    */
  54.  
  55.   template<class charT, class traits>
  56.   basic_streambuf<charT, traits>::~basic_streambuf()
  57.   {
  58.  
  59.   }
  60.  
  61.   /*
  62.    * basic_streambuf()
  63.    */
  64.  
  65.   template<class charT, class traits>
  66.   basic_streambuf<charT, traits>::basic_streambuf()
  67.   {
  68.     streambuf_init();
  69.   }
  70.  
  71.   /*
  72.    * void streambuf_init()
  73.    */
  74.  
  75.   template<class charT, class traits>
  76.   void basic_streambuf<charT, traits>::streambuf_init(bool set_mode)
  77.   {
  78.     if ( set_mode )
  79.       mode_ = ( ios_base::in | ios_base::out );
  80.  
  81.     __gbeg  = 0;
  82.     __gnext = 0;
  83.     __gend  = 0;
  84.  
  85.     __pbeg  = 0;
  86.     __pnext = 0;
  87.     __pend  = 0;
  88.   }
  89.   /*
  90.    * int_type overflow(int_type)
  91.    */
  92.  
  93.   template<class charT, class traits>
  94.   _TYPENAME basic_streambuf<charT, traits>::int_type
  95.   basic_streambuf<charT, traits>::overflow(int_type )
  96.   {
  97.     return traits::eof();  
  98.   }
  99.  
  100.   /*
  101.    * int_type pbackfail(int_type)
  102.    */
  103.  
  104.   template<class charT, class traits>
  105.   _TYPENAME basic_streambuf<charT, traits>::int_type
  106.   basic_streambuf<charT, traits>::pbackfail(int_type )
  107.   {
  108.     return traits::eof();
  109.   }
  110.  
  111.   /*
  112.    * int showmanyc()
  113.    */
  114.  
  115.   template<class charT, class traits>
  116.   int basic_streambuf<charT, traits>::showmanyc()
  117.   {
  118.     if ( gptr() )
  119.     {
  120.       if ( pptr()>egptr() ) setg(eback(),gptr(),pptr());
  121.     }
  122.     else
  123.       if ( pptr() ) setg(pbase(),pbase(),pptr());
  124.  
  125.     return (int)(egptr()-gptr());
  126.   }
  127.  
  128.   /*
  129.    * int_type underflow()
  130.    */
  131.  
  132.   template<class charT, class traits>
  133.   _TYPENAME basic_streambuf<charT, traits>::int_type
  134.   basic_streambuf<charT, traits>::underflow()
  135.   {
  136.     return traits::eof();
  137.   }
  138.  
  139.   /*
  140.    * int_type uflow()
  141.    */
  142.  
  143.   template<class charT, class traits>
  144.   _TYPENAME basic_streambuf<charT, traits>::int_type
  145.   basic_streambuf<charT, traits>::uflow()
  146.   {
  147.     if( traits::eq_int_type(underflow(),traits::eof()) )
  148.       return traits::eof();
  149.     return sbumpc();
  150.   }
  151.  
  152.   /*
  153.    * streamsize xsgetn(char_type *, streamsize)
  154.    */
  155.  
  156.   template<class charT, class traits>
  157.   streamsize basic_streambuf<charT, traits>::
  158.   xsgetn(char_type *s, streamsize n)
  159.   {
  160.     if ( !s || (n==0) ) return 0;
  161.  
  162.     streamsize i = ( in_avail() > n ) ? n : in_avail();
  163.     int_type   c;
  164.  
  165.     if(i > 0) {
  166.       s = traits::copy(s, gptr(), i);
  167.       s += i;
  168.       gbump(i);
  169.     }
  170.  
  171.     while((i < n) && ( !traits::eq_int_type( (c = sbumpc()),traits::eof()))) {
  172.       *s++ = traits::to_char_type(c);
  173.       ++i;
  174.     }
  175.  
  176.     return i;
  177.   }
  178.  
  179.   /*
  180.    * streamsize xsputn(const char_type *, streamsize)
  181.    */
  182.  
  183.   template<class charT, class traits>
  184.   streamsize basic_streambuf<charT, traits>::
  185.   xsputn(const char_type *s, streamsize n)
  186.   {
  187.     if ( !s || (n == 0) ) return 0;
  188.  
  189.     int         i=0;
  190.  
  191.     while((i < n) && ( !traits::eq_int_type(sputc(*s++),traits::eof()))) {
  192.       i++;
  193.     }
  194.  
  195.     return i;
  196.   }
  197.  
  198.   /*
  199.    * pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode)
  200.    */
  201.  
  202.   template<class charT, class traits>
  203.   _TYPENAME basic_streambuf<charT, traits>::pos_type
  204.   basic_streambuf<charT, traits>::
  205.   seekoff(off_type , ios_base::seekdir , ios_base::openmode )
  206.   {
  207.     return pos_type(off_type(-1));
  208.   }
  209.  
  210.   /*
  211.    * pos_type seekpos(pos_type, ios_base::openmode)
  212.    */
  213.  
  214.   template<class charT, class traits>
  215.   _TYPENAME basic_streambuf<charT, traits>::pos_type
  216.   basic_streambuf<charT, traits>::
  217.   seekpos(pos_type , ios_base::openmode )
  218.   {
  219.     return pos_type(off_type(-1));
  220.   }
  221.  
  222.   /*
  223.    * basic_streambuf *setbuf(char_type *, streamsize)
  224.    */
  225.  
  226.   template<class charT, class traits>
  227.   basic_streambuf<charT, traits> *
  228.   basic_streambuf<charT, traits>::setbuf(char_type*, streamsize )
  229.   {
  230.     return this;
  231.   }
  232.  
  233.   /*
  234.    * int sync()
  235.    */
  236.  
  237.   template<class charT, class traits>
  238.   int basic_streambuf<charT, traits>::sync()
  239.   {
  240.     return 0;
  241.   }
  242.   /*
  243.    * locale pubimbue(const locale& loc)
  244.    */
  245.  
  246.   template<class charT, class traits>
  247.   locale basic_streambuf<charT, traits>::pubimbue(const locale& loc)
  248.   {
  249.     locale tmp = getloc();
  250.     imbue(loc);
  251.     return tmp; 
  252.   }
  253.  
  254.   /*
  255.    * locale getloc() const
  256.    */
  257.  
  258.   template<class charT, class traits>
  259.   locale basic_streambuf<charT, traits>::getloc() const
  260.   {
  261.     return __loc_buf;
  262.   }
  263.  
  264.   /*
  265.    * virtual void imbue(const locale& loc)
  266.    */
  267.  
  268.   template<class charT, class traits>
  269.   void basic_streambuf<charT, traits>::imbue(const locale& loc)
  270.   {
  271.     __loc_buf = loc;
  272.  
  273.   }
  274.  
  275. #ifndef _RWSTD_NO_NAMESPACE
  276. }
  277. #endif
  278.  
  279. #pragma option pop
  280. #endif /* __STREAMBU_CC */
  281.