push.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_PUSH_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED
  8. #if defined(_MSC_VER)
  9. # pragma once
  10. #endif
  11. #include <boost/config.hpp> // BOOST_MSVC.
  12. #include <boost/detail/workaround.hpp>
  13. #include <boost/iostreams/categories.hpp>
  14. #include <boost/iostreams/categories.hpp>
  15. #include <boost/iostreams/detail/adapter/range_adapter.hpp>
  16. #include <boost/iostreams/detail/config/wide_streams.hpp>
  17. #include <boost/iostreams/detail/enable_if_stream.hpp>
  18. #include <boost/iostreams/pipeline.hpp>
  19. #include <boost/iostreams/detail/push_params.hpp>
  20. #include <boost/iostreams/detail/resolve.hpp>
  21. #include <boost/mpl/bool.hpp>
  22. #include <boost/preprocessor/cat.hpp>
  23. #include <boost/preprocessor/control/iif.hpp>
  24. #include <boost/static_assert.hpp>
  25. #include <boost/type_traits/is_convertible.hpp>
  26. //
  27. // Macro: BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name, mode, ch, helper).
  28. // Description: Defines overloads with name 'name' which forward to a function
  29. // 'helper' which takes a filter or devide by const reference.
  30. //
  31. #define BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name, mode, ch, helper) \
  32. BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 0, ?) \
  33. /**/
  34. //
  35. // Macro: BOOST_IOSTREAMS_DEFINE_PUSH(name, mode, ch, helper).
  36. // Description: Defines constructors which forward to a function
  37. // 'helper' which takes a filter or device by const reference.
  38. //
  39. #define BOOST_IOSTREAMS_DEFINE_PUSH(name, mode, ch, helper) \
  40. BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, 1, void) \
  41. /**/
  42. //--------------------Definition of BOOST_IOSTREAMS_DEFINE_PUSH_IMPL----------//
  43. #define BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, arg, helper, has_return) \
  44. this->helper( ::boost::iostreams::detail::resolve<mode, ch>(arg) \
  45. BOOST_IOSTREAMS_PUSH_ARGS() ); \
  46. /**/
  47. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) \
  48. /**/
  49. # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES
  50. # define BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \
  51. template<typename CharType, typename TraitsType> \
  52. BOOST_PP_IIF(has_return, result, explicit) \
  53. name(::std::basic_streambuf<CharType, TraitsType>& sb BOOST_IOSTREAMS_PUSH_PARAMS()) \
  54. { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, sb, helper, has_return); } \
  55. template<typename CharType, typename TraitsType> \
  56. BOOST_PP_IIF(has_return, result, explicit) \
  57. name(::std::basic_istream<CharType, TraitsType>& is BOOST_IOSTREAMS_PUSH_PARAMS()) \
  58. { BOOST_STATIC_ASSERT((!is_convertible<mode, output>::value)); \
  59. BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, is, helper, has_return); } \
  60. template<typename CharType, typename TraitsType> \
  61. BOOST_PP_IIF(has_return, result, explicit) \
  62. name(::std::basic_ostream<CharType, TraitsType>& os BOOST_IOSTREAMS_PUSH_PARAMS()) \
  63. { BOOST_STATIC_ASSERT((!is_convertible<mode, input>::value)); \
  64. BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, os, helper, has_return); } \
  65. template<typename CharType, typename TraitsType> \
  66. BOOST_PP_IIF(has_return, result, explicit) \
  67. name(::std::basic_iostream<CharType, TraitsType>& io BOOST_IOSTREAMS_PUSH_PARAMS()) \
  68. { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, io, helper, has_return); } \
  69. template<typename Iter> \
  70. BOOST_PP_IIF(has_return, result, explicit) \
  71. name(const iterator_range<Iter>& rng BOOST_IOSTREAMS_PUSH_PARAMS()) \
  72. { BOOST_PP_EXPR_IF(has_return, return) \
  73. this->helper( ::boost::iostreams::detail::range_adapter< \
  74. mode, iterator_range<Iter> \
  75. >(rng) \
  76. BOOST_IOSTREAMS_PUSH_ARGS() ); } \
  77. template<typename Pipeline, typename Concept> \
  78. BOOST_PP_IIF(has_return, result, explicit) \
  79. name(const ::boost::iostreams::pipeline<Pipeline, Concept>& p) \
  80. { p.push(*this); } \
  81. template<typename T> \
  82. BOOST_PP_IIF(has_return, result, explicit) \
  83. name(const T& t BOOST_IOSTREAMS_PUSH_PARAMS() BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) \
  84. { this->helper( ::boost::iostreams::detail::resolve<mode, ch>(t) \
  85. BOOST_IOSTREAMS_PUSH_ARGS() ); } \
  86. /**/
  87. # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES
  88. # define BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \
  89. BOOST_PP_IF(has_return, result, explicit) \
  90. name(::std::streambuf& sb BOOST_IOSTREAMS_PUSH_PARAMS()) \
  91. { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, sb, helper, has_return); } \
  92. BOOST_PP_IF(has_return, result, explicit) \
  93. name(::std::istream& is BOOST_IOSTREAMS_PUSH_PARAMS()) \
  94. { BOOST_STATIC_ASSERT((!is_convertible<mode, output>::value)); \
  95. BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, is, helper, has_return); } \
  96. BOOST_PP_IF(has_return, result, explicit) \
  97. name(::std::ostream& os BOOST_IOSTREAMS_PUSH_PARAMS()) \
  98. { BOOST_STATIC_ASSERT((!is_convertible<mode, input>::value)); \
  99. BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, os, helper, has_return); } \
  100. BOOST_PP_IF(has_return, result, explicit) \
  101. name(::std::iostream& io BOOST_IOSTREAMS_PUSH_PARAMS()) \
  102. { BOOST_IOSTREAMS_ADAPT_STREAM(mode, ch, io, helper, has_return); } \
  103. template<typename Iter> \
  104. BOOST_PP_IF(has_return, result, explicit) \
  105. name(const iterator_range<Iter>& rng BOOST_IOSTREAMS_PUSH_PARAMS()) \
  106. { BOOST_PP_EXPR_IF(has_return, return) \
  107. this->helper( ::boost::iostreams::detail::range_adapter< \
  108. mode, iterator_range<Iter> \
  109. >(rng) \
  110. BOOST_IOSTREAMS_PUSH_ARGS() ); } \
  111. template<typename Pipeline, typename Concept> \
  112. BOOST_PP_IF(has_return, result, explicit) \
  113. name(const ::boost::iostreams::pipeline<Pipeline, Concept>& p) \
  114. { p.push(*this); } \
  115. template<typename T> \
  116. BOOST_PP_EXPR_IF(has_return, result) \
  117. name(const T& t BOOST_IOSTREAMS_PUSH_PARAMS() BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)) \
  118. { this->helper( ::boost::iostreams::detail::resolve<mode, ch>(t) \
  119. BOOST_IOSTREAMS_PUSH_ARGS() ); } \
  120. /**/
  121. # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES
  122. #else // #if VC6, VC7.0, Borland 5.x
  123. # define BOOST_IOSTREAMS_DEFINE_PUSH_IMPL(name, mode, ch, helper, has_return, result) \
  124. template<typename T> \
  125. void BOOST_PP_CAT(name, _msvc_impl) \
  126. ( ::boost::mpl::true_, const T& t BOOST_IOSTREAMS_PUSH_PARAMS() ) \
  127. { t.push(*this); } \
  128. template<typename T> \
  129. void BOOST_PP_CAT(name, _msvc_impl) \
  130. ( ::boost::mpl::false_, const T& t BOOST_IOSTREAMS_PUSH_PARAMS() ) \
  131. { this->helper( ::boost::iostreams::detail::resolve<mode, ch>(t) \
  132. BOOST_IOSTREAMS_PUSH_ARGS() ); } \
  133. template<typename T> \
  134. BOOST_PP_IF(has_return, result, explicit) \
  135. name(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \
  136. { \
  137. this->BOOST_PP_CAT(name, _msvc_impl) \
  138. ( ::boost::iostreams::detail::is_pipeline<T>(), \
  139. t BOOST_IOSTREAMS_PUSH_ARGS() ); \
  140. } \
  141. /**/
  142. #endif // #if VC6, VC7.0, Borland 5.x
  143. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_PUSH_HPP_INCLUDED