_ostreambuf_iterator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers. You should not attempt to use this header
  20. // file directly.
  21. #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
  22. #define _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
  23. #ifndef _STLP_INTERNAL_STREAMBUF
  24. # include <stl/_streambuf.h>
  25. #endif
  26. _STLP_BEGIN_NAMESPACE
  27. _STLP_MOVE_TO_PRIV_NAMESPACE
  28. template<class _CharT, class _Traits>
  29. extern basic_streambuf<_CharT, _Traits>* _STLP_CALL __get_ostreambuf(basic_ostream<_CharT, _Traits>&);
  30. _STLP_MOVE_TO_STD_NAMESPACE
  31. // The default template argument is declared in iosfwd
  32. template <class _CharT, class _Traits>
  33. class ostreambuf_iterator :
  34. public iterator<output_iterator_tag, void, void, void, void> {
  35. public:
  36. typedef _CharT char_type;
  37. typedef _Traits traits_type;
  38. typedef typename _Traits::int_type int_type;
  39. typedef basic_streambuf<_CharT, _Traits> streambuf_type;
  40. typedef basic_ostream<_CharT, _Traits> ostream_type;
  41. typedef output_iterator_tag iterator_category;
  42. typedef void value_type;
  43. typedef void difference_type;
  44. typedef void pointer;
  45. typedef void reference;
  46. public:
  47. ostreambuf_iterator(streambuf_type* __buf) _STLP_NOTHROW : _M_buf(__buf), _M_ok(__buf!=0) {}
  48. // ostreambuf_iterator(ostream_type& __o) _STLP_NOTHROW : _M_buf(__get_ostreambuf(__o)), _M_ok(_M_buf != 0) {}
  49. inline ostreambuf_iterator(ostream_type& __o) _STLP_NOTHROW;
  50. ostreambuf_iterator<_CharT, _Traits>& operator=(char_type __c) {
  51. _M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c),
  52. traits_type::eof());
  53. return *this;
  54. }
  55. ostreambuf_iterator<_CharT, _Traits>& operator*() { return *this; }
  56. ostreambuf_iterator<_CharT, _Traits>& operator++() { return *this; }
  57. ostreambuf_iterator<_CharT, _Traits>& operator++(int) { return *this; }
  58. bool failed() const { return !_M_ok; }
  59. private:
  60. streambuf_type* _M_buf;
  61. bool _M_ok;
  62. };
  63. template <class _CharT, class _Traits>
  64. inline ostreambuf_iterator<_CharT, _Traits>::ostreambuf_iterator(basic_ostream<_CharT, _Traits>& __o) _STLP_NOTHROW
  65. : _M_buf(_STLP_PRIV __get_ostreambuf(__o)), _M_ok(_M_buf != 0) {}
  66. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  67. _STLP_EXPORT_TEMPLATE_CLASS ostreambuf_iterator<char, char_traits<char> >;
  68. # if defined (INSTANTIATE_WIDE_STREAMS)
  69. _STLP_EXPORT_TEMPLATE_CLASS ostreambuf_iterator<wchar_t, char_traits<wchar_t> >;
  70. # endif
  71. #endif /* _STLP_USE_TEMPLATE_EXPORT */
  72. #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
  73. template <class _CharT, class _Traits>
  74. inline output_iterator_tag _STLP_CALL
  75. iterator_category(const ostreambuf_iterator<_CharT, _Traits>&) { return output_iterator_tag(); }
  76. #endif
  77. _STLP_END_NAMESPACE
  78. #endif /* _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H */
  79. // Local Variables:
  80. // mode:C++
  81. // End: