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

  1. #ifndef __IOS_H
  2. #define __IOS_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __STD_IOS__
  6. #define __STD_IOS__
  7.  
  8. /***************************************************************************
  9.  *
  10.  * ios - Declarations for the Standard Library basic stream I/O
  11.  *
  12.  ***************************************************************************
  13.  *
  14.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  15.  * ALL RIGHTS RESERVED
  16.  *
  17.  * The software and information contained herein are proprietary to, and
  18.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  19.  * intends to preserve as trade secrets such software and information.
  20.  * This software is furnished pursuant to a written license agreement and
  21.  * may be used, copied, transmitted, and stored only in accordance with
  22.  * the terms of such license and with the inclusion of the above copyright
  23.  * notice.  This software and information or any other copies thereof may
  24.  * not be provided or otherwise made available to any other person.
  25.  *
  26.  * Notwithstanding any other lease or license that may pertain to, or
  27.  * accompany the delivery of, this computer software and information, the
  28.  * rights of the Government regarding its use, reproduction and disclosure
  29.  * are as set forth in Section 52.227-19 of the FARS Computer
  30.  * Software-Restricted Rights clause.
  31.  * 
  32.  * Use, duplication, or disclosure by the Government is subject to
  33.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  34.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  35.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  36.  * P.O. Box 2328, Corvallis, Oregon 97339.
  37.  *
  38.  * This computer software and information is distributed with "restricted
  39.  * rights."  Use, duplication or disclosure is subject to restrictions as
  40.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  41.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  42.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  43.  * then the "Alternate III" clause applies.
  44.  *
  45.  **************************************************************************/
  46.  
  47. #include <stdcomp.h>
  48.  
  49. #include <rw/rwstderr.h>        // error messages
  50. #include <rw/rwlocale>          // locale class
  51. #include <rw/ctype>             // facets
  52. #include <rw/codecvt>           // code coversion facet
  53. #include <rw/numeral>           // numeric facet 
  54. #include <rw/vendor>            // standard xxx_byname facets & vendor-defined extensions
  55. #include <rw/usefacet>          // usefacet and hasfacet
  56. #ifndef _RWSTD_NO_NAMESPACE
  57. namespace __rwstd {
  58. #endif
  59.  
  60. #ifdef _RWSTD_LOCALIZED_ERRORS
  61.   extern const unsigned int _RWSTDExport rwse_failbit_set;
  62.   extern const unsigned int _RWSTDExport rwse_badbit_set;
  63.   extern const unsigned int _RWSTDExport rwse_eofbit_set;
  64. #else
  65.   extern const char _RWSTDExportFunc(*) rwse_failbit_set;
  66.   extern const char _RWSTDExportFunc(*) rwse_badbit_set;
  67.   extern const char _RWSTDExportFunc(*) rwse_eofbit_set;
  68. #endif // _RWSTD_LOCALIZED_ERRORS
  69. #ifndef _RWSTD_NO_NAMESPACE
  70. }
  71. namespace std {
  72. #endif
  73.  
  74.   /*
  75.    *    Class basic_ios
  76.    */
  77.  
  78.   template<class charT, class traits>
  79.   class _RWSTDExportTemplate basic_ios : public ios_base
  80.   { 
  81.  
  82.   public:
  83.     //
  84.     // Types:
  85.     //
  86.     typedef _TYPENAME traits::char_type        char_type;
  87.     typedef _TYPENAME traits::int_type         int_type;
  88.     typedef _TYPENAME traits::pos_type         pos_type;
  89.     typedef _TYPENAME traits::off_type         off_type;
  90.     typedef traits                             traits_type;
  91.       
  92.     typedef basic_ios<charT, traits>           ios_type;
  93.     typedef basic_streambuf<charT, traits>     streambuf_type; 
  94.     typedef basic_ostream<charT, traits>       ostream_type;
  95.  
  96.     inline operator void*() const;
  97.     inline bool operator! () const;
  98.     inline iostate rdstate() const;
  99.     inline void clear(iostate state = goodbit);
  100.     inline void setstate(iostate state);
  101.  
  102.     inline bool good() const;
  103.     inline bool eof()  const;
  104.     inline bool fail() const;
  105.     inline bool bad()  const;
  106.       
  107.     inline iostate exceptions() const;
  108.     inline void exceptions(iostate excpt);
  109.       
  110.     _EXPLICIT basic_ios(basic_streambuf<charT, traits> *sb_arg);
  111.     virtual ~basic_ios();
  112.  
  113.     inline ostream_type *tie() const;
  114.     ostream_type *tie(ostream_type *tie_arg);
  115.  
  116.     inline streambuf_type *rdbuf() const;
  117.     streambuf_type *rdbuf( streambuf_type *sb);
  118.  
  119.     ios_type& copyfmt(const ios_type& rhs);
  120.       
  121.     char_type fill() const
  122.     {
  123.       return __fillch;
  124.     }
  125.     char_type fill(char_type ch)
  126.     {
  127. #ifdef _RWSTD_MULTI_THREAD
  128.       _RWSTDGuard guard(this->__stream_mutex);
  129. #endif
  130.       char_type    temp = __fillch;
  131.       __fillch = ch;
  132.       return temp;
  133.     }
  134.     locale imbue(const locale& loc);
  135.  
  136.     inline char  narrow(charT, char) const;
  137.     inline charT widen(char) const;
  138.  
  139.   protected:
  140.     basic_ios();
  141.     void init(basic_streambuf<charT, traits> *sb);
  142.       
  143.     inline void _RW_UNSAFE_clear(iostate state = goodbit);
  144.  
  145.   private:
  146.     streambuf_type       *__sb;    
  147.     ostream_type         *__tiestr;   
  148.     char_type            __fillch; 
  149.     iostate              __state;   
  150.     iostate              _Except; 
  151.  
  152.   };
  153.  
  154.   /*
  155.    * basic_streambuf *rdbuf() const
  156.    */
  157.  
  158.   template<class charT, class traits>
  159.   inline basic_streambuf<charT, traits> *
  160.   basic_ios<charT, traits>::rdbuf() const
  161.   {
  162.     return __sb;
  163.   }
  164.  
  165.   /*
  166.    * basic_ostream *tie() const
  167.    */
  168.  
  169.   template<class charT, class traits>
  170.   inline basic_ostream<charT, traits> *
  171.   basic_ios<charT, traits>::tie() const
  172.   {
  173.     return __tiestr;
  174.   }
  175.  
  176.   /*
  177.    * void exceptions(iostate)
  178.    */
  179.  
  180.   template<class charT, class traits>
  181.   inline void 
  182.   basic_ios<charT, traits>::exceptions(ios_base::iostate st)
  183.   {
  184. #ifdef _RWSTD_MULTI_THREAD
  185.     _RWSTDGuard guard(this->__stream_mutex);
  186. #endif
  187.     _Except = st;
  188.  
  189. #ifdef _RWSTD_MULTI_THREAD
  190.     _RW_UNSAFE_clear(rdstate()); 
  191. #else
  192.     clear(rdstate());
  193. #endif //  _RWSTD_MULTI_THREAD
  194.   }
  195.  
  196.   /*
  197.    * iostate exceptions() const
  198.    */
  199.  
  200.   template<class charT, class traits>
  201.   inline ios_base::iostate 
  202.   basic_ios<charT, traits>::exceptions() const
  203.   { 
  204.     return _Except;
  205.   }
  206.  
  207.   /*
  208.    * void clear(iostate )
  209.    */
  210.  
  211.   template<class charT, class traits>
  212.   inline void 
  213.   basic_ios<charT, traits>::clear(iostate st)
  214.   {
  215. #ifdef _RWSTD_MULTI_THREAD
  216.     _RWSTDGuard guard(this->__stream_mutex);
  217. #endif 
  218.     _RW_UNSAFE_clear(st); 
  219.   }
  220.  
  221.   /*
  222.    * void setstate(iostate)
  223.    */
  224.  
  225.   template<class charT, class traits>
  226.   inline void
  227.   basic_ios<charT, traits>::setstate(iostate st)
  228.   {
  229. #ifdef _RWSTD_MULTI_THREAD
  230.     _RWSTDGuard guard(this->__stream_mutex);
  231. #endif // _RWSTD_MULTI_THREAD
  232.  
  233. #ifdef _RWSTD_MULTI_THREAD
  234.     _RW_UNSAFE_clear(__state | st); 
  235. #else
  236.     clear(__state | st);
  237. #endif // _RWSTD_MULTI_THREAD
  238.   }
  239.  
  240.   /*
  241.    * iostate rdstate() const
  242.    */
  243.  
  244.   template<class charT, class traits>
  245.   inline ios_base::iostate 
  246.   basic_ios<charT, traits>::rdstate() const
  247.   {
  248.     return __state;
  249.   }
  250.  
  251.   /*
  252.    * operator bool() const
  253.    */
  254.  
  255.   template<class charT, class traits>
  256.   inline basic_ios<charT, traits>::operator void*() const
  257.   {
  258.     return fail() ? (void*)0 : (void*)1;
  259.   }
  260.  
  261.   /*
  262.    * bool operator!() const
  263.    */
  264.  
  265.   template<class charT, class traits>
  266.   inline bool 
  267.   basic_ios<charT, traits>::operator!() const
  268.   {
  269.     return fail();
  270.   }
  271.  
  272.   /*
  273.    * bool good() const
  274.    */
  275.  
  276.   template<class charT, class traits>
  277.   inline bool 
  278.   basic_ios<charT, traits>::good() const
  279.   {
  280.     return (__state == ios_base::goodbit);
  281.   }
  282.  
  283.   /*
  284.    * bool eof() const
  285.    */
  286.  
  287.   template<class charT, class traits>
  288.   inline bool 
  289.   basic_ios<charT, traits>::eof() const
  290.   {
  291.     return (__state & ios_base::eofbit);
  292.   }
  293.  
  294.   /*
  295.    * bool fail() const
  296.    */
  297.  
  298.   template<class charT, class traits>
  299.   inline bool 
  300.   basic_ios<charT, traits>::fail() const
  301.   {
  302.     return (__state & (ios_base::failbit | ios_base::badbit));
  303.   }
  304.  
  305.   /*
  306.    * bool bad() const
  307.    */
  308.  
  309.   template<class charT, class traits>
  310.   inline bool 
  311.   basic_ios<charT, traits>::bad() const
  312.   {
  313.     return (__state & ios_base::badbit);
  314.   }
  315.  
  316.   /*
  317.    * void _RW_UNSAFE_clear(iostate )
  318.    */
  319.  
  320.   template<class charT, class traits>
  321.   inline void 
  322.   basic_ios<charT, traits>::_RW_UNSAFE_clear(iostate st)
  323.   {
  324.     if ( !__sb ) 
  325.     {
  326.       st |= ios_base::badbit;
  327.       __state |= ios_base::badbit; 
  328.     }
  329.  
  330.     __state = st;
  331.  
  332.     if( rdstate() & exceptions() )
  333.     {
  334. #ifdef _RW_STD_EXCEPT
  335. #ifndef _RWSTD_NO_EXCEPTIONS
  336.       if ( rdstate() & exceptions() & ios_base::failbit )
  337.       { 
  338.         __state=st;
  339.         throw ios_base::failure( string(__RWSTD::except_msg_string(__RWSTD::rwse_failbit_set).msgstr()) );
  340.       }
  341.  
  342.       if ( rdstate() & exceptions() & ios_base::badbit )
  343.       { 
  344.         __state=st;
  345.         throw ios_base::failure( string(__RWSTD::except_msg_string(__RWSTD::rwse_badbit_set).msgstr()) );
  346.       }
  347.       if ( rdstate() & exceptions() & ios_base::eofbit )
  348.       { 
  349.         __state=st;
  350.         throw ios_base::failure( string(__RWSTD::except_msg_string(__RWSTD::rwse_eofbit_set).msgstr()) );
  351.       }
  352. #endif //  _RWSTD_NO_EXCEPTIONS
  353. #endif //  _RW_STD_EXCEPT
  354.     }
  355.   }
  356.  
  357.   /*
  358.    * char narrow(charT, char) const
  359.    */
  360.  
  361.   template<class charT, class traits>
  362.   inline char 
  363.   basic_ios<charT, traits>::narrow(charT c, char dfault) const
  364.   {
  365. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  366.     return use_facet< ctype<charT> >(getloc()).narrow(c,dfault);
  367. #else
  368.     return use_facet(getloc(),(ctype<charT>*)0).narrow(c,dfault);
  369. #endif
  370.      
  371.   }
  372.  
  373.   /*
  374.    * charT widen(char) const
  375.    */
  376.  
  377.   template<class charT, class traits>
  378.   inline charT 
  379.   basic_ios<charT, traits>::widen(char c) const
  380.   {
  381. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  382.     return use_facet< ctype<charT> >(getloc()).widen(c);
  383. #else
  384.     return use_facet(getloc(),(ctype<charT>*)0).widen(c);
  385. #endif
  386.      
  387.   }
  388.  
  389. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  390.   typedef basic_ios<char>                          ios;
  391. #else
  392.   typedef basic_ios<char, char_traits<char> >      ios;
  393. #endif
  394.  
  395. #ifndef _RWSTD_NO_WIDE_CHAR
  396. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  397.   typedef basic_ios<wchar_t>                         wios;
  398. #else
  399.   typedef basic_ios<wchar_t, char_traits<wchar_t> >  wios;
  400. #endif //  _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  401. #endif //  _RWSTD_NO_WIDE_CHAR
  402.  
  403.   /*
  404.    *     external declarations for manipulators
  405.    */
  406.  
  407. #ifdef _RWSTD_MULTI_THREAD
  408.   template <class charT, class traits>
  409.   basic_ios<charT,traits>& __lock(basic_ios<charT,traits>&);
  410.  
  411.   template <class charT, class traits>
  412.   basic_ios<charT,traits>& __unlock(basic_ios<charT,traits>&);
  413. #endif // _RWSTD_MULTI_THREAD
  414. #ifndef _RWSTD_NO_NAMESPACE
  415. }
  416. #endif
  417.  
  418. #ifdef _RWSTD_COMPILE_INSTANTIATE
  419. #include <ios.cc>
  420. #endif // _RWSTD_COMPILE_INSTANTIATE
  421. #endif // __STD_IOS_
  422. #ifndef __USING_STD_NAMES__
  423.   using namespace std;
  424. #endif
  425. #pragma option pop
  426. #endif /* __IOS_H */
  427.