home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / streambu.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  6.2 KB  |  269 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.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  11.  *
  12.  * This computer software is owned by Rogue Wave Software, Inc. and is
  13.  * protected by U.S. copyright laws and other laws and by international
  14.  * treaties.  This computer software is furnished by Rogue Wave Software,
  15.  * Inc. pursuant to a written license agreement and may be used, copied,
  16.  * transmitted, and stored only in accordance with the terms of such
  17.  * license and with the inclusion of the above copyright notice.  This
  18.  * computer software or any other copies thereof may not be provided or
  19.  * otherwise made available to any other person.
  20.  *
  21.  * U.S. Government Restricted Rights.  This computer software is provided
  22.  * with Restricted Rights.  Use, duplication, or disclosure by the
  23.  * Government is subject to restrictions as set forth in subparagraph (c)
  24.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  25.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  26.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  27.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  28.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  29.  *
  30.  **************************************************************************/
  31.  
  32. #ifndef _RWSTD_NO_NAMESPACE
  33. namespace std {
  34. #endif
  35.  
  36.   /*
  37.    * class basic_streambuf<charT, traits>
  38.    */
  39.  
  40.   /*
  41.    * ~basic_streambuf()
  42.    */
  43.  
  44.   template<class charT, class traits>
  45.   basic_streambuf<charT, traits>::~basic_streambuf()
  46.   {
  47.  
  48.   }
  49.  
  50.   /*
  51.    * basic_streambuf()
  52.    */
  53.  
  54.   template<class charT, class traits>
  55.   basic_streambuf<charT, traits>::basic_streambuf()
  56.   {
  57.     streambuf_init();
  58.   }
  59.  
  60.   /*
  61.    * void streambuf_init()
  62.    */
  63.  
  64.   template<class charT, class traits>
  65.   void basic_streambuf<charT, traits>::streambuf_init(bool set_mode)
  66.   {
  67.     if ( set_mode )
  68.       mode_ = ( ios_base::in | ios_base::out );
  69.  
  70.     __gbeg  = 0;
  71.     __gnext = 0;
  72.     __gend  = 0;
  73.  
  74.     __pbeg  = 0;
  75.     __pnext = 0;
  76.     __pend  = 0;
  77.   }
  78.   /*
  79.    * int_type overflow(int_type)
  80.    */
  81.  
  82.   template<class charT, class traits>
  83.   _TYPENAME basic_streambuf<charT, traits>::int_type
  84.   basic_streambuf<charT, traits>::overflow(int_type )
  85.   {
  86.     return traits::eof();  
  87.   }
  88.  
  89.   /*
  90.    * int_type pbackfail(int_type)
  91.    */
  92.  
  93.   template<class charT, class traits>
  94.   _TYPENAME basic_streambuf<charT, traits>::int_type
  95.   basic_streambuf<charT, traits>::pbackfail(int_type )
  96.   {
  97.     return traits::eof();
  98.   }
  99.  
  100.   /*
  101.    * streamsize showmanyc()
  102.    */
  103.  
  104.   template<class charT, class traits>
  105.   streamsize basic_streambuf<charT, traits>::showmanyc()
  106.   {
  107.     if ( gptr() )
  108.     {
  109.       if ( pptr()>egptr() ) setg(eback(),gptr(),pptr());
  110.     }
  111.     else
  112.       if ( pptr() ) setg(pbase(),pbase(),pptr());
  113.  
  114.     return (streamsize)(egptr()-gptr());
  115.   }
  116.  
  117.   /*
  118.    * int_type underflow()
  119.    */
  120.  
  121.   template<class charT, class traits>
  122.   _TYPENAME basic_streambuf<charT, traits>::int_type
  123.   basic_streambuf<charT, traits>::underflow()
  124.   {
  125.     return traits::eof();
  126.   }
  127.  
  128.   /*
  129.    * int_type uflow()
  130.    */
  131.  
  132.   template<class charT, class traits>
  133.   _TYPENAME basic_streambuf<charT, traits>::int_type
  134.   basic_streambuf<charT, traits>::uflow()
  135.   {
  136.     if( traits::eq_int_type(underflow(),traits::eof()) )
  137.       return traits::eof();
  138.     return sbumpc();
  139.   }
  140.  
  141.   /*
  142.    * streamsize xsgetn(char_type *, streamsize)
  143.    */
  144.  
  145.   template<class charT, class traits>
  146.   streamsize basic_streambuf<charT, traits>::
  147.   xsgetn(char_type *s, streamsize n)
  148.   {
  149.     if ( !s || (n==0) ) return 0;
  150.  
  151.     streamsize i = ( in_avail() > n ) ? n : in_avail();
  152.     int_type   c;
  153.  
  154.     if(i > 0) {
  155.       s = traits::copy(s, gptr(), i);
  156.       s += i;
  157.       gbump(i);
  158.     }
  159.  
  160.     while((i < n) && ( !traits::eq_int_type( (c = sbumpc()),traits::eof()))) {
  161.       *s++ = traits::to_char_type(c);
  162.       ++i;
  163.     }
  164.  
  165.     return i;
  166.   }
  167.  
  168.   /*
  169.    * streamsize xsputn(const char_type *, streamsize)
  170.    */
  171.  
  172.   template<class charT, class traits>
  173.   streamsize basic_streambuf<charT, traits>::
  174.   xsputn(const char_type *s, streamsize n)
  175.   {
  176.     if ( !s || (n == 0) ) return 0;
  177.  
  178.     int         i=0;
  179.  
  180.     while((i < n) && ( !traits::eq_int_type(sputc(*s++),traits::eof()))) {
  181.       i++;
  182.     }
  183.  
  184.     return i;
  185.   }
  186.  
  187.   /*
  188.    * pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode)
  189.    */
  190.  
  191.   template<class charT, class traits>
  192.   _TYPENAME basic_streambuf<charT, traits>::pos_type
  193.   basic_streambuf<charT, traits>::
  194.   seekoff(off_type , ios_base::seekdir , ios_base::openmode )
  195.   {
  196.     return pos_type(off_type(-1));
  197.   }
  198.  
  199.   /*
  200.    * pos_type seekpos(pos_type, ios_base::openmode)
  201.    */
  202.  
  203.   template<class charT, class traits>
  204.   _TYPENAME basic_streambuf<charT, traits>::pos_type
  205.   basic_streambuf<charT, traits>::
  206.   seekpos(pos_type , ios_base::openmode )
  207.   {
  208.     return pos_type(off_type(-1));
  209.   }
  210.  
  211.   /*
  212.    * basic_streambuf *setbuf(char_type *, streamsize)
  213.    */
  214.  
  215.   template<class charT, class traits>
  216.   basic_streambuf<charT, traits> *
  217.   basic_streambuf<charT, traits>::setbuf(char_type*, streamsize )
  218.   {
  219.     return this;
  220.   }
  221.  
  222.   /*
  223.    * int sync()
  224.    */
  225.  
  226.   template<class charT, class traits>
  227.   int basic_streambuf<charT, traits>::sync()
  228.   {
  229.     return 0;
  230.   }
  231.   /*
  232.    * locale pubimbue(const locale& loc)
  233.    */
  234.  
  235.   template<class charT, class traits>
  236.   locale basic_streambuf<charT, traits>::pubimbue(const locale& loc)
  237.   {
  238.     locale tmp = getloc();
  239.     imbue(loc);
  240.     return tmp; 
  241.   }
  242.  
  243.   /*
  244.    * locale getloc() const
  245.    */
  246.  
  247.   template<class charT, class traits>
  248.   locale basic_streambuf<charT, traits>::getloc() const
  249.   {
  250.     return __loc_buf;
  251.   }
  252.  
  253.   /*
  254.    * virtual void imbue(const locale& loc)
  255.    */
  256.  
  257.   template<class charT, class traits>
  258.   void basic_streambuf<charT, traits>::imbue(const locale& loc)
  259.   {
  260.     __loc_buf = loc;
  261.  
  262.   }
  263.  
  264. #ifndef _RWSTD_NO_NAMESPACE
  265. }
  266. #endif
  267. #pragma option pop
  268. #endif /* __STREAMBU_CC */
  269.