forward.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_FORWARD_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED
  8. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  9. # pragma once
  10. #endif
  11. #include <boost/config.hpp> // BOOST_MSVC, BOOST_NO_SFINAE
  12. #include <boost/detail/workaround.hpp>
  13. #include <boost/iostreams/detail/config/limits.hpp>
  14. #include <boost/iostreams/detail/push_params.hpp>
  15. #include <boost/preprocessor/arithmetic/dec.hpp>
  16. #include <boost/preprocessor/arithmetic/inc.hpp>
  17. #include <boost/preprocessor/punctuation/comma_if.hpp>
  18. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  19. #include <boost/preprocessor/repetition/enum_params.hpp>
  20. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  21. #include <boost/preprocessor/tuple/elem.hpp>
  22. #include <boost/type_traits/is_same.hpp>
  23. //------Macros for defining forwarding constructors and open overloads--------//
  24. //
  25. // Macro: BOOST_IOSTREAMS_FORWARD(class, impl, device, params, args)
  26. // Description: Defines constructors and overloads of 'open' which construct
  27. // a device using the specified argument list and pass it to the specified
  28. // helper function
  29. // class - The class name
  30. // impl - The helper function
  31. // device - The device type
  32. // params - The list of formal parameters trailing the device parameter in
  33. // the helper function's signature
  34. // params - The list of arguments passed to the helper function, following the
  35. // device argument
  36. //
  37. #define BOOST_IOSTREAMS_FORWARD(class, impl, device, params, args) \
  38. class(const device& t params()) \
  39. { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
  40. class(device& t params()) \
  41. { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
  42. class(const ::boost::reference_wrapper<device>& ref params()) \
  43. { this->impl(ref args()); } \
  44. void open(const device& t params()) \
  45. { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
  46. void open(device& t params()) \
  47. { this->impl(::boost::iostreams::detail::wrap(t) args()); } \
  48. void open(const ::boost::reference_wrapper<device>& ref params()) \
  49. { this->impl(ref args()); } \
  50. BOOST_PP_REPEAT_FROM_TO( \
  51. 1, BOOST_PP_INC(BOOST_IOSTREAMS_MAX_FORWARDING_ARITY), \
  52. BOOST_IOSTREAMS_FORWARDING_CTOR, (class, impl, device) \
  53. ) \
  54. BOOST_PP_REPEAT_FROM_TO( \
  55. 1, BOOST_PP_INC(BOOST_IOSTREAMS_MAX_FORWARDING_ARITY), \
  56. BOOST_IOSTREAMS_FORWARDING_FN, (class, impl, device) \
  57. ) \
  58. /**/
  59. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  60. # define BOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) \
  61. template< typename U100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  62. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), typename U) > \
  63. BOOST_PP_TUPLE_ELEM(3, 0, tuple) \
  64. ( U100& u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  65. BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_DEC(n), const U, &u) \
  66. BOOST_IOSTREAMS_DISABLE_IF_SAME(U100, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  67. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  68. ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
  69. ( u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  70. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), u)) ); } \
  71. /**/
  72. # define BOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) \
  73. template< typename U100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  74. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), typename U) > \
  75. void open \
  76. ( U100& u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  77. BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_DEC(n), const U, &u) \
  78. BOOST_IOSTREAMS_DISABLE_IF_SAME(U100, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  79. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  80. ( u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  81. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), u) ); } \
  82. /**/
  83. #else
  84. # define BOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple)
  85. # define BOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple)
  86. #endif
  87. #define BOOST_IOSTREAMS_FORWARDING_CTOR(z, n, tuple) \
  88. template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \
  89. BOOST_PP_TUPLE_ELEM(3, 0, tuple) \
  90. (BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \
  91. BOOST_IOSTREAMS_DISABLE_IF_SAME(U0, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  92. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  93. ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
  94. (BOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \
  95. BOOST_IOSTREAMS_FORWARDING_CTOR_I(z, n, tuple) \
  96. /**/
  97. #define BOOST_IOSTREAMS_FORWARDING_FN(z, n, tuple) \
  98. template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \
  99. void open(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \
  100. BOOST_IOSTREAMS_DISABLE_IF_SAME(U0, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  101. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  102. ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
  103. (BOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \
  104. BOOST_IOSTREAMS_FORWARDING_FN_I(z, n, tuple) \
  105. /**/
  106. // Disable forwarding constructors if first parameter type is the same
  107. // as the device type
  108. #if !defined(BOOST_NO_SFINAE) && \
  109. !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
  110. # define BOOST_IOSTREAMS_DISABLE_IF_SAME(device, param) \
  111. , typename boost::disable_if< boost::is_same<device, param> >::type* = 0 \
  112. /**/
  113. #else
  114. # define BOOST_IOSTREAMS_DISABLE_IF_SAME(device, param)
  115. #endif
  116. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED