_ios.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef _STLP_INTERNAL_IOS_H
  21. # include <stl/_ios.h>
  22. #endif
  23. #ifndef _STLP_INTERNAL_STREAMBUF
  24. # include <stl/_streambuf.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_NUMPUNCT_H
  27. # include <stl/_numpunct.h>
  28. #endif
  29. _STLP_BEGIN_NAMESPACE
  30. // basic_ios<>'s non-inline member functions
  31. // Public constructor, taking a streambuf.
  32. template <class _CharT, class _Traits>
  33. basic_ios<_CharT, _Traits>
  34. ::basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf)
  35. : ios_base(), _M_cached_ctype(0),
  36. _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0) {
  37. basic_ios<_CharT, _Traits>::init(__streambuf);
  38. }
  39. template <class _CharT, class _Traits>
  40. basic_streambuf<_CharT, _Traits>*
  41. basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __buf) {
  42. basic_streambuf<_CharT, _Traits>* __tmp = _M_streambuf;
  43. _M_streambuf = __buf;
  44. this->clear();
  45. return __tmp;
  46. }
  47. template <class _CharT, class _Traits>
  48. basic_ios<_CharT, _Traits>&
  49. basic_ios<_CharT, _Traits>::copyfmt(const basic_ios<_CharT, _Traits>& __x) {
  50. _M_invoke_callbacks(erase_event);
  51. _M_copy_state(__x); // Inherited from ios_base.
  52. _M_cached_ctype = __x._M_cached_ctype;
  53. _M_fill = __x._M_fill;
  54. _M_tied_ostream = __x._M_tied_ostream;
  55. _M_invoke_callbacks(copyfmt_event);
  56. this->_M_set_exception_mask(__x.exceptions());
  57. return *this;
  58. }
  59. template <class _CharT, class _Traits>
  60. locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) {
  61. locale __tmp = ios_base::imbue(__loc);
  62. _STLP_TRY {
  63. if (_M_streambuf)
  64. _M_streambuf->pubimbue(__loc);
  65. // no throwing here
  66. _M_cached_ctype = &use_facet<ctype<char_type> >(__loc);
  67. }
  68. _STLP_CATCH_ALL {
  69. __tmp = ios_base::imbue(__tmp);
  70. _M_handle_exception(ios_base::failbit);
  71. }
  72. return __tmp;
  73. }
  74. // Protected constructor and initialization functions. The default
  75. // constructor creates an uninitialized basic_ios, and init() initializes
  76. // all of the members to the values in Table 89 of the C++ standard.
  77. template <class _CharT, class _Traits>
  78. basic_ios<_CharT, _Traits>::basic_ios()
  79. : ios_base(),
  80. _M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
  81. {}
  82. template <class _CharT, class _Traits>
  83. void
  84. basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
  85. {
  86. this->rdbuf(__sb);
  87. this->imbue(locale());
  88. this->tie(0);
  89. this->_M_set_exception_mask(ios_base::goodbit);
  90. this->_M_clear_nothrow(__sb != 0 ? ios_base::goodbit : ios_base::badbit);
  91. ios_base::flags(ios_base::skipws | ios_base::dec);
  92. ios_base::width(0);
  93. ios_base::precision(6);
  94. this->fill(widen(' '));
  95. // We don't need to worry about any of the three arrays: they are
  96. // initialized correctly in ios_base's constructor.
  97. }
  98. // This is never called except from within a catch clause.
  99. template <class _CharT, class _Traits>
  100. void basic_ios<_CharT, _Traits>::_M_handle_exception(ios_base::iostate __flag)
  101. {
  102. this->_M_setstate_nothrow(__flag);
  103. if (this->_M_get_exception_mask() & __flag)
  104. _STLP_RETHROW;
  105. }
  106. _STLP_END_NAMESPACE
  107. #endif /* _STLP_IOS_C */
  108. // Local Variables:
  109. // mode:C++
  110. // End: