stream.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2003-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #ifndef BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_HPP_INCLUDED
  8. #include <boost/iostreams/detail/broken_overload_resolution/forward.hpp>
  9. namespace boost { namespace iostreams {
  10. template< typename Device,
  11. typename Tr =
  12. BOOST_IOSTREAMS_CHAR_TRAITS(
  13. BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
  14. ),
  15. typename Alloc =
  16. std::allocator<
  17. BOOST_DEDUCED_TYPENAME char_type_of<Device>::type
  18. > >
  19. struct stream : detail::stream_base<Device, Tr, Alloc> {
  20. public:
  21. typedef typename char_type_of<Device>::type char_type;
  22. struct category
  23. : mode_of<Device>::type,
  24. closable_tag,
  25. detail::stream_traits<Device, Tr>::stream_tag
  26. { };
  27. BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
  28. private:
  29. typedef typename
  30. detail::stream_traits<
  31. Device, Tr
  32. >::stream_type stream_type;
  33. public:
  34. stream() { }
  35. template<typename U0>
  36. stream(const U0& u0)
  37. {
  38. open_impl(detail::forward<Device, U0>(), u0);
  39. }
  40. template<typename U0, typename U1>
  41. stream(const U0& u0, const U1& u1)
  42. {
  43. open_impl(detail::forward<Device, U0>(), u0, u1);
  44. }
  45. template<typename U0, typename U1, typename U2>
  46. stream(const U0& u0, const U1& u1, const U2& u2)
  47. {
  48. open_impl(detail::forward<Device, U0>(), u0, u1, u2);
  49. }
  50. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
  51. template<typename U0>
  52. stream(U0& u0)
  53. {
  54. open_impl(detail::forward<Device, U0>(), u0);
  55. }
  56. template<typename U0, typename U1>
  57. stream(U0& u0, const U1& u1)
  58. {
  59. open_impl(detail::forward<Device, U0>(), u0, u1);
  60. }
  61. template<typename U0, typename U1, typename U2>
  62. stream(U0& u0, const U1& u1, const U2& u2)
  63. {
  64. open_impl(detail::forward<Device, U0>(), u0, u1, u2);
  65. }
  66. #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
  67. template<typename U0>
  68. void open(const U0& u0)
  69. {
  70. open_impl(detail::forward<Device, U0>(), u0);
  71. }
  72. template<typename U0, typename U1>
  73. void open(const U0& u0, const U1& u1)
  74. {
  75. open_impl(detail::forward<Device, U0>(), u0, u1);
  76. }
  77. template<typename U0, typename U1, typename U2>
  78. void open(const U0& u0, const U1& u1, const U2& u2)
  79. {
  80. open_impl(detail::forward<Device, U0>(), u0, u1, u2);
  81. }
  82. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
  83. template<typename U0>
  84. void open(U0& u0)
  85. {
  86. open_impl(detail::forward<Device, U0>(), u0);
  87. }
  88. template<typename U0, typename U1>
  89. void open(U0& u0, const U1& u1)
  90. {
  91. open_impl(detail::forward<Device, U0>(), u0, u1);
  92. }
  93. template<typename U0, typename U1, typename U2>
  94. void open(U0& u0, const U1& u1, const U2& u2)
  95. {
  96. open_impl(detail::forward<Device, U0>(), u0, u1, u2);
  97. }
  98. #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
  99. bool is_open() const { return this->member.is_open(); }
  100. void close() { this->member.close(); }
  101. bool auto_close() const { return this->member.auto_close(); }
  102. void set_auto_close(bool close) { this->member.set_auto_close(close); }
  103. bool strict_sync() { return this->member.strict_sync(); }
  104. Device& operator*() { return *this->member; }
  105. Device* operator->() { return &*this->member; }
  106. private:
  107. template<typename U0>
  108. void open_impl(mpl::false_, const U0& u0)
  109. {
  110. this->clear();
  111. this->member.open(u0);
  112. }
  113. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
  114. template<typename U0>
  115. void open_impl(mpl::false_, U0& u0)
  116. {
  117. this->clear();
  118. this->member.open(detail::wrap(u0));
  119. }
  120. #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
  121. template<typename U0>
  122. void open_impl(mpl::true_, const U0& u0)
  123. {
  124. this->clear();
  125. this->member.open(Device(const_cast<U0&>(u0)));
  126. }
  127. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
  128. template<typename U0>
  129. void open_impl(mpl::true_, U0& u0)
  130. {
  131. this->clear();
  132. this->member.open(Device(u0));
  133. }
  134. #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
  135. template<typename U0, typename U1>
  136. void open_impl(mpl::false_, const U0& u0, const U1& u1)
  137. {
  138. this->clear();
  139. this->member.open(u0, u1);
  140. }
  141. template<typename U0, typename U1>
  142. void open_impl(mpl::true_, const U0& u0, const U1& u1)
  143. {
  144. this->clear();
  145. this->member.open(Device(const_cast<U0&>(u0), u1));
  146. }
  147. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
  148. template<typename U0, typename U1>
  149. void open_impl(mpl::true_, U0& u0, const U1& u1)
  150. {
  151. this->clear();
  152. this->member.open(Device(u0, u1));
  153. }
  154. #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
  155. template<typename U0, typename U1, typename U2>
  156. void open_impl(mpl::false_, const U0& u0, const U1& u1, const U2& u2)
  157. {
  158. this->clear();
  159. this->member.open(u0, u1, u2);
  160. }
  161. template<typename U0, typename U1, typename U2>
  162. void open_impl(mpl::true_, const U0& u0, const U1& u1, const U2& u2)
  163. {
  164. this->clear();
  165. this->member.open(Device(const_cast<U0&>(u0), u1, u2));
  166. }
  167. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
  168. template<typename U0, typename U1, typename U2>
  169. void open_impl(mpl::true_, U0& u0, const U1& u1, const U2& u2)
  170. {
  171. this->clear();
  172. this->member.open(Device(u0, u1, u2));
  173. }
  174. #endif
  175. };
  176. } } // End namespaces iostreams, boost.
  177. #endif BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_HPP_INCLUDED