williamr@4: /*
williamr@4:  * Copyright (c) 1999
williamr@4:  * Silicon Graphics Computer Systems, Inc.
williamr@4:  *
williamr@4:  * Copyright (c) 1999
williamr@4:  * Boris Fomitchev
williamr@4:  *
williamr@4:  * This material is provided "as is", with absolutely no warranty expressed
williamr@4:  * or implied. Any use is at your own risk.
williamr@4:  *
williamr@4:  * Permission to use or copy this software for any purpose is hereby granted
williamr@4:  * without fee, provided the above notices are retained on all copies.
williamr@4:  * Permission to modify the code and to distribute modified code is granted,
williamr@4:  * provided the above notices are retained, and a notice that the code was
williamr@4:  * modified is included with the above copyright notice.
williamr@4:  *
williamr@4:  */
williamr@4: #ifndef _STLP_INTERNAL_IOS_H
williamr@4: #define _STLP_INTERNAL_IOS_H
williamr@4: 
williamr@4: 
williamr@4: #ifndef _STLP_IOS_BASE_H
williamr@4: # include <stl/_ios_base.h>
williamr@4: #endif
williamr@4: 
williamr@4: #ifndef _STLP_INTERNAL_CTYPE_H
williamr@4: # include <stl/_ctype.h>
williamr@4: #endif
williamr@4: #ifndef _STLP_INTERNAL_NUMPUNCT_H
williamr@4: # include <stl/_numpunct.h>
williamr@4: #endif
williamr@4: 
williamr@4: _STLP_BEGIN_NAMESPACE
williamr@4: 
williamr@4: // ----------------------------------------------------------------------
williamr@4: 
williamr@4: // Class basic_ios, a subclass of ios_base.  The only important difference
williamr@4: // between the two is that basic_ios is a class template, parameterized
williamr@4: // by the character type.  ios_base exists to factor out all of the
williamr@4: // common properties that don't depend on the character type.
williamr@4: 
williamr@4: // The second template parameter, _Traits, defaults to char_traits<_CharT>.
williamr@4: // The default is declared in header <iosfwd>, and it isn't declared here
williamr@4: // because C++ language rules do not allow it to be declared twice.
williamr@4: 
williamr@4: template <class _CharT, class _Traits>
williamr@4: class basic_ios : public ios_base {
williamr@4:   friend class ios_base;
williamr@4: public:                         // Synonyms for types.
williamr@4:   typedef _CharT                     char_type;
williamr@4:   typedef typename _Traits::int_type int_type;
williamr@4:   typedef typename _Traits::pos_type pos_type;
williamr@4:   typedef typename _Traits::off_type off_type;
williamr@4:   typedef _Traits                    traits_type;
williamr@4: 
williamr@4: public:                         // Constructor, destructor.
williamr@4:   explicit basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf);
williamr@4:   virtual ~basic_ios() {}
williamr@4: 
williamr@4: public:                         // Members from clause 27.4.4.2
williamr@4:   basic_ostream<_CharT, _Traits>* tie() const {
williamr@4:     return _M_tied_ostream;
williamr@4:   }
williamr@4:   basic_ostream<_CharT, _Traits>*
williamr@4:   tie(basic_ostream<char_type, traits_type>* __new_tied_ostream) {
williamr@4:     basic_ostream<char_type, traits_type>* __tmp = _M_tied_ostream;
williamr@4:     _M_tied_ostream = __new_tied_ostream;
williamr@4:     return __tmp;
williamr@4:   }
williamr@4: 
williamr@4:   basic_streambuf<_CharT, _Traits>* rdbuf() const
williamr@4:     { return _M_streambuf; }
williamr@4: 
williamr@4:   basic_streambuf<_CharT, _Traits>*
williamr@4:   rdbuf(basic_streambuf<char_type, traits_type>*);
williamr@4: 
williamr@4:   // Copies __x's state to *this.
williamr@4:   basic_ios<_CharT, _Traits>& copyfmt(const basic_ios<_CharT, _Traits>& __x);
williamr@4: 
williamr@4:   char_type fill() const { return _M_fill; }
williamr@4:   char_type fill(char_type __fill) {
williamr@4:     char_type __tmp(_M_fill);
williamr@4:     _M_fill = __fill;
williamr@4:     return __tmp;
williamr@4:   }
williamr@4: 
williamr@4: public:                         // Members from 27.4.4.3.  These four functions
williamr@4:                                 // can almost be defined in ios_base.
williamr@4: 
williamr@4:   void clear(iostate __state = goodbit) {
williamr@4:     _M_clear_nothrow(this->rdbuf() ? __state : iostate(__state|ios_base::badbit));
williamr@4:     _M_check_exception_mask();
williamr@4:   }
williamr@4:   void setstate(iostate __state) { this->clear(rdstate() | __state); }
williamr@4: 
williamr@4:   iostate exceptions() const { return this->_M_get_exception_mask(); }
williamr@4:   void exceptions(iostate __mask) {
williamr@4:     this->_M_set_exception_mask(__mask);
williamr@4:     this->clear(this->rdstate());
williamr@4:   }
williamr@4: 
williamr@4: public:                         // Locale-related member functions.
williamr@4:   locale imbue(const locale&);
williamr@4: 
williamr@4:   inline char narrow(_CharT, char) const ;
williamr@4:   inline _CharT widen(char) const;
williamr@4: 
williamr@4:   // Helper function that makes testing for EOF more convenient.
williamr@4:   static bool _STLP_CALL _S_eof(int_type __c) {
williamr@4:     const int_type __eof = _Traits::eof();
williamr@4:     return _Traits::eq_int_type(__c, __eof);
williamr@4:   }
williamr@4: 
williamr@4: protected:
williamr@4:   basic_ios();
williamr@4: 
williamr@4:   void init(basic_streambuf<_CharT, _Traits>* __streambuf);
williamr@4: 
williamr@4: public:
williamr@4: 
williamr@4:   // Helper function used in istream and ostream.  It is called only from
williamr@4:   // a catch clause.
williamr@4:   void _M_handle_exception(ios_base::iostate __flag);
williamr@4: 
williamr@4: private:                        // Data members
williamr@4:   char_type _M_fill;            // The fill character, used for padding.
williamr@4: 
williamr@4:   basic_streambuf<_CharT, _Traits>* _M_streambuf;
williamr@4:   basic_ostream<_CharT, _Traits>*   _M_tied_ostream;
williamr@4: 
williamr@4: };
williamr@4: 
williamr@4: 
williamr@4: template <class _CharT, class _Traits>
williamr@4: inline char
williamr@4: basic_ios<_CharT, _Traits>::narrow(_CharT __c, char __default) const
williamr@4: { return __STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())->narrow(__c, __default); }
williamr@4: 
williamr@4: template <class _CharT, class _Traits>
williamr@4: inline _CharT
williamr@4: basic_ios<_CharT, _Traits>::widen(char __c) const
williamr@4: { return __STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())->widen(__c); }
williamr@4: 
williamr@4: # if !defined (_STLP_NO_METHOD_SPECIALIZATION)
williamr@4: _STLP_TEMPLATE_NULL
williamr@4: inline char
williamr@4: basic_ios<char, char_traits<char> >::narrow(char __c, char) const
williamr@4: {
williamr@4:   return __c;
williamr@4: }
williamr@4: 
williamr@4: _STLP_TEMPLATE_NULL
williamr@4: inline char
williamr@4: basic_ios<char, char_traits<char> >::widen(char __c) const
williamr@4: {
williamr@4:   return __c;
williamr@4: }
williamr@4: # endif /* _STLP_NO_METHOD_SPECIALIZATION */
williamr@4: 
williamr@4: # if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4: _STLP_EXPORT_TEMPLATE_CLASS basic_ios<char, char_traits<char> >;
williamr@4: #  if ! defined (_STLP_NO_WCHAR_T)
williamr@4: _STLP_EXPORT_TEMPLATE_CLASS basic_ios<wchar_t, char_traits<wchar_t> >;
williamr@4: #  endif
williamr@4: # endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@4: 
williamr@4: _STLP_END_NAMESPACE
williamr@4: 
williamr@4: #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4: #  include <stl/_ios.c>
williamr@4: #endif
williamr@4: 
williamr@4: #endif /* _STLP_IOS */
williamr@4: 
williamr@4: // Local Variables:
williamr@4: // mode:C++
williamr@4: // End:
williamr@4: