forward.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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)
  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. #define BOOST_IOSTREAMS_FORWARDING_CTOR(z, n, tuple) \
  60. template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \
  61. BOOST_PP_TUPLE_ELEM(3, 0, tuple) \
  62. (BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \
  63. BOOST_IOSTREAMS_DISABLE_IF_SAME(U0, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  64. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  65. ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
  66. (BOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \
  67. template< typename U100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  68. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), typename U) > \
  69. BOOST_PP_TUPLE_ELEM(3, 0, tuple) \
  70. ( U100& u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  71. BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_DEC(n), const U, &u) \
  72. BOOST_IOSTREAMS_DISABLE_IF_SAME(U100, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  73. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  74. ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
  75. ( u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  76. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), u)) ); } \
  77. /**/
  78. #define BOOST_IOSTREAMS_FORWARDING_FN(z, n, tuple) \
  79. template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename U)> \
  80. void open(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, const U, &u) \
  81. BOOST_IOSTREAMS_DISABLE_IF_SAME(U0, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  82. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  83. ( BOOST_PP_TUPLE_ELEM(3, 2, tuple) \
  84. (BOOST_PP_ENUM_PARAMS_Z(z, n, u)) ); } \
  85. template< typename U100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  86. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), typename U) > \
  87. void open \
  88. ( U100& u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  89. BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_DEC(n), const U, &u) \
  90. BOOST_IOSTREAMS_DISABLE_IF_SAME(U100, BOOST_PP_TUPLE_ELEM(3, 2, tuple))) \
  91. { this->BOOST_PP_TUPLE_ELEM(3, 1, tuple) \
  92. ( u100 BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
  93. BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), u) ); } \
  94. /**/
  95. // Disable forwarding constructors if first parameter type is the same
  96. // as the device type
  97. #if !defined(BOOST_NO_SFINAE) && \
  98. !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x592))
  99. # define BOOST_IOSTREAMS_DISABLE_IF_SAME(device, param) \
  100. , typename boost::disable_if< boost::is_same<device, param> >::type* = 0 \
  101. /**/
  102. #else
  103. # define BOOST_IOSTREAMS_DISABLE_IF_SAME(device, param)
  104. #endif
  105. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_FORWARD_HPP_INCLUDED