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

  1. #ifndef __ISTREAM_CC
  2. #define __ISTREAM_CC
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. /***************************************************************************
  5.  *
  6.  * istream.cc - istream definitions
  7.  *
  8.  ***************************************************************************
  9.  *
  10.  * Copyright (c) 1994
  11.  * Hewlett-Packard Company
  12.  *
  13.  * Permission to use, copy, modify, distribute and sell this software
  14.  * and its documentation for any purpose is hereby granted without fee,
  15.  * provided that the above copyright notice appear in all copies and
  16.  * that both that copyright notice and this permission notice appear
  17.  * in supporting documentation.  Hewlett-Packard Company makes no
  18.  * representations about the suitability of this software for any
  19.  * purpose.  It is provided "as is" without express or implied warranty.
  20.  *
  21.  *
  22.  ***************************************************************************
  23.  *
  24.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  25.  * ALL RIGHTS RESERVED
  26.  *
  27.  * The software and information contained herein are proprietary to, and
  28.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  29.  * intends to preserve as trade secrets such software and information.
  30.  * This software is furnished pursuant to a written license agreement and
  31.  * may be used, copied, transmitted, and stored only in accordance with
  32.  * the terms of such license and with the inclusion of the above copyright
  33.  * notice.  This software and information or any other copies thereof may
  34.  * not be provided or otherwise made available to any other person.
  35.  *
  36.  * Notwithstanding any other lease or license that may pertain to, or
  37.  * accompany the delivery of, this computer software and information, the
  38.  * rights of the Government regarding its use, reproduction and disclosure
  39.  * are as set forth in Section 52.227-19 of the FARS Computer
  40.  * Software-Restricted Rights clause.
  41.  * 
  42.  * Use, duplication, or disclosure by the Government is subject to
  43.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  44.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  45.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  46.  * P.O. Box 2328, Corvallis, Oregon 97339.
  47.  *
  48.  * This computer software and information is distributed with "restricted
  49.  * rights."  Use, duplication or disclosure is subject to restrictions as
  50.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  51.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  52.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  53.  * then the "Alternate III" clause applies.
  54.  *
  55.  **************************************************************************/
  56.  
  57. #ifndef _RWSTD_NO_NEW_HEADER
  58. #include <cctype>
  59. #else
  60. #include <ctype.h>
  61. #endif
  62.  
  63. #include <ios>
  64.  
  65. #ifndef _RWSTD_NO_NAMESPACE
  66. namespace std {
  67. #endif
  68.  
  69.   /*
  70.    * basic_istream manipulators
  71.    * skips the next available white spaces
  72.    */
  73.  
  74.   template<class charT, class traits>
  75.   basic_istream<charT, traits>&
  76.   _RWSTDExportTemplate ws(basic_istream<charT, traits>& is)
  77.   {
  78.     _TYPENAME traits::int_type        c;
  79.  
  80. #ifdef _RWSTD_MULTI_THREAD
  81.     if ( is.rdbuf() )
  82.       is.istream_sentry_guard = new _RWSTDGuard(is.rdbuf()->buffer_mutex_);
  83. #ifndef _RWSTD_NO_EXCEPTIONS
  84.     try {
  85. #endif
  86. #endif // _RWSTD_MULTI_THREAD
  87.  
  88. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  89.       const ctype<charT>& ct = use_facet< ctype<charT> >(is.getloc());
  90. #else
  91.       const ctype<charT>& ct = use_facet(is.getloc(),(ctype<charT>*)0);
  92. #endif         
  93.       while((c = is.rdbuf()->sgetc()),
  94.             ( !traits::eq_int_type(c,traits::eof()) && ct.is(ct.space,c) )) 
  95.         is.rdbuf()->snextc();
  96.  
  97.       if( traits::eq_int_type(c,traits::eof()) )
  98.         is.setstate(ios_base::eofbit);
  99.  
  100. #if defined (_RWSTD_MULTI_THREAD) && !defined (_RWSTD_NO_EXCEPTIONS)
  101.     } catch(...) 
  102.     {
  103.       if ( is.rdbuf() )
  104.         delete is.istream_sentry_guard;
  105.       throw;
  106.     }          
  107. #endif // _RWSTD_MULTI_THREAD etc.
  108.        
  109. #ifdef _RWSTD_MULTI_THREAD
  110.     if ( is.rdbuf() )
  111.       delete is.istream_sentry_guard;
  112. #endif
  113.  
  114.     return is;
  115.   }
  116.  
  117.   /*
  118.    * basic_istream(basic_streambuf *)
  119.    */
  120.  
  121.   template<class charT, class traits>
  122.   basic_istream<charT, traits>::
  123.   basic_istream(basic_streambuf<charT, traits> *sb)
  124.   : __chcount(0)
  125.   {
  126.     if ( sb )
  127.     {
  128.       if ( sb->which_open_mode() & ios_base::in )
  129.         this->init(sb);
  130.       else
  131.         this->init(0);
  132.     } 
  133.     else
  134.       this->init(0); 
  135.   }
  136.  
  137.   /*
  138.    * basic_istream( )
  139.    */
  140.  
  141.   template<class charT, class traits>
  142.   basic_istream<charT, traits>::
  143.   basic_istream( )
  144.   : __chcount(0)
  145.   { 
  146.   }
  147.  
  148.   /*
  149.    * ~basic_istream();
  150.    */
  151.  
  152.   template<class charT, class traits>
  153.   basic_istream<charT, traits>::~basic_istream()
  154.   {
  155.   }
  156.  
  157.   /*
  158.    * istream_type& operator>>(istream_type& (*pf)(istream_type&))
  159.    * for functions relating to istreams
  160.    */
  161.   template<class charT, class traits>
  162.   basic_istream<charT, traits>&
  163.   basic_istream<charT, traits>::
  164.   operator>>(basic_istream<charT,traits>& (*pf)(basic_istream<charT,traits>&))
  165.   {
  166.     (*pf)(*this);
  167.     return *this;
  168.   }
  169.  
  170.   /*
  171.    * istream_type& operator>>(ios_base& (*pf)(ios_base&))
  172.    * for manipulators relating to the ios_base class
  173.    */
  174.  
  175.   template<class charT, class traits>
  176.   basic_istream<charT, traits>&
  177.   basic_istream<charT, traits>::
  178.   operator>>(ios_base& (*pf)(ios_base&))
  179.   {
  180.     (*pf)(*this);
  181.     return *this;
  182.   }
  183.  
  184.   /*
  185.    * istream_type& operator>>(ios_type& (*pf)(ios_type&))
  186.    * used to set one of the ios states (ios manipulator)
  187.    */
  188.   template<class charT, class traits>
  189.   basic_istream<charT, traits>&
  190.   basic_istream<charT, traits>::
  191.   operator>>(basic_ios<charT, traits>& (*pf)(basic_ios<charT, traits>&))
  192.   {
  193.     (*pf)(*this);
  194.     return *this;
  195.   }
  196.  
  197.   /*
  198.    * basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>, charT *)
  199.    * read in a charT *. 
  200.    */
  201.  
  202.   template<class charT, class traits>
  203.   basic_istream<charT, traits>&
  204.   _RWSTDExportTemplate operator>>(basic_istream<charT, traits>& is, charT *p)
  205.   {
  206.     ios_base::iostate err = 0;
  207.  
  208. #ifndef _RWSTD_NO_EXCEPTIONS
  209.     try {
  210. #endif  
  211.       if ( p!=0 )
  212.       {
  213.         _TYPENAME basic_istream<charT, traits>::sentry ipfx(is);
  214.  
  215.         if(ipfx)
  216.         { 
  217.           charT                      *op = p;
  218.           _TYPENAME traits::int_type  c = 0;
  219.           int                        len; 
  220.           if ( is.width() == 0 ) len=0; 
  221.           else len=is.width(); 
  222.  
  223. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  224.           const ctype<charT>& ct = use_facet< ctype<charT> >(is.getloc());
  225. #else
  226.           const ctype<charT>& ct = use_facet(is.getloc(), (ctype<charT>*)0);
  227. #endif
  228.           while(--len &&
  229.                 (c = is.rdbuf()->sgetc(),!( traits::eq_int_type(c,traits::eof()) ||
  230.                                             ct.is(ct.space,c))))
  231.           {
  232.             *p++ = c;
  233.             is.rdbuf()->sbumpc();
  234.           }
  235.         
  236.           if( traits::eq_int_type(c,traits::eof()) )
  237.             err = ((p == op) ? 
  238.                    (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit);
  239.           *p = charT ('\0');  
  240.           is.width(0); 
  241.         }
  242.       }
  243.       else
  244.         err = ios_base::failbit;
  245.  
  246. #ifndef _RWSTD_NO_EXCEPTIONS
  247.     } // end try block
  248. #endif
  249.  
  250. #ifndef _RWSTD_NO_EXCEPTIONS
  251.     catch(...)
  252.     {
  253.       bool flag = false;
  254.       try {
  255.         is.setstate(ios_base::badbit);
  256.       }
  257.       catch( ios_base::failure ) { flag= true; }
  258.       if ( flag ) throw;
  259.     }
  260. #endif // _RWSTD_NO_EXCEPTIONS
  261.     if ( err ) is.setstate(err);
  262.     return is;
  263.   }
  264.  
  265.   /*
  266.    * basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT& )
  267.    * read in a character
  268.    */
  269.  
  270.   template<class charT, class traits>
  271.   basic_istream<charT, traits>&
  272.   _RWSTDExportTemplate operator>>(basic_istream<charT,traits>& is, charT& c)
  273.   {
  274.     ios_base::iostate err = 0;
  275.  
  276. #ifndef _RWSTD_NO_EXCEPTIONS
  277.     try {
  278. #endif  
  279.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(is);
  280.  
  281.       if(ipfx)
  282.       { 
  283.         _TYPENAME traits::int_type tmp = is.rdbuf()->sbumpc();
  284.         if ( traits::eq_int_type(traits::eof(),tmp) ) 
  285.           err = ios_base::failbit | ios_base::eofbit;
  286.         else
  287.           c = traits::to_char_type(tmp);
  288.       }
  289. #ifndef _RWSTD_NO_EXCEPTIONS
  290.     } // end try block
  291. #endif
  292.  
  293. #ifndef _RWSTD_NO_EXCEPTIONS
  294.     catch(...)
  295.     {
  296.       bool flag = false;
  297.       try {
  298.         is.setstate(ios_base::badbit);
  299.       }
  300.       catch( ios_base::failure ) { flag= true; }
  301.       if ( flag ) throw;
  302.     }
  303. #endif // _RWSTD_NO_EXCEPTIONS
  304.     if ( err ) is.setstate(err);
  305.     return is;
  306.   }
  307.  
  308. #ifndef _RWSTD_NO_SIGNED_CHAR_IN_STREAMS
  309.   /*
  310.    * istream& operator>>(basic_istream<char,traits>&,unsigned char& )
  311.    */
  312.  
  313.   template <class traits>
  314.   basic_istream<char, traits>&
  315.   _RWSTDExportTemplate operator>>(basic_istream<char, traits>& is, unsigned char& uc)
  316.   {
  317.     is >> (char &)uc;
  318.     return is;
  319.   }
  320.  
  321.   /*
  322.    * istream& operator>>(basic_istream<char, traits>&, signed char& )
  323.    */
  324.  
  325.   template <class traits>
  326.   basic_istream<char, traits>&
  327.   _RWSTDExportTemplate operator>>(basic_istream<char, traits>& is, signed char& sc)
  328.   {
  329.     is >> (char &)sc;
  330.     return is;
  331.   }
  332.  
  333.   /*
  334.    * istream& operator>>(basic_istream<char, traits>&, unsigned char* )
  335.    */
  336.  
  337.   template <class traits>
  338.   basic_istream<char, traits>&
  339.   _RWSTDExportTemplate operator>>(basic_istream<char, traits>& is,unsigned char* uc)
  340.   {
  341.     is >> (char *)uc;
  342.     return is;
  343.   }
  344.  
  345.   /*
  346.    * istream& operator>>(basic_istream<char, traits>&,signed char* )
  347.    */
  348.  
  349.   template <class traits>
  350.   basic_istream<char, traits>&
  351.   _RWSTDExportTemplate operator>>(basic_istream<char, traits>& is, signed char* sc)
  352.   {
  353.     is >> (char *)sc;
  354.     return is;
  355.   }
  356. #endif // _RWSTD_NO_SIGNED_CHAR_IN_STREAMS
  357.  
  358. #ifndef _RWSTD_NO_BOOL
  359.   /*
  360.    * istream_type& operator>>(bool&)
  361.    */
  362.  
  363.   template<class charT, class traits>
  364.   basic_istream<charT, traits>&
  365.   basic_istream<charT, traits>::operator>>(bool& n)
  366.   {
  367.     ios_base::iostate err = 0;
  368.  
  369. #ifndef _RWSTD_NO_EXCEPTIONS
  370.     try {
  371. #endif
  372.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  373.       if(ipfx) 
  374.       {
  375. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  376.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  377. #else
  378.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  379. #endif
  380.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  381.       }
  382. #ifndef _RWSTD_NO_EXCEPTIONS
  383.     } // end of try block
  384. #endif
  385.  
  386. #ifndef _RWSTD_NO_EXCEPTIONS
  387.     catch(...)
  388.     {
  389.       bool flag = false;
  390.       try {
  391.         this->setstate(ios_base::badbit);
  392.       }
  393.       catch( ios_base::failure ) { flag= true; }
  394.       if ( flag ) throw;
  395.     }
  396. #endif // _RWSTD_NO_EXCEPTIONS
  397.     if ( err ) this->setstate(err);
  398.     return *this;
  399.   }
  400.  
  401. #endif // _RWSTD_NO_BOOL 
  402.  
  403.   /*
  404.    * istream_type& operator>>(short&)
  405.    */
  406.  
  407.   template<class charT, class traits>
  408.   basic_istream<charT, traits>&
  409.   basic_istream<charT, traits>::operator>>(short& n)
  410.   {
  411.     ios_base::iostate err = 0;
  412.  
  413. #ifndef _RWSTD_NO_EXCEPTIONS
  414.     try {
  415. #endif 
  416.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  417.  
  418.       if(ipfx) 
  419.       {
  420.         long l;
  421. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  422.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  423. #else
  424.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  425. #endif
  426.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,l);
  427.         n=(short)l;
  428.         if ( (n!=l) && ((unsigned short)n != l) )
  429.           err |= ios_base::failbit;
  430.       }
  431. #ifndef _RWSTD_NO_EXCEPTIONS
  432.     } // end of try block
  433. #endif
  434.  
  435. #ifndef _RWSTD_NO_EXCEPTIONS
  436.     catch(...)
  437.     {
  438.       bool flag = false;
  439.       try {
  440.         this->setstate(ios_base::badbit);
  441.       }
  442.       catch( ios_base::failure ) { flag= true; }
  443.       if ( flag ) throw;
  444.     }
  445. #endif // _RWSTD_NO_EXCEPTIONS
  446.     if ( err ) this->setstate(err);
  447.     return *this;
  448.   }
  449.   /*
  450.    * istream_type& operator>>(unsigned short&)
  451.    */
  452.   
  453.   template<class charT, class traits>
  454.   basic_istream<charT, traits>&
  455.   basic_istream<charT, traits>::operator>>(unsigned short& n)
  456.   {
  457.     ios_base::iostate err = 0;
  458.  
  459. #ifndef _RWSTD_NO_EXCEPTIONS
  460.     try {
  461. #endif
  462.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  463.       if(ipfx)
  464.       {
  465. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  466.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  467. #else
  468.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  469. #endif
  470.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  471.       }
  472.  
  473. #ifndef _RWSTD_NO_EXCEPTIONS
  474.     } // end of try block
  475. #endif
  476.  
  477. #ifndef _RWSTD_NO_EXCEPTIONS
  478.     catch(...)
  479.     {
  480.       bool flag = false;
  481.       try {
  482.         this->setstate(ios_base::badbit);
  483.       }
  484.       catch( ios_base::failure ) { flag= true; }
  485.       if ( flag ) throw;
  486.     }
  487. #endif // _RWSTD_NO_EXCEPTIONS
  488.     if ( err ) this->setstate(err);
  489.     return *this;
  490.   }
  491.   /*
  492.    * istream_type& operator>>(int&)
  493.    */
  494.  
  495.   template<class charT, class traits>
  496.   basic_istream<charT, traits>&
  497.   basic_istream<charT, traits>::operator>>(int& n)
  498.   {
  499.     ios_base::iostate err = 0;
  500.  
  501. #ifndef _RWSTD_NO_EXCEPTIONS
  502.     try {
  503. #endif
  504.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  505.  
  506.       if(ipfx)
  507.       {
  508.         long l;
  509. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  510.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  511. #else
  512.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  513. #endif
  514.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,l);
  515.         n=(int)l;
  516.         if ( (n!=l) && ((unsigned int)n!=(unsigned long)l) )
  517.           err |= ios_base::failbit;
  518.       }
  519.  
  520. #ifndef _RWSTD_NO_EXCEPTIONS
  521.     } // end of try block
  522. #endif
  523.  
  524. #ifndef _RWSTD_NO_EXCEPTIONS
  525.     catch(...)
  526.     {
  527.       bool flag = false;
  528.       try {
  529.         this->setstate(ios_base::badbit);
  530.       }
  531.       catch( ios_base::failure ) { flag= true; }
  532.       if ( flag ) throw;
  533.     }
  534. #endif
  535.     if ( err ) this->setstate(err);
  536.     return *this;
  537.   }
  538.  
  539.   /*
  540.    * istream_type& operator>>(unsigned int&)
  541.    */
  542.  
  543.   template<class charT, class traits>
  544.   basic_istream<charT, traits>&
  545.   basic_istream<charT, traits>::operator>>(unsigned int& n)
  546.   {
  547.     ios_base::iostate err = 0;
  548.  
  549. #ifndef _RWSTD_NO_EXCEPTIONS
  550.     try {
  551. #endif
  552.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  553.  
  554.       if(ipfx)
  555.       {
  556. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  557.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  558. #else
  559.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  560. #endif
  561.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  562.       }
  563. #ifndef _RWSTD_NO_EXCEPTIONS
  564.     } // end of try block
  565. #endif
  566.  
  567. #ifndef _RWSTD_NO_EXCEPTIONS
  568.     catch(...)
  569.     {
  570.       bool flag = false;
  571.       try {
  572.         this->setstate(ios_base::badbit);
  573.       }
  574.       catch( ios_base::failure ) { flag= true; }
  575.       if ( flag ) throw;
  576.     }
  577. #endif
  578.     if ( err ) this->setstate(err); 
  579.     return *this;
  580.   }
  581.  
  582.   /*
  583.    * istream_type& operator>>(long&)
  584.    */
  585.  
  586.   template<class charT, class traits>
  587.   basic_istream<charT, traits>&
  588.   basic_istream<charT, traits>::operator>>(long& n)
  589.   {
  590.     ios_base::iostate err = 0;
  591.  
  592. #ifndef _RWSTD_NO_EXCEPTIONS
  593.     try {
  594. #endif
  595.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  596.  
  597.       if(ipfx)
  598.       {
  599. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  600.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  601. #else
  602.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  603. #endif
  604.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  605.       }
  606.  
  607. #ifndef _RWSTD_NO_EXCEPTIONS
  608.     } // end of try block
  609. #endif
  610.  
  611. #ifndef _RWSTD_NO_EXCEPTIONS
  612.     catch(...)
  613.     {
  614.       bool flag = false;
  615.       try {
  616.         this->setstate(ios_base::badbit);
  617.       }
  618.       catch( ios_base::failure ) { flag= true; }
  619.       if ( flag ) throw;
  620.     }
  621. #endif
  622.     if ( err ) this->setstate(err);
  623.     return *this;
  624.   }
  625.  
  626.   /*
  627.    * istream_type& operator>>(unsigned long&)
  628.    */
  629.  
  630.   template<class charT, class traits>
  631.   basic_istream<charT, traits>&
  632.   basic_istream<charT, traits>::operator>>(unsigned long& n)
  633.   {
  634.     ios_base::iostate err = 0;
  635.  
  636. #ifndef _RWSTD_NO_EXCEPTIONS
  637.     try {
  638. #endif
  639.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  640.  
  641.       if(ipfx)
  642.       {
  643. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  644.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  645. #else
  646.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  647. #endif
  648.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,n);
  649.       }
  650. #ifndef _RWSTD_NO_EXCEPTIONS
  651.     } //  end of try block
  652. #endif
  653.  
  654. #ifndef _RWSTD_NO_EXCEPTIONS
  655.     catch(...)
  656.     {
  657.       bool flag = false;
  658.       try {
  659.         this->setstate(ios_base::badbit);
  660.       }
  661.       catch( ios_base::failure ) { flag= true; }
  662.       if ( flag ) throw;
  663.     }
  664. #endif
  665.     if ( err ) this->setstate(err);
  666.     return *this;
  667.   }
  668.  
  669.   /*
  670.    * istream_type& operator>>(float&)
  671.    */
  672.  
  673.   template<class charT, class traits>
  674.   basic_istream<charT, traits>&
  675.   basic_istream<charT, traits>::operator>>(float& f)
  676.   {
  677.     ios_base::iostate err = 0;
  678.  
  679. #ifndef _RWSTD_NO_EXCEPTIONS
  680.     try {
  681. #endif
  682.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  683.  
  684.       if(ipfx)
  685.       { 
  686. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  687.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  688. #else
  689.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  690. #endif
  691.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,f);
  692.       }
  693.  
  694. #ifndef _RWSTD_NO_EXCEPTIONS
  695.     }
  696. #endif
  697.  
  698. #ifndef _RWSTD_NO_EXCEPTIONS
  699.     catch(...)
  700.     {
  701.       bool flag = false;
  702.       try {
  703.         this->setstate(ios_base::badbit);
  704.       }
  705.       catch( ios_base::failure ) { flag= true; }
  706.       if ( flag ) throw;
  707.     }
  708. #endif
  709.     if ( err ) this->setstate(err);
  710.     return *this;
  711.   }
  712.  
  713.   /*
  714.    * istream_type& operator>>(double&)
  715.    */
  716.  
  717.   template<class charT, class traits>
  718.   basic_istream<charT, traits>&
  719.   basic_istream<charT, traits>::operator>>(double& f)
  720.   {
  721.     ios_base::iostate err = 0;
  722.  
  723. #ifndef _RWSTD_NO_EXCEPTIONS
  724.     try {
  725. #endif  
  726.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  727.  
  728.       if(ipfx)
  729.       {
  730. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  731.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  732. #else
  733.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  734. #endif
  735.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,f);
  736.       }
  737. #ifndef _RWSTD_NO_EXCEPTIONS
  738.     } // end of try block
  739. #endif
  740.  
  741. #ifndef _RWSTD_NO_EXCEPTIONS
  742.     catch(...)
  743.     {
  744.       bool flag = false;
  745.       try {
  746.         this->setstate(ios_base::badbit);
  747.       }
  748.       catch( ios_base::failure ) { flag= true; }
  749.       if ( flag ) throw;
  750.     }
  751. #endif
  752.     if ( err ) this->setstate(err);
  753.     return *this;
  754.   }
  755.  
  756.   /*
  757.    * istream_type& operator>>(long double&)
  758.    */
  759.  
  760.   template<class charT, class traits>
  761.   basic_istream<charT, traits>&
  762.   basic_istream<charT, traits>::operator>>(long double& f)
  763.   {
  764.     ios_base::iostate err = 0;
  765.  
  766. #ifndef _RWSTD_NO_EXCEPTIONS
  767.     try {
  768. #endif  
  769.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  770.  
  771.       if(ipfx)
  772.       {  
  773. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  774.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  775. #else   
  776.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  777. #endif
  778.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,f);
  779.       }
  780.  
  781. #ifndef _RWSTD_NO_EXCEPTIONS
  782.     } // end of try block
  783. #endif
  784.  
  785. #ifndef _RWSTD_NO_EXCEPTIONS
  786.     catch(...)
  787.     {
  788.       bool flag = false;
  789.       try {
  790.         this->setstate(ios_base::badbit);
  791.       }
  792.       catch( ios_base::failure ) { flag= true; }
  793.       if ( flag ) throw;
  794.     }
  795. #endif
  796.     if ( err ) this->setstate(err);
  797.     return *this;
  798.   }
  799. /*
  800.  * istream_type& operator>>(_RWSTD_LONG_LONG&)
  801.  */
  802.  
  803. #ifdef _RWSTD_LONG_LONG
  804.  
  805.   template<class charT, class traits>
  806.   basic_istream<charT, traits>&
  807.   basic_istream<charT, traits>::operator>>(_RWSTD_LONG_LONG& ll)
  808.   {
  809.     ios_base::iostate err = 0;
  810.  
  811. #ifndef _RWSTD_NO_EXCEPTIONS
  812.     try {
  813. #endif 
  814.  
  815.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  816.  
  817.       if(ipfx) { 
  818. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  819.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  820. #else  
  821.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  822. #endif
  823.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,ll);
  824.       }
  825.  
  826. #ifndef _RWSTD_NO_EXCEPTIONS
  827.     }
  828. #endif
  829.  
  830. #ifndef _RWSTD_NO_EXCEPTIONS
  831.     catch(...)
  832.     {
  833.       bool flag = false;
  834.       try {
  835.         this->setstate(ios_base::badbit);
  836.       }
  837.       catch( ios_base::failure ) { flag= true; }
  838.       if ( flag ) throw;
  839.     }
  840. #endif
  841.  
  842.     if ( err ) this->setstate(err);
  843.  
  844.     return *this;
  845.   }
  846.  
  847. /*
  848.  * istream_type& operator>>(unsigned _RWSTD_LONG_LONG&)
  849.  */
  850.  
  851.   template<class charT, class traits>
  852.   basic_istream<charT, traits>&
  853.   basic_istream<charT, traits>::operator>>(unsigned _RWSTD_LONG_LONG& ull)
  854.   {
  855.     ios_base::iostate err = 0;
  856.  
  857. #ifndef _RWSTD_NO_EXCEPTIONS
  858.     try {
  859. #endif 
  860.  
  861.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  862.  
  863.       if(ipfx) { 
  864. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  865.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  866. #else  
  867.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  868. #endif
  869.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,ull);
  870.       }
  871.  
  872. #ifndef _RWSTD_NO_EXCEPTIONS
  873.     }
  874. #endif
  875.  
  876. #ifndef _RWSTD_NO_EXCEPTIONS
  877.     catch(...)
  878.     {
  879.       bool flag = false;
  880.       try {
  881.         this->setstate(ios_base::badbit);
  882.       }
  883.       catch( ios_base::failure ) { flag= true; }
  884.       if ( flag ) throw;
  885.     }
  886. #endif
  887.  
  888.     if ( err ) this->setstate(err);
  889.  
  890.     return *this;
  891.   }
  892. #endif // _RWSTD_LONG_LONG
  893.   /*
  894.    * istream_type& operator>>(void*&)
  895.    */
  896.  
  897.   template<class charT, class traits>
  898.   basic_istream<charT, traits>&
  899.   basic_istream<charT, traits>::operator>>(void*& p)
  900.   {
  901.     ios_base::iostate err = 0;
  902.  
  903. #ifndef _RWSTD_NO_EXCEPTIONS
  904.     try {
  905. #endif
  906.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  907.  
  908.       if(ipfx) 
  909.       {
  910. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  911.         use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
  912. #else
  913.         use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
  914. #endif
  915.         .get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,p);
  916.       }
  917. #ifndef _RWSTD_NO_EXCEPTIONS
  918.     } // end of try block
  919. #endif
  920.  
  921. #ifndef _RWSTD_NO_EXCEPTIONS
  922.     catch(...)
  923.     {
  924.       bool flag = false;
  925.       try {
  926.         this->setstate(ios_base::badbit);
  927.       }
  928.       catch( ios_base::failure ) { flag= true; }
  929.       if ( flag ) throw;
  930.     }
  931. #endif
  932.     if ( err ) this->setstate(err);
  933.     return *this;
  934.   }
  935.  
  936.   /*
  937.    * istream_type& operator>>(basic_streambuf&)
  938.    * reads characters from the stream and inserts them into 'sb'
  939.    */
  940.  
  941.   template<class charT, class traits>
  942.   basic_istream<charT, traits>&
  943.   basic_istream<charT, traits>::operator>>(streambuf_type& sb)
  944.   {
  945.     ios_base::iostate err = 0;
  946.  
  947. #ifndef _RWSTD_NO_EXCEPTIONS
  948.     try {
  949. #endif  
  950.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  951.       if(ipfx)
  952.       {
  953.         int_type         c;
  954.  
  955.         if ( traits::eq_int_type(this->rdbuf()->sgetc(),traits::eof()) ) 
  956.           err = ios_base::failbit; 
  957.          
  958.         while( !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) ) {
  959.           if( traits::eq_int_type(sb.sputc(c),traits::eof()) ) { 
  960.             err = ios_base::failbit;
  961.             break;
  962.           }
  963.           this->rdbuf()->sbumpc();  
  964.         }
  965.         if( traits::eq_int_type(c,traits::eof()) ) 
  966.           err |= ios_base::eofbit;  
  967.       }
  968. #ifndef _RWSTD_NO_EXCEPTIONS
  969.     } // end of try block
  970. #endif
  971.  
  972. #ifndef _RWSTD_NO_EXCEPTIONS
  973.     catch(...)
  974.     {
  975.       bool flag = false;
  976.       try {
  977.         this->setstate(ios_base::failbit);
  978.       }
  979.       catch( ios_base::failure ) { flag= true; }
  980.       if ( flag ) throw;
  981.     }
  982. #endif
  983.     if ( err ) this->setstate(err);
  984.     return *this;
  985.   }
  986.  
  987.   /*
  988.    * istream_type& operator>>(basic_streambuf *)
  989.    * reads characters from the stream and inserts them into 'sb'
  990.    */
  991.  
  992.   template<class charT, class traits>
  993.   basic_istream<charT, traits>&
  994.   basic_istream<charT, traits>::operator>>(streambuf_type *sb)
  995.   {
  996.     ios_base::iostate err = 0;
  997.  
  998. #ifndef _RWSTD_NO_EXCEPTIONS
  999.     try {
  1000. #endif 
  1001.       if ( sb!=0 )
  1002.       {
  1003.         _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
  1004.  
  1005.         if(ipfx)
  1006.         {
  1007.           int_type         c;
  1008.     
  1009.           if ( traits::eq_int_type(this->rdbuf()->sgetc(),traits::eof()) ) 
  1010.             err = ios_base::failbit; 
  1011.      
  1012.           while( !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
  1013.           {
  1014.             if( traits::eq_int_type(sb->sputc(c),traits::eof()) )
  1015.             { 
  1016.               err = ios_base::failbit;
  1017.               break;
  1018.             }
  1019.             this->rdbuf()->sbumpc(); 
  1020.           }
  1021.           if( traits::eq_int_type(c,traits::eof()) )
  1022.             err |= ios_base::eofbit;
  1023.         }
  1024.       }
  1025.       else
  1026.         err = ios_base::failbit;
  1027.  
  1028. #ifndef _RWSTD_NO_EXCEPTIONS
  1029.     } // end of try block
  1030. #endif
  1031.  
  1032. #ifndef _RWSTD_NO_EXCEPTIONS
  1033.     catch(...)
  1034.     {
  1035.       bool flag = false;
  1036.       try {
  1037.         this->setstate(ios_base::failbit);
  1038.       }
  1039.       catch( ios_base::failure ) { flag= true; }
  1040.       if ( flag ) throw;
  1041.     }
  1042. #endif
  1043.     if ( err ) this->setstate(err);
  1044.     return *this;
  1045.   }
  1046.  
  1047.   /*
  1048.    * istream_type& get(char_type *, streamsize, char_type)
  1049.    */
  1050.  
  1051.   template<class charT, class traits>
  1052.   basic_istream<charT, traits>&
  1053.   basic_istream<charT, traits>::
  1054.   get(char_type *s, streamsize n, char_type delim)
  1055.   {
  1056.     ios_base::iostate err = 0; 
  1057.  
  1058. #ifndef _RWSTD_NO_EXCEPTIONS
  1059.     try {
  1060. #endif  
  1061.       __chcount = 0; 
  1062.  
  1063.       if (s!=0)
  1064.       {
  1065.         _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1066.         if(ipfx)
  1067.         { 
  1068.           char_type  *op = s;
  1069.           int_type   c = 0;
  1070.  
  1071.           while(--n > 0 && (c = this->rdbuf()->sgetc()) != delim && 
  1072.                 ( !traits::eq_int_type(c,traits::eof()) ))
  1073.           {
  1074.             *s++ = c; 
  1075.             ++__chcount;
  1076.             this->rdbuf()->snextc(); 
  1077.           }
  1078.  
  1079.           if( traits::eq_int_type(c,traits::eof()) )  
  1080.             err = ((s == op) ? (ios_base::eofbit | ios_base::failbit) :
  1081.                    ios_base::eofbit);
  1082.         }
  1083.  
  1084.         *s = 0;  //terminate with null
  1085.       }
  1086.       else
  1087.         err = ios_base::badbit;
  1088.  
  1089. #ifndef _RWSTD_NO_EXCEPTIONS
  1090.     } // end of try block
  1091. #endif
  1092.  
  1093. #ifndef _RWSTD_NO_EXCEPTIONS
  1094.     catch(...)
  1095.     {
  1096.       bool flag = false;
  1097.       try {
  1098.         this->setstate(ios_base::badbit);
  1099.       }
  1100.       catch( ios_base::failure ) { flag= true; }
  1101.       if ( flag ) throw;
  1102.     }
  1103. #endif
  1104.     if ( err ) this->setstate(err);
  1105.     return *this;
  1106.   }
  1107.  
  1108.   /*
  1109.    * istream_type& get(char_type&)
  1110.    * gets a single character, first skipping white space.
  1111.    * see also: int_type get();
  1112.    */
  1113.  
  1114.   template<class charT, class traits>
  1115.   basic_istream<charT, traits>&
  1116.   basic_istream<charT, traits>::get(char_type& s)
  1117.   {
  1118.     ios_base::iostate err = 0;  
  1119.  
  1120. #ifndef _RWSTD_NO_EXCEPTIONS
  1121.     try {
  1122. #endif
  1123.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1124.       __chcount = 0;
  1125.  
  1126.       if(ipfx)
  1127.       { 
  1128.         int_type tmp = this->rdbuf()->sbumpc();
  1129.         if ( traits::eq_int_type(tmp,traits::eof()) ) 
  1130.         {
  1131.           err = ios_base::failbit | ios_base::eofbit;
  1132.         }
  1133.         else
  1134.         {
  1135.           s = traits::to_char_type(tmp);
  1136.           __chcount = 1;
  1137.         }
  1138.       }
  1139.  
  1140. #ifndef _RWSTD_NO_EXCEPTIONS
  1141.     } // end of try block
  1142. #endif
  1143.  
  1144. #ifndef _RWSTD_NO_EXCEPTIONS
  1145.     catch(...)
  1146.     {
  1147.       bool flag = false;
  1148.       try {
  1149.         this->setstate(ios_base::badbit);
  1150.       }
  1151.       catch( ios_base::failure ) { flag= true; }
  1152.       if ( flag ) throw;
  1153.     }
  1154. #endif
  1155.     if ( err ) this->setstate(err);
  1156.     return *this;
  1157.   }
  1158.  
  1159.   /*
  1160.    * istream_type& get(basic_streambuf&, char_type)
  1161.    * insert characters into sb upto delim
  1162.    */
  1163.  
  1164.   template<class charT, class traits>
  1165.   basic_istream<charT, traits>&
  1166.   basic_istream<charT, traits>::
  1167.   get(streambuf_type& sb, char_type delim)
  1168.   {
  1169.     ios_base::iostate err = 0;   
  1170.  
  1171. #ifndef _RWSTD_NO_EXCEPTIONS
  1172.     try {
  1173. #endif
  1174.       _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1175.       __chcount = 0;
  1176.  
  1177.       if(ipfx)
  1178.       { 
  1179.         int_type        c;
  1180.  
  1181.         while(((c = this->rdbuf()->sgetc()) != delim) && 
  1182.               ( !traits::eq_int_type(c,traits::eof()) ))
  1183.         {
  1184.           if( traits::eq_int_type(sb.sputc(c),traits::eof()) ) {  
  1185.             err = ios_base::failbit;  
  1186.             break;
  1187.           }
  1188.           ++__chcount;
  1189.           this->rdbuf()->sbumpc();  
  1190.         }
  1191.  
  1192.         if(c == traits::eof())  
  1193.           err |= ios_base::eofbit;
  1194.       }
  1195.  
  1196. #ifndef _RWSTD_NO_EXCEPTIONS
  1197.     } // end of try block
  1198. #endif
  1199.  
  1200. #ifndef _RWSTD_NO_EXCEPTIONS
  1201.     catch(...)
  1202.     {
  1203.       bool flag = false;
  1204.       try {
  1205.         this->setstate(ios_base::badbit);
  1206.       }
  1207.       catch( ios_base::failure ) { flag= true; }
  1208.       if ( flag ) throw;
  1209.     }
  1210. #endif
  1211.     if ( err ) this->setstate(err);
  1212.     return *this;
  1213.   }
  1214.  
  1215.   /*
  1216.    * istream_type& getline(char_type *, streamsize, char_type)
  1217.    */
  1218.  
  1219.   template<class charT, class traits>
  1220.   basic_istream<charT, traits>&
  1221.   basic_istream<charT, traits>::
  1222.   getline(char_type *s, streamsize n, char_type delim)
  1223.   {
  1224.     ios_base::iostate err = 0;
  1225.  
  1226. #ifndef _RWSTD_NO_EXCEPTIONS
  1227.     try {
  1228. #endif
  1229.       __chcount = 0;
  1230.  
  1231.       if (s!=0)
  1232.       {
  1233.         _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1234.  
  1235.         if(ipfx) {
  1236.           char_type    *op = s;
  1237.           int_type     c = 0;
  1238.  
  1239.           while( --n > 0 && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
  1240.           {
  1241.             ++__chcount;
  1242.             this->rdbuf()->sbumpc();
  1243.             if(c == delim)
  1244.               break;
  1245.             *s++ = c;
  1246.           }
  1247.           *s = 0;
  1248.           if( traits::eq_int_type(c,traits::eof()) )
  1249.             err = (s == op) ? (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit;
  1250.  
  1251.           if ( n == 0 )
  1252.           {
  1253.             if ( this->rdbuf()->sgetc() != delim )
  1254.               err |= ios_base::failbit;
  1255.             else
  1256. #if defined(__BORLANDC__) // RW_BUG: potential fix for bts-43439
  1257.               this->rdbuf()->sbumpc();
  1258. #else
  1259.               this->rdbuf()->snextc();
  1260. #endif
  1261.           }
  1262.  
  1263.         }
  1264.   
  1265.         *s = 0; //terminate with null
  1266.       }
  1267.       else
  1268.         err = ios_base::badbit;
  1269.  
  1270. #ifndef _RWSTD_NO_EXCEPTIONS
  1271.     } // end of try block
  1272. #endif
  1273.  
  1274. #ifndef _RWSTD_NO_EXCEPTIONS
  1275.     catch(...)
  1276.     {
  1277.       bool flag = false;
  1278.       try {
  1279.         this->setstate(ios_base::badbit);
  1280.       }
  1281.       catch( ios_base::failure ) { flag= true; }
  1282.       if ( flag ) throw;
  1283.     }
  1284. #endif //  _RWSTD_NO_EXCEPTIONS
  1285.     if ( err ) this->setstate(err);
  1286.     return *this;
  1287.   }
  1288.  
  1289.   /*
  1290.    * istream_type& ignore(streamsize, int_type)
  1291.    * this ignores n characters or until delim
  1292.    */
  1293.  
  1294.   template<class charT, class traits>
  1295.   basic_istream<charT, traits>&
  1296.   basic_istream<charT, traits>::ignore(streamsize n, int_type delim)
  1297.   {
  1298.     _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1299.     __chcount = 0;
  1300.  
  1301.     if(ipfx)
  1302.     {  
  1303.       int_type      c = 0;
  1304.  
  1305.       while(--n >= 0 && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
  1306.       {
  1307.         ++__chcount;
  1308.         this->rdbuf()->sbumpc();
  1309.         if(c == delim)   
  1310.           break;
  1311.       }
  1312.       if( traits::eq_int_type(c,traits::eof()) )
  1313.         this->setstate(ios_base::eofbit);
  1314.     }
  1315.     return *this;
  1316.   }
  1317.  
  1318.   /*
  1319.    * istream_type& read(char_type *, streamsize)
  1320.    */
  1321.  
  1322.   template<class charT, class traits>
  1323.   basic_istream<charT, traits>&
  1324.   basic_istream<charT, traits>::read(char_type *s, streamsize n)
  1325.   {
  1326.     ios_base::iostate err = 0; 
  1327.  
  1328. #ifndef _RWSTD_NO_EXCEPTIONS
  1329.     try {
  1330. #endif 
  1331.       __chcount = 0;
  1332.  
  1333.       if (s!=0)
  1334.       { 
  1335.         _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1336.  
  1337.         if(ipfx)
  1338.         {  
  1339.           int_type       c = 0;
  1340.  
  1341.           while((--n >= 0) && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()))
  1342.           {
  1343.             *s++ = c; 
  1344.             ++__chcount;
  1345.             this->rdbuf()->sbumpc();  
  1346.           }
  1347.  
  1348.           if( traits::eq_int_type(c,traits::eof()) )  
  1349.             err = (n >= 0) ? (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit;
  1350.         }
  1351.       }
  1352.       else
  1353.         err = ios_base::badbit;  
  1354.  
  1355. #ifndef _RWSTD_NO_EXCEPTIONS
  1356.     } // end of try block
  1357. #endif
  1358.  
  1359. #ifndef _RWSTD_NO_EXCEPTIONS
  1360.     catch(...)
  1361.     {
  1362.       bool flag = false;
  1363.       try {
  1364.         this->setstate(ios_base::badbit);
  1365.       }
  1366.       catch( ios_base::failure ) { flag= true; }
  1367.       if ( flag ) throw;
  1368.     }
  1369. #endif //  _RWSTD_NO_EXCEPTIONS
  1370.     if ( err ) this->setstate(err);
  1371.     return *this;
  1372.   }
  1373.  
  1374.   /*
  1375.    * streamsize readsome(char_type *, streamsize)
  1376.    */
  1377.  
  1378.   template<class charT, class traits>
  1379.   streamsize 
  1380.   basic_istream<charT, traits>::readsome(char_type *s, streamsize n)
  1381.   {
  1382.     int navail = this->rdbuf()->in_avail();
  1383.  
  1384.    
  1385.     if(navail == -1)
  1386.     {   
  1387.       this->setstate(ios_base::eofbit);
  1388.       return 0;
  1389.     }
  1390.     if(navail == 0 ) return 0;
  1391.  
  1392.     if ( this->good() )
  1393.     {
  1394.       if(n < navail) 
  1395.       { 
  1396.         read(s, n);
  1397.         return (n);
  1398.       }
  1399.  
  1400.       read(s, navail);
  1401.       return (streamsize)(navail);
  1402.     }
  1403.     else
  1404.     { 
  1405.       if ( !(this->rdstate() & ios_base::failbit) )
  1406.         this->setstate(ios_base::failbit);
  1407.     }
  1408.   
  1409.     return 0;
  1410.   }
  1411.  
  1412.   /*
  1413.    * int peek()
  1414.    */
  1415.  
  1416.   template<class charT, class traits>
  1417.   int basic_istream<charT, traits>::peek()
  1418.   {
  1419.     __chcount = 0;
  1420.  
  1421.     if(this->good())
  1422.     {
  1423. #ifdef _RWSTD_MULTI_THREAD
  1424.       if ( this->rdbuf() )
  1425.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1426. #endif
  1427.       _TYPENAME traits::int_type tmp = this->rdbuf()->sgetc();
  1428.       if ( !traits::eq_int_type( tmp,traits::eof() ) )
  1429.         __chcount = 1;
  1430.       return tmp;
  1431.     }
  1432.  
  1433.     return traits::eof();
  1434.   }
  1435.  
  1436.   /*
  1437.    * pos_type tellg()
  1438.    */
  1439.  
  1440.   template<class charT, class traits>
  1441.   _TYPENAME basic_istream<charT, traits>::pos_type
  1442.   basic_istream<charT, traits>::tellg()
  1443.   {
  1444.     ios_base::iostate err = 0; 
  1445.     pos_type         p;
  1446.  
  1447. #ifndef _RWSTD_NO_EXCEPTIONS
  1448.     try {
  1449. #endif 
  1450.  
  1451. #ifdef _RWSTD_MULTI_THREAD
  1452.       if ( this->rdbuf() )
  1453.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1454. #endif //  _RWSTD_MULTI_THREAD
  1455.       if ( this->bad() ) return pos_type(off_type(-1));   
  1456.  
  1457.       if((p = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in))
  1458.          == pos_type(off_type(-1)))
  1459.         err = ios_base::failbit;
  1460.  
  1461. #ifndef _RWSTD_NO_EXCEPTIONS
  1462.     }
  1463. #endif
  1464.  
  1465. #ifndef _RWSTD_NO_EXCEPTIONS
  1466.     catch(...)
  1467.     {
  1468.       bool flag = false;
  1469.       try {
  1470.         this->setstate(ios_base::badbit);
  1471.       }
  1472.       catch( ios_base::failure ) { flag= true; }
  1473.       if ( flag ) throw;
  1474.     }
  1475. #endif
  1476.     if ( err ) this->setstate(err);
  1477.     return p;
  1478.   }
  1479.   /*
  1480.    * istream_type& putback(char_type)
  1481.    */
  1482.  
  1483.   template<class charT, class traits>
  1484.   basic_istream<charT, traits>&
  1485.   basic_istream<charT, traits>::putback(char_type c)
  1486.   {
  1487.     ios_base::iostate err = 0;
  1488.  
  1489. #ifndef _RWSTD_NO_EXCEPTIONS
  1490.     try {
  1491. #endif 
  1492.   
  1493. #ifdef _RWSTD_MULTI_THREAD
  1494.       if ( this->rdbuf() )
  1495.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1496. #endif 
  1497.       if (this->good())
  1498.       {
  1499.         if( traits::eq_int_type(this->rdbuf()->sputbackc(c),traits::eof()) ) 
  1500.           err = ios_base::badbit;      
  1501.       }
  1502.       else
  1503.       { 
  1504.         if ( !(this->rdstate() & ios_base::failbit) )
  1505.           this->setstate(ios_base::failbit);
  1506.       }
  1507.  
  1508. #ifndef _RWSTD_NO_EXCEPTIONS
  1509.     }
  1510. #endif
  1511.  
  1512. #ifndef _RWSTD_NO_EXCEPTIONS
  1513.     catch(...)
  1514.     {
  1515.       bool flag = false;
  1516.       try {
  1517.         this->setstate(ios_base::badbit);
  1518.       }
  1519.       catch( ios_base::failure ) { flag= true; }
  1520.       if ( flag ) throw;
  1521.     }
  1522. #endif
  1523.     if ( err ) this->setstate(err);
  1524.     return *this;
  1525.   }
  1526.  
  1527.   /*
  1528.    * istream_type& unget()
  1529.    */
  1530.  
  1531.   template<class charT, class traits>
  1532.   basic_istream<charT, traits>&
  1533.   basic_istream<charT, traits>::unget()
  1534.   {
  1535.     ios_base::iostate err = 0;
  1536.  
  1537. #ifndef _RWSTD_NO_EXCEPTIONS
  1538.     try {
  1539. #endif 
  1540.  
  1541. #ifdef _RWSTD_MULTI_THREAD
  1542.       if ( this->rdbuf() )
  1543.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1544. #endif
  1545.       if (this->good())
  1546.       {
  1547.         if( traits::eq_int_type(this->rdbuf()->sungetc(),traits::eof()) )
  1548.           err = ios_base::badbit;  
  1549.       }
  1550.       else
  1551.       { 
  1552.         if ( !(this->rdstate() & ios_base::failbit) )
  1553.           this->setstate(ios_base::failbit);
  1554.       }
  1555.  
  1556. #ifndef _RWSTD_NO_EXCEPTIONS
  1557.     } // end of try block
  1558. #endif
  1559.  
  1560. #ifndef _RWSTD_NO_EXCEPTIONS
  1561.     catch(...)
  1562.     {
  1563.       bool flag = false;
  1564.       try {
  1565.         this->setstate(ios_base::badbit);
  1566.       }
  1567.       catch( ios_base::failure ) { flag= true; }
  1568.       if ( flag ) throw;
  1569.     }
  1570. #endif //  _RWSTD_NO_EXCEPTIONS
  1571.     if ( err ) this->setstate(err);
  1572.     return *this;
  1573.   }
  1574.  
  1575.   /*
  1576.    * streamsize gcount() const
  1577.    */
  1578.  
  1579.   template<class charT, class traits>
  1580.   streamsize basic_istream<charT, traits>::gcount() const
  1581.   {
  1582.     return __chcount;
  1583.   }
  1584.  
  1585.   /*
  1586.    * int sync()
  1587.    */
  1588.  
  1589.   template<class charT, class traits>
  1590.   int basic_istream<charT, traits>::sync()
  1591.   {
  1592.     ios_base::iostate err = 0;
  1593.  
  1594. #ifndef _RWSTD_NO_EXCEPTIONS
  1595.     try {
  1596. #endif 
  1597.   
  1598. #ifdef _RWSTD_MULTI_THREAD
  1599.       if ( this->rdbuf() )
  1600.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1601. #endif
  1602.       if(this->rdbuf()) 
  1603.       {  
  1604.         if(this->rdbuf()->pubsync() == -1)
  1605.           err = ios_base::badbit;  
  1606.         else
  1607.         {
  1608.           if ( this->rdstate() & ios_base::eofbit )
  1609.             clear( this->rdstate() & ~(ios_base::eofbit | ios_base::failbit));
  1610.           return 0;
  1611.         } 
  1612.       }
  1613.  
  1614. #ifndef _RWSTD_NO_EXCEPTIONS
  1615.     } // end of try block
  1616. #endif
  1617.  
  1618. #ifndef _RWSTD_NO_EXCEPTIONS
  1619.     catch(...)
  1620.     {
  1621.       bool flag = false;
  1622.       try {
  1623.         this->setstate(ios_base::badbit);
  1624.       }
  1625.       catch( ios_base::failure ) { flag= true; }
  1626.       if ( flag ) throw;
  1627.     }
  1628. #endif
  1629.     if ( err ) this->setstate(err);
  1630.     return -1;
  1631.   }
  1632.  
  1633.   // string extractor and getline
  1634.  
  1635. #ifndef _RWSTD_NO_NAMESPACE
  1636. }
  1637. namespace __rwstd {
  1638. #endif
  1639.  
  1640.   template <class streamT, class stringT, class traits>
  1641.   streamT& _RWSTDExportTemplate rw_extract_string(streamT& is, stringT& s, traits)
  1642.   {
  1643.     _TYPENAME streamT::int_type c;
  1644.     _RW_STD::ios_base::iostate err = 0;
  1645.  
  1646. #ifndef _RWSTD_NO_EXCEPTIONS
  1647.     try {
  1648. #endif  
  1649.       _TYPENAME streamT::sentry ipfx(is);
  1650.  
  1651.       if(ipfx)
  1652.       { 
  1653.         s.erase();
  1654.         c = is.rdbuf()->sbumpc();
  1655.  
  1656.         const _RW_STD::ctype<_TYPENAME streamT::char_type>& ctype_facet =
  1657. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  1658.         _RW_STD::use_facet<_RW_STD::ctype<_TYPENAME streamT::char_type> >(is.getloc());
  1659. #else
  1660.         _RW_STD::use_facet(is.getloc(),(_RW_STD::ctype<_TYPENAME streamT::char_type>*)0);
  1661. #endif //  _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  1662.  
  1663.         _TYPENAME stringT::size_type i = 0, len = 32;
  1664.         _TYPENAME stringT::value_type* buff = new _TYPENAME stringT::value_type[len+1];
  1665.         _TYPENAME stringT::value_type* ptr = buff;
  1666.  
  1667.         _TYPENAME stringT::size_type end = s.max_size();
  1668.         if (is.width())
  1669.           end = (end >  (_TYPENAME stringT::size_type)is.width()) ? is.width() : end;
  1670.  
  1671.         while ( !traits::eq_int_type(c,traits::eof()) &&  !ctype_facet.is(ctype_facet.space,c) )
  1672.         {
  1673.           if (i == len)
  1674.           {
  1675.             _TYPENAME stringT::size_type oldlen = len;             
  1676.             len *= 2;
  1677.             _TYPENAME stringT::value_type* tmp = new _TYPENAME stringT::value_type[len+1];
  1678.             traits::move(tmp,buff,oldlen);
  1679.             delete [] buff;
  1680.             buff = tmp;
  1681.             ptr = buff + i;
  1682.           }
  1683.  
  1684.           *ptr++ = traits::to_char_type(c);            
  1685.           i++;
  1686.           if ( i == end ) break;
  1687.           c = is.rdbuf()->sbumpc();
  1688.         }
  1689.         *ptr = traits::to_char_type(0);
  1690.         s.assign(buff,i);
  1691.         delete [] buff;
  1692.  
  1693.         if ( i == 0 ) err |= _RW_STD::ios_base::failbit;
  1694.         if ( traits::eq_int_type(c,traits::eof()) ) 
  1695.           err |= _RW_STD::ios_base::eofbit;
  1696.  
  1697.       }
  1698.  
  1699.       is.width(0);
  1700. #ifndef _RWSTD_NO_EXCEPTIONS
  1701.     } // end of try block
  1702. #endif
  1703.  
  1704. #ifndef _RWSTD_NO_EXCEPTIONS
  1705.     catch(...)
  1706.     {
  1707.       bool flag = false;
  1708.       try {
  1709.         is.setstate(_RW_STD::ios_base::badbit);
  1710.       }
  1711.       catch( _RW_STD::ios_base::failure ) { flag= true; }
  1712.       if ( flag ) throw;
  1713.     }
  1714. #endif
  1715.  
  1716.     if ( err ) is.setstate(err);
  1717.     return is;
  1718.   }
  1719. #ifndef _RWSTD_NO_NAMESPACE
  1720. }
  1721. namespace std {
  1722. #endif
  1723.  
  1724.   template<class charT, class traits, class Allocator>
  1725.   basic_istream<charT,traits>&
  1726.   _RWSTDExportTemplate getline (basic_istream<charT,traits>& is,
  1727.                         basic_string<charT,traits,Allocator>& str,
  1728.                         charT delim )
  1729.   {
  1730.     _TYPENAME traits::int_type c;
  1731.     ios_base::iostate err = 0;
  1732.  
  1733. #ifndef _RWSTD_NO_EXCEPTIONS
  1734.     try {
  1735. #endif
  1736.       _TYPENAME basic_istream<charT,traits>::sentry ipfx(is,1);
  1737.  
  1738.       if(ipfx)
  1739.       {
  1740.         c = is.rdbuf()->sbumpc();
  1741.         _TYPENAME Allocator::size_type i = 0, len = 32;
  1742.  
  1743.         charT* buff = new charT[len+1];
  1744.         charT* ptr =  buff;
  1745.         bool force_no_error = false;  // RW_BUG: (bts-43483)
  1746.  
  1747.         while ( !traits::eq_int_type(c,traits::eof()) )
  1748.         {
  1749.           if (i == len)
  1750.           {
  1751.             _TYPENAME Allocator::size_type oldlen = len;
  1752.             len *= 2;
  1753.             charT* tmp = new charT[len+1];
  1754.             traits::move(tmp,buff,oldlen);
  1755.             delete [] buff;
  1756.             buff = tmp;
  1757.             ptr = buff + i;
  1758.           }
  1759.           if ( traits::eq(traits::to_char_type(c),delim) )
  1760.           {
  1761.             if (i == 0)
  1762.               force_no_error = true;  // RW_BUG: (bts-43483)
  1763.             break;
  1764.           }
  1765.           i++;
  1766.           if (i == str.max_size())
  1767.           {
  1768.             err |= ios_base::failbit;
  1769.             break;
  1770.           }
  1771.           *ptr++ = traits::to_char_type(c);
  1772.           c = is.rdbuf()->sbumpc();
  1773.         }
  1774.         *ptr = traits::to_char_type(0);
  1775.         str.assign(buff,i);
  1776.         delete [] buff;
  1777.  
  1778.         if ( traits::eq_int_type(c,traits::eof()) )
  1779.           err |= ios_base::eofbit;
  1780.  
  1781.         if ( i==0 && (force_no_error == false))  // RW_BUG: (bts-43483)
  1782.           err |= ios_base::failbit;
  1783.  
  1784.       }
  1785. #ifndef _RWSTD_NO_EXCEPTIONS
  1786.     } // end of try block
  1787. #endif
  1788.  
  1789. #ifndef _RWSTD_NO_EXCEPTIONS
  1790.     catch(...)
  1791.     {
  1792.       bool flag = false;
  1793.       try {
  1794.         is.setstate(ios_base::badbit);
  1795.       }
  1796.       catch( ios_base::failure ) { flag= true; }
  1797.       if ( flag ) throw;
  1798.     }
  1799. #endif
  1800.     if ( err ) is.setstate(err);
  1801.     return is;
  1802.   }  
  1803.   /*
  1804.    * class basic_iostream
  1805.    */
  1806.  
  1807.   /*
  1808.    * basic_iostream(basic_streambuf *)
  1809.    */
  1810.  
  1811.   template<class charT, class traits>
  1812.   basic_iostream<charT, traits>::
  1813.   basic_iostream(basic_streambuf<charT, traits> *sb)
  1814.   :basic_istream<charT, traits>(sb)
  1815.   ,basic_ostream<charT, traits>(sb)
  1816.   {
  1817.   }
  1818.  
  1819.   /*
  1820.    * basic_iostream( )
  1821.    */
  1822.  
  1823.   template<class charT, class traits>
  1824.   basic_iostream<charT, traits>::
  1825.   basic_iostream( )
  1826.   :basic_istream<charT, traits>()
  1827.   ,basic_ostream<charT, traits>()
  1828.   {
  1829.   }
  1830.   /*
  1831.    * ~basic_iostream()
  1832.    */
  1833.  
  1834.   template<class charT, class traits>
  1835.   basic_iostream<charT, traits>::
  1836.   ~basic_iostream()
  1837.   {
  1838.   }
  1839.  
  1840. #ifndef _RWSTD_NO_NAMESPACE
  1841. }
  1842. #endif
  1843.  
  1844. #pragma option pop
  1845. #endif /* __ISTREAM_CC */
  1846.