home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / istream.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  44.3 KB  |  1,825 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.           else if ( this->rdbuf()->sgetc() == delim )
  1242.              this->rdbuf()->sbumpc();          // eat the delimiter
  1243.           else if ( n == 0 )
  1244.              err |= ios_base::failbit;   // too much data
  1245.         }
  1246.   
  1247.         *s = 0; //terminate with null
  1248.       }
  1249.       else
  1250.         err = ios_base::badbit;
  1251.  
  1252. #ifndef _RWSTD_NO_EXCEPTIONS
  1253.     } // end of try block
  1254. #endif
  1255.  
  1256. #ifndef _RWSTD_NO_EXCEPTIONS
  1257.     catch(...)
  1258.     {
  1259.       bool flag = false;
  1260.       try {
  1261.         this->setstate(ios_base::badbit);
  1262.       }
  1263.       catch( ios_base::failure ) { flag= true; }
  1264.       if ( flag ) throw;
  1265.     }
  1266. #endif //  _RWSTD_NO_EXCEPTIONS
  1267.     if ( err ) this->setstate(err);
  1268.     return *this;
  1269.   }
  1270.  
  1271.   /*
  1272.    * istream_type& ignore(streamsize, int_type)
  1273.    * this ignores n characters or until delim
  1274.    */
  1275.  
  1276.   template<class charT, class traits>
  1277.   basic_istream<charT, traits>&
  1278.   basic_istream<charT, traits>::ignore(streamsize n, int_type delim)
  1279.   {
  1280.     _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1281.     __chcount = 0;
  1282.  
  1283.     if(ipfx)
  1284.     {  
  1285.       int_type      c = 0;
  1286.  
  1287.       while(--n >= 0 && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
  1288.       {
  1289.         ++__chcount;
  1290.         this->rdbuf()->sbumpc();
  1291.         if(c == delim)   
  1292.           break;
  1293.       }
  1294.       if( traits::eq_int_type(c,traits::eof()) )
  1295.         this->setstate(ios_base::eofbit);
  1296.     }
  1297.     return *this;
  1298.   }
  1299.  
  1300.   /*
  1301.    * istream_type& read(char_type *, streamsize)
  1302.    */
  1303.  
  1304.   template<class charT, class traits>
  1305.   basic_istream<charT, traits>&
  1306.   basic_istream<charT, traits>::read(char_type *s, streamsize n)
  1307.   {
  1308.     ios_base::iostate err = 0; 
  1309.  
  1310. #ifndef _RWSTD_NO_EXCEPTIONS
  1311.     try {
  1312. #endif 
  1313.       __chcount = 0;
  1314.  
  1315.       if (s!=0)
  1316.       { 
  1317.         _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
  1318.  
  1319.         if(ipfx)
  1320.         {  
  1321.           int_type       c = 0;
  1322.  
  1323.           while((--n >= 0) && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()))
  1324.           {
  1325.             *s++ = c; 
  1326.             ++__chcount;
  1327.             this->rdbuf()->sbumpc();  
  1328.           }
  1329.  
  1330.           if( traits::eq_int_type(c,traits::eof()) )  
  1331.             err = (n >= 0) ? (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit;
  1332.         }
  1333.       }
  1334.       else
  1335.         err = ios_base::badbit;  
  1336.  
  1337. #ifndef _RWSTD_NO_EXCEPTIONS
  1338.     } // end of try block
  1339. #endif
  1340.  
  1341. #ifndef _RWSTD_NO_EXCEPTIONS
  1342.     catch(...)
  1343.     {
  1344.       bool flag = false;
  1345.       try {
  1346.         this->setstate(ios_base::badbit);
  1347.       }
  1348.       catch( ios_base::failure ) { flag= true; }
  1349.       if ( flag ) throw;
  1350.     }
  1351. #endif //  _RWSTD_NO_EXCEPTIONS
  1352.     if ( err ) this->setstate(err);
  1353.     return *this;
  1354.   }
  1355.  
  1356.   /*
  1357.    * streamsize readsome(char_type *, streamsize)
  1358.    */
  1359.  
  1360.   template<class charT, class traits>
  1361.   streamsize 
  1362.   basic_istream<charT, traits>::readsome(char_type *s, streamsize n)
  1363.   {
  1364.     int navail = this->rdbuf()->in_avail();
  1365.  
  1366.    
  1367.     if(navail == -1)
  1368.     {   
  1369.       this->setstate(ios_base::eofbit);
  1370.       return 0;
  1371.     }
  1372.     if(navail == 0 ) return 0;
  1373.  
  1374.     if ( this->good() )
  1375.     {
  1376.       if(n < navail) 
  1377.       { 
  1378.         read(s, n);
  1379.         return (n);
  1380.       }
  1381.  
  1382.       read(s, navail);
  1383.       return (streamsize)(navail);
  1384.     }
  1385.     else
  1386.     { 
  1387.       if ( !(this->rdstate() & ios_base::failbit) )
  1388.         this->setstate(ios_base::failbit);
  1389.     }
  1390.   
  1391.     return 0;
  1392.   }
  1393.  
  1394.   /*
  1395.    * int_type peek()
  1396.    */
  1397.  
  1398.   template<class charT, class traits>
  1399.   _TYPENAME basic_istream<charT, traits>::int_type
  1400.   basic_istream<charT, traits>::peek()
  1401.   {
  1402.     __chcount = 0;
  1403.  
  1404.     if(this->good())
  1405.     {
  1406. #ifdef _RWSTD_MULTI_THREAD
  1407.       if ( this->rdbuf() )
  1408.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1409. #endif
  1410.       _TYPENAME traits::int_type tmp = this->rdbuf()->sgetc();
  1411.       if ( !traits::eq_int_type( tmp,traits::eof() ) )
  1412.         __chcount = 1;
  1413.       return tmp;
  1414.     }
  1415.  
  1416.     return traits::eof();
  1417.   }
  1418.  
  1419.   /*
  1420.    * pos_type tellg()
  1421.    */
  1422.  
  1423.   template<class charT, class traits>
  1424.   _TYPENAME basic_istream<charT, traits>::pos_type
  1425.   basic_istream<charT, traits>::tellg()
  1426.   {
  1427.     ios_base::iostate err = 0; 
  1428.     pos_type         p;
  1429.  
  1430. #ifndef _RWSTD_NO_EXCEPTIONS
  1431.     try {
  1432. #endif 
  1433.  
  1434. #ifdef _RWSTD_MULTI_THREAD
  1435.       if ( this->rdbuf() ) {
  1436.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1437. #endif //  _RWSTD_MULTI_THREAD
  1438.       if ( this->fail() ) return pos_type(off_type(-1));   
  1439.  
  1440.       p = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
  1441.  
  1442. #ifdef _RWSTD_MULTI_THREAD
  1443.       }
  1444. #endif //  _RWSTD_MULTI_THREAD
  1445.  
  1446. #ifndef _RWSTD_NO_EXCEPTIONS
  1447.     }
  1448. #endif
  1449.  
  1450. #ifndef _RWSTD_NO_EXCEPTIONS
  1451.     catch(...)
  1452.     {
  1453.       bool flag = false;
  1454.       try {
  1455.         this->setstate(ios_base::badbit);
  1456.       }
  1457.       catch( ios_base::failure ) { flag= true; }
  1458.       if ( flag ) throw;
  1459.     }
  1460. #endif
  1461.  
  1462.     return p;
  1463.   }
  1464.   /*
  1465.    * istream_type& putback(char_type)
  1466.    */
  1467.  
  1468.   template<class charT, class traits>
  1469.   basic_istream<charT, traits>&
  1470.   basic_istream<charT, traits>::putback(char_type c)
  1471.   {
  1472.     ios_base::iostate err = 0;
  1473.  
  1474. #ifndef _RWSTD_NO_EXCEPTIONS
  1475.     try {
  1476. #endif 
  1477.   
  1478. #ifdef _RWSTD_MULTI_THREAD
  1479.       if ( this->rdbuf() )
  1480.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1481. #endif 
  1482.       if (this->good())
  1483.       {
  1484.         if( traits::eq_int_type(this->rdbuf()->sputbackc(c),traits::eof()) ) 
  1485.           err = ios_base::badbit;      
  1486.       }
  1487.       else
  1488.       { 
  1489.         if ( !(this->rdstate() & ios_base::failbit) )
  1490.           this->setstate(ios_base::failbit);
  1491.       }
  1492.  
  1493. #ifndef _RWSTD_NO_EXCEPTIONS
  1494.     }
  1495. #endif
  1496.  
  1497. #ifndef _RWSTD_NO_EXCEPTIONS
  1498.     catch(...)
  1499.     {
  1500.       bool flag = false;
  1501.       try {
  1502.         this->setstate(ios_base::badbit);
  1503.       }
  1504.       catch( ios_base::failure ) { flag= true; }
  1505.       if ( flag ) throw;
  1506.     }
  1507. #endif
  1508.     if ( err ) this->setstate(err);
  1509.     return *this;
  1510.   }
  1511.  
  1512.   /*
  1513.    * istream_type& unget()
  1514.    */
  1515.  
  1516.   template<class charT, class traits>
  1517.   basic_istream<charT, traits>&
  1518.   basic_istream<charT, traits>::unget()
  1519.   {
  1520.     ios_base::iostate err = 0;
  1521.  
  1522. #ifndef _RWSTD_NO_EXCEPTIONS
  1523.     try {
  1524. #endif 
  1525.  
  1526. #ifdef _RWSTD_MULTI_THREAD
  1527.       if ( this->rdbuf() )
  1528.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1529. #endif
  1530.       if (this->good())
  1531.       {
  1532.         if( traits::eq_int_type(this->rdbuf()->sungetc(),traits::eof()) )
  1533.           err = ios_base::badbit;  
  1534.       }
  1535.       else
  1536.       { 
  1537.         if ( !(this->rdstate() & ios_base::failbit) )
  1538.           this->setstate(ios_base::failbit);
  1539.       }
  1540.  
  1541. #ifndef _RWSTD_NO_EXCEPTIONS
  1542.     } // end of try block
  1543. #endif
  1544.  
  1545. #ifndef _RWSTD_NO_EXCEPTIONS
  1546.     catch(...)
  1547.     {
  1548.       bool flag = false;
  1549.       try {
  1550.         this->setstate(ios_base::badbit);
  1551.       }
  1552.       catch( ios_base::failure ) { flag= true; }
  1553.       if ( flag ) throw;
  1554.     }
  1555. #endif //  _RWSTD_NO_EXCEPTIONS
  1556.     if ( err ) this->setstate(err);
  1557.     return *this;
  1558.   }
  1559.  
  1560.   /*
  1561.    * streamsize gcount() const
  1562.    */
  1563.  
  1564.   template<class charT, class traits>
  1565.   streamsize basic_istream<charT, traits>::gcount() const
  1566.   {
  1567.     return __chcount;
  1568.   }
  1569.  
  1570.   /*
  1571.    * int sync()
  1572.    */
  1573.  
  1574.   template<class charT, class traits>
  1575.   int basic_istream<charT, traits>::sync()
  1576.   {
  1577.     ios_base::iostate err = 0;
  1578.  
  1579. #ifndef _RWSTD_NO_EXCEPTIONS
  1580.     try {
  1581. #endif 
  1582.   
  1583. #ifdef _RWSTD_MULTI_THREAD
  1584.       if ( this->rdbuf() )
  1585.         _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
  1586. #endif
  1587.       if(this->rdbuf()) 
  1588.       {  
  1589.         if(this->rdbuf()->pubsync() == -1)
  1590.           err = ios_base::badbit;  
  1591.         else
  1592.         {
  1593.           if ( this->rdstate() & ios_base::eofbit )
  1594.             clear( this->rdstate() & ~(ios_base::eofbit | ios_base::failbit));
  1595.           return 0;
  1596.         } 
  1597.       }
  1598.  
  1599. #ifndef _RWSTD_NO_EXCEPTIONS
  1600.     } // end of try block
  1601. #endif
  1602.  
  1603. #ifndef _RWSTD_NO_EXCEPTIONS
  1604.     catch(...)
  1605.     {
  1606.       bool flag = false;
  1607.       try {
  1608.         this->setstate(ios_base::badbit);
  1609.       }
  1610.       catch( ios_base::failure ) { flag= true; }
  1611.       if ( flag ) throw;
  1612.     }
  1613. #endif
  1614.     if ( err ) this->setstate(err);
  1615.     return -1;
  1616.   }
  1617.  
  1618.   // string extractor and getline
  1619.  
  1620. #ifndef _RWSTD_NO_NAMESPACE
  1621. }
  1622. namespace __rwstd {
  1623. #endif
  1624.  
  1625.   template <class streamT, class stringT, class traits>
  1626.   streamT& _RWSTDExportTemplate rw_extract_string(streamT& is, stringT& s, traits)
  1627.   {
  1628.     _TYPENAME streamT::int_type c;
  1629.     _RW_STD::ios_base::iostate err = 0;
  1630.  
  1631. #ifndef _RWSTD_NO_EXCEPTIONS
  1632.     try {
  1633. #endif  
  1634.       _TYPENAME streamT::sentry ipfx(is);
  1635.  
  1636.       if(ipfx)
  1637.       { 
  1638.         s.erase();
  1639.         c = is.rdbuf()->sbumpc();
  1640.  
  1641.         const _RW_STD::ctype<_TYPENAME streamT::char_type>& ctype_facet =
  1642. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  1643.         _RW_STD::use_facet<_RW_STD::ctype<_TYPENAME streamT::char_type> >(is.getloc());
  1644. #else
  1645.         _RW_STD::use_facet(is.getloc(),(_RW_STD::ctype<_TYPENAME streamT::char_type>*)0);
  1646. #endif //  _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  1647.  
  1648.         _TYPENAME stringT::size_type i = 0, len = 32;
  1649.         _TYPENAME stringT::value_type* buff = new _TYPENAME stringT::value_type[len+1];
  1650.         _TYPENAME stringT::value_type* ptr = buff;
  1651.  
  1652.         _TYPENAME stringT::size_type end = s.max_size();
  1653.         if (is.width())
  1654.           end = (end >  (_TYPENAME stringT::size_type)is.width()) ? is.width() : end;
  1655.  
  1656.         while ( !traits::eq_int_type(c,traits::eof()) &&  !ctype_facet.is(ctype_facet.space,c) )
  1657.         {
  1658.           if (i == len)
  1659.           {
  1660.             _TYPENAME stringT::size_type oldlen = len;             
  1661.             len *= 2;
  1662.             _TYPENAME stringT::value_type* tmp = new _TYPENAME stringT::value_type[len+1];
  1663.             traits::move(tmp,buff,oldlen);
  1664.             delete [] buff;
  1665.             buff = tmp;
  1666.             ptr = buff + i;
  1667.           }
  1668.  
  1669.           *ptr++ = traits::to_char_type(c);            
  1670.           i++;
  1671.           if ( i == end ) break;
  1672.           c = is.rdbuf()->sbumpc();
  1673.         }
  1674.         *ptr = traits::to_char_type(0);
  1675.         s.assign(buff,i);
  1676.         delete [] buff;
  1677.  
  1678.         if ( i == 0 ) err |= _RW_STD::ios_base::failbit;
  1679.         if ( traits::eq_int_type(c,traits::eof()) ) 
  1680.           err |= _RW_STD::ios_base::eofbit;
  1681.  
  1682.       }
  1683.  
  1684.       is.width(0);
  1685. #ifndef _RWSTD_NO_EXCEPTIONS
  1686.     } // end of try block
  1687. #endif
  1688.  
  1689. #ifndef _RWSTD_NO_EXCEPTIONS
  1690.     catch(...)
  1691.     {
  1692.       bool flag = false;
  1693.       try {
  1694.         is.setstate(_RW_STD::ios_base::badbit);
  1695.       }
  1696.       catch( _RW_STD::ios_base::failure ) { flag= true; }
  1697.       if ( flag ) throw;
  1698.     }
  1699. #endif
  1700.  
  1701.     if ( err ) is.setstate(err);
  1702.     return is;
  1703.   }
  1704. #ifndef _RWSTD_NO_NAMESPACE
  1705. }
  1706. namespace std {
  1707. #endif
  1708.  
  1709.   template<class charT, class traits, class Allocator>
  1710.   basic_istream<charT,traits>&
  1711.   _RWSTDExportTemplate getline (basic_istream<charT,traits>& is,
  1712.                         basic_string<charT,traits,Allocator>& str,
  1713.                         charT delim )
  1714.   {
  1715.     _TYPENAME traits::int_type c;
  1716.     ios_base::iostate err = 0;
  1717.  
  1718. #ifndef _RWSTD_NO_EXCEPTIONS
  1719.     try {
  1720. #endif  
  1721.       _TYPENAME basic_istream<charT,traits>::sentry ipfx(is,1);
  1722.  
  1723.       if(ipfx)
  1724.       {
  1725.         c = is.rdbuf()->sbumpc();
  1726.         _TYPENAME Allocator::size_type i = 0, len = 32;
  1727.  
  1728.         charT* buff = new charT[len+1];
  1729.         charT* ptr =  buff;
  1730.  
  1731.         while ( !traits::eq_int_type(c,traits::eof()) )
  1732.         {
  1733.           if (i == len)
  1734.           {
  1735.             _TYPENAME Allocator::size_type oldlen = len;
  1736.             len *= 2;
  1737.             charT* tmp = new charT[len+1];
  1738.             traits::move(tmp,buff,oldlen);
  1739.             delete [] buff;
  1740.             buff = tmp;
  1741.             ptr = buff + i;
  1742.           }
  1743.           i++; // RW_BUG: <Regressed> i++ must happen before the break line (bts-43483)
  1744.           if ( traits::eq(traits::to_char_type(c),delim) )
  1745.             break;
  1746.           if (i == str.max_size())
  1747.           {
  1748.             err |= ios_base::failbit;
  1749.             break;
  1750.           }
  1751.           *ptr++ = traits::to_char_type(c);
  1752.           c = is.rdbuf()->sbumpc();
  1753.         }
  1754.         *ptr = traits::to_char_type(0);
  1755.         str.assign(buff,i);
  1756.         delete [] buff;
  1757.  
  1758.         if ( traits::eq_int_type(c,traits::eof()) )
  1759.           err |= ios_base::eofbit;
  1760.  
  1761.         if ( i==0 )
  1762.           err |= ios_base::failbit;
  1763.  
  1764.       }
  1765. #ifndef _RWSTD_NO_EXCEPTIONS
  1766.     } // end of try block
  1767. #endif
  1768.  
  1769. #ifndef _RWSTD_NO_EXCEPTIONS
  1770.     catch(...)
  1771.     {
  1772.       bool flag = false;
  1773.       try {
  1774.         is.setstate(ios_base::badbit);
  1775.       }
  1776.       catch( ios_base::failure ) { flag= true; }
  1777.       if ( flag ) throw;
  1778.     }
  1779. #endif
  1780.     if ( err ) is.setstate(err);
  1781.     return is;
  1782.   }  
  1783.   /*
  1784.    * class basic_iostream
  1785.    */
  1786.  
  1787.   /*
  1788.    * basic_iostream(basic_streambuf *)
  1789.    */
  1790.  
  1791.   template<class charT, class traits>
  1792.   basic_iostream<charT, traits>::
  1793.   basic_iostream(basic_streambuf<charT, traits> *sb)
  1794.   :basic_istream<charT, traits>(sb)
  1795.   ,basic_ostream<charT, traits>(sb)
  1796.   {
  1797.   }
  1798.  
  1799.   /*
  1800.    * basic_iostream( )
  1801.    */
  1802.  
  1803.   template<class charT, class traits>
  1804.   basic_iostream<charT, traits>::
  1805.   basic_iostream( )
  1806.   :basic_istream<charT, traits>()
  1807.   ,basic_ostream<charT, traits>()
  1808.   {
  1809.   }
  1810.   /*
  1811.    * ~basic_iostream()
  1812.    */
  1813.  
  1814.   template<class charT, class traits>
  1815.   basic_iostream<charT, traits>::
  1816.   ~basic_iostream()
  1817.   {
  1818.   }
  1819.  
  1820. #ifndef _RWSTD_NO_NAMESPACE
  1821. }
  1822. #endif
  1823. #pragma option pop
  1824. #endif /* __ISTREAM_CC */
  1825.