home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _ios.c < prev    next >
C/C++ Source or Header  |  2002-02-02  |  4KB  |  128 lines

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Copyright (c) 1999 
  6.  * Boris Fomitchev
  7.  *
  8.  * This material is provided "as is", with absolutely no warranty expressed
  9.  * or implied. Any use is at your own risk.
  10.  *
  11.  * Permission to use or copy this software for any purpose is hereby granted 
  12.  * without fee, provided the above notices are retained on all copies.
  13.  * Permission to modify the code and to distribute modified code is granted,
  14.  * provided the above notices are retained, and a notice that the code was
  15.  * modified is included with the above copyright notice.
  16.  *
  17.  */ 
  18. #ifndef _STLP_IOS_C
  19. #define _STLP_IOS_C
  20.  
  21. #ifndef _STLP_INTERNAL_IOS_H
  22. # include <stl/_ios.h>
  23. #endif
  24.  
  25. #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
  26.  
  27. #ifndef _STLP_INTERNAL_STREAMBUF
  28. # include <stl/_streambuf.h>
  29. #endif
  30.  
  31. #ifndef _STLP_INTERNAL_NUMPUNCT_H
  32. # include <stl/_numpunct.h>
  33. #endif
  34.  
  35. _STLP_BEGIN_NAMESPACE
  36.  
  37. // basic_ios<>'s non-inline member functions
  38.  
  39. // Public constructor, taking a streambuf.
  40. template <class _CharT, class _Traits>
  41. basic_ios<_CharT, _Traits>
  42.   ::basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf)
  43.     : ios_base(),
  44.       _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
  45. {
  46.   init(__streambuf);
  47. }
  48.  
  49. template <class _CharT, class _Traits>
  50. basic_streambuf<_CharT, _Traits>*
  51. basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __buf)
  52. {
  53.   basic_streambuf<_CharT, _Traits>* __tmp = _M_streambuf;
  54.   _M_streambuf = __buf;
  55.   this->clear();
  56.   return __tmp;
  57. }
  58.  
  59. template <class _CharT, class _Traits>
  60. basic_ios<_CharT, _Traits>&
  61. basic_ios<_CharT, _Traits>::copyfmt(const basic_ios<_CharT, _Traits>& __x)
  62. {
  63.   _M_invoke_callbacks(erase_event);
  64.   _M_copy_state(__x);           // Inherited from ios_base.
  65.   _M_fill = __x._M_fill;
  66.   _M_tied_ostream = __x._M_tied_ostream;
  67.   _M_invoke_callbacks(copyfmt_event);
  68.   this->_M_set_exception_mask(__x.exceptions());
  69.   return *this;
  70. }
  71.  
  72. template <class _CharT, class _Traits>
  73. locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
  74. {
  75.   locale __tmp = ios_base::imbue(__loc);
  76.  
  77.   if (_M_streambuf)
  78.     _M_streambuf->pubimbue(__loc);
  79.  
  80.   // no throwing here
  81.   this->_M_cached_ctype = __loc._M_get_facet(ctype<char_type>::id) ;
  82.   this->_M_cached_numpunct = __loc._M_get_facet(numpunct<char_type>::id) ;
  83.   this->_M_cached_grouping = ((numpunct<char_type>*)_M_cached_numpunct)->grouping() ;
  84.   return __tmp;
  85. }
  86.  
  87. // Protected constructor and initialization functions. The default
  88. // constructor creates an uninitialized basic_ios, and init() initializes
  89. // all of the members to the values in Table 89 of the C++ standard.
  90.  
  91. template <class _CharT, class _Traits>
  92. basic_ios<_CharT, _Traits>::basic_ios()
  93.   : ios_base(),
  94.     _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
  95. {}
  96.  
  97. template <class _CharT, class _Traits>
  98. void
  99. basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
  100. {
  101.   this->rdbuf(__sb);
  102.   this->imbue(locale());
  103.   this->tie(0);
  104.   this->_M_set_exception_mask(ios_base::goodbit);
  105.   this->_M_clear_nothrow(__sb != 0 ? ios_base::goodbit : ios_base::badbit);
  106.   ios_base::flags(ios_base::skipws | ios_base::dec);
  107.   ios_base::width(0);
  108.   ios_base::precision(6);
  109.   this->fill(widen(' '));
  110.   // We don't need to worry about any of the three arrays: they are
  111.   // initialized correctly in ios_base's constructor.
  112. }
  113.  
  114. // This is never called except from within a catch clause.
  115. template <class _CharT, class _Traits>
  116. void basic_ios<_CharT, _Traits>::_M_handle_exception(ios_base::iostate __flag)
  117. {
  118.   this->_M_setstate_nothrow(__flag);
  119.   if (this->_M_get_exception_mask() & __flag)
  120.     _STLP_RETHROW;
  121. }
  122.  
  123. _STLP_END_NAMESPACE
  124.  
  125. #endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
  126.  
  127. #endif /* _STLP_IOS_C */
  128.