_ios.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_INTERNAL_IOS_H
  19. #define _STLP_INTERNAL_IOS_H
  20. #ifndef _STLP_IOS_BASE_H
  21. # include <stl/_ios_base.h>
  22. #endif
  23. #ifndef _STLP_INTERNAL_CTYPE_H
  24. # include <stl/_ctype.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_NUMPUNCT_H
  27. # include <stl/_numpunct.h>
  28. #endif
  29. _STLP_BEGIN_NAMESPACE
  30. // ----------------------------------------------------------------------
  31. // Class basic_ios, a subclass of ios_base. The only important difference
  32. // between the two is that basic_ios is a class template, parameterized
  33. // by the character type. ios_base exists to factor out all of the
  34. // common properties that don't depend on the character type.
  35. // The second template parameter, _Traits, defaults to char_traits<_CharT>.
  36. // The default is declared in header <iosfwd>, and it isn't declared here
  37. // because C++ language rules do not allow it to be declared twice.
  38. template <class _CharT, class _Traits>
  39. class basic_ios : public ios_base {
  40. friend class ios_base;
  41. public: // Synonyms for types.
  42. typedef _CharT char_type;
  43. typedef typename _Traits::int_type int_type;
  44. typedef typename _Traits::pos_type pos_type;
  45. typedef typename _Traits::off_type off_type;
  46. typedef _Traits traits_type;
  47. public: // Constructor, destructor.
  48. explicit basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf);
  49. virtual ~basic_ios() {}
  50. public: // Members from clause 27.4.4.2
  51. basic_ostream<_CharT, _Traits>* tie() const {
  52. return _M_tied_ostream;
  53. }
  54. basic_ostream<_CharT, _Traits>*
  55. tie(basic_ostream<char_type, traits_type>* __new_tied_ostream) {
  56. basic_ostream<char_type, traits_type>* __tmp = _M_tied_ostream;
  57. _M_tied_ostream = __new_tied_ostream;
  58. return __tmp;
  59. }
  60. basic_streambuf<_CharT, _Traits>* rdbuf() const
  61. { return _M_streambuf; }
  62. basic_streambuf<_CharT, _Traits>*
  63. rdbuf(basic_streambuf<char_type, traits_type>*);
  64. // Copies __x's state to *this.
  65. basic_ios<_CharT, _Traits>& copyfmt(const basic_ios<_CharT, _Traits>& __x);
  66. char_type fill() const { return _M_fill; }
  67. char_type fill(char_type __fill) {
  68. char_type __tmp(_M_fill);
  69. _M_fill = __fill;
  70. return __tmp;
  71. }
  72. public: // Members from 27.4.4.3. These four functions
  73. // can almost be defined in ios_base.
  74. void clear(iostate __state = goodbit) {
  75. _M_clear_nothrow(this->rdbuf() ? __state : iostate(__state|ios_base::badbit));
  76. _M_check_exception_mask();
  77. }
  78. void setstate(iostate __state) { this->clear(rdstate() | __state); }
  79. iostate exceptions() const { return this->_M_get_exception_mask(); }
  80. void exceptions(iostate __mask) {
  81. this->_M_set_exception_mask(__mask);
  82. this->clear(this->rdstate());
  83. }
  84. public: // Locale-related member functions.
  85. locale imbue(const locale&);
  86. inline char narrow(_CharT, char) const ;
  87. inline _CharT widen(char) const;
  88. // Helper function that makes testing for EOF more convenient.
  89. static bool _STLP_CALL _S_eof(int_type __c) {
  90. const int_type __eof = _Traits::eof();
  91. return _Traits::eq_int_type(__c, __eof);
  92. }
  93. protected:
  94. // Cached copy of the curent locale's ctype facet. Set by init() and imbue().
  95. const ctype<char_type>* _M_cached_ctype;
  96. public:
  97. // Equivalent to &use_facet< Facet >(getloc()), but faster.
  98. const ctype<char_type>* _M_ctype_facet() const { return _M_cached_ctype; }
  99. protected:
  100. basic_ios();
  101. void init(basic_streambuf<_CharT, _Traits>* __streambuf);
  102. public:
  103. // Helper function used in istream and ostream. It is called only from
  104. // a catch clause.
  105. void _M_handle_exception(ios_base::iostate __flag);
  106. private: // Data members
  107. char_type _M_fill; // The fill character, used for padding.
  108. basic_streambuf<_CharT, _Traits>* _M_streambuf;
  109. basic_ostream<_CharT, _Traits>* _M_tied_ostream;
  110. };
  111. template <class _CharT, class _Traits>
  112. inline char
  113. basic_ios<_CharT, _Traits>::narrow(_CharT __c, char __default) const
  114. { return _M_ctype_facet()->narrow(__c, __default); }
  115. template <class _CharT, class _Traits>
  116. inline _CharT
  117. basic_ios<_CharT, _Traits>::widen(char __c) const
  118. { return _M_ctype_facet()->widen(__c); }
  119. # if !defined (_STLP_NO_METHOD_SPECIALIZATION)
  120. _STLP_TEMPLATE_NULL
  121. inline char
  122. basic_ios<char, char_traits<char> >::narrow(char __c, char) const
  123. {
  124. return __c;
  125. }
  126. _STLP_TEMPLATE_NULL
  127. inline char
  128. basic_ios<char, char_traits<char> >::widen(char __c) const
  129. {
  130. return __c;
  131. }
  132. # endif /* _STLP_NO_METHOD_SPECIALIZATION */
  133. # if defined (_STLP_USE_TEMPLATE_EXPORT)
  134. _STLP_EXPORT_TEMPLATE_CLASS basic_ios<char, char_traits<char> >;
  135. # if ! defined (_STLP_NO_WCHAR_T)
  136. _STLP_EXPORT_TEMPLATE_CLASS basic_ios<wchar_t, char_traits<wchar_t> >;
  137. # endif
  138. # endif /* _STLP_USE_TEMPLATE_EXPORT */
  139. _STLP_END_NAMESPACE
  140. #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
  141. # include <stl/_ios.c>
  142. #endif
  143. #endif /* _STLP_IOS */
  144. // Local Variables:
  145. // mode:C++
  146. // End: