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