parameter_tools.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file parameter_tools.hpp
  9. * \author Andrey Semashev
  10. * \date 28.06.2009
  11. *
  12. * \brief This header is the Boost.Log library implementation, see the library documentation
  13. * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
  14. */
  15. #ifndef BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_
  16. #define BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_
  17. #include <boost/mpl/or.hpp>
  18. #include <boost/core/enable_if.hpp>
  19. #include <boost/parameter/keyword.hpp>
  20. #include <boost/type_traits/is_base_of.hpp>
  21. #include <boost/preprocessor/control/if.hpp>
  22. #include <boost/preprocessor/comparison/equal.hpp>
  23. #include <boost/preprocessor/repetition/enum_params.hpp>
  24. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  25. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  26. #include <boost/preprocessor/facilities/intercept.hpp>
  27. #include <boost/preprocessor/arithmetic/dec.hpp>
  28. #include <boost/preprocessor/tuple/elem.hpp>
  29. #include <boost/log/detail/config.hpp>
  30. #include <boost/log/detail/sfinae_tools.hpp>
  31. #include <boost/log/detail/header.hpp>
  32. #ifdef BOOST_HAS_PRAGMA_ONCE
  33. #pragma once
  34. #endif
  35. #ifndef BOOST_LOG_MAX_PARAMETER_ARGS
  36. //! The maximum number of named arguments that are accepted by constructors and functions
  37. #define BOOST_LOG_MAX_PARAMETER_ARGS 16
  38. #endif
  39. // The macro applies the passed macro with the specified arguments BOOST_LOG_MAX_PARAMETER_ARGS times
  40. #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(macro, args)\
  41. public:\
  42. BOOST_PP_REPEAT_FROM_TO(1, BOOST_LOG_MAX_PARAMETER_ARGS, macro, args)
  43. #define BOOST_LOG_CTOR_FORWARD_1(n, types)\
  44. template< typename T0 >\
  45. explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) :\
  46. BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))) {}
  47. #define BOOST_LOG_CTOR_FORWARD_N(n, types)\
  48. template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
  49. explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg)) :\
  50. BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))) {}
  51. #define BOOST_LOG_CTOR_FORWARD(z, n, types)\
  52. BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_CTOR_FORWARD_1, BOOST_LOG_CTOR_FORWARD_N)(n, types)
  53. // The macro expands to a number of templated constructors that aggregate their named arguments
  54. // into an ArgumentsPack and pass it to the base class constructor.
  55. #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_FORWARD(class_type, base_type)\
  56. BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_CTOR_FORWARD, (class_type, base_type))
  57. #define BOOST_LOG_CTOR_CALL_1(n, types)\
  58. template< typename T0 >\
  59. explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy())\
  60. { BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))); }
  61. #define BOOST_LOG_CTOR_CALL_N(n, types)\
  62. template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
  63. explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg))\
  64. { BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))); }
  65. #define BOOST_LOG_CTOR_CALL(z, n, types)\
  66. BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_CTOR_CALL_1, BOOST_LOG_CTOR_CALL_N)(n, types)
  67. // The macro expands to a number of templated constructors that aggregate their named arguments
  68. // into an ArgumentsPack and pass it to a function call.
  69. #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(class_type, fun)\
  70. BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_CTOR_CALL, (class_type, fun))
  71. namespace boost {
  72. BOOST_LOG_OPEN_NAMESPACE
  73. namespace aux {
  74. // Yeah, not too cute. The empty_arg_list class should really be public.
  75. // https://svn.boost.org/trac/boost/ticket/7247
  76. typedef boost::parameter::aux::empty_arg_list empty_arg_list;
  77. #if !(defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_LOG_NO_CXX11_ARG_PACKS_TO_NON_VARIADIC_ARGS_EXPANSION))
  78. //! The metafunction generates argument pack
  79. template< typename ArgT0, typename... ArgsT >
  80. struct make_arg_list
  81. {
  82. typedef boost::parameter::aux::arg_list< ArgT0, typename make_arg_list< ArgsT... >::type > type;
  83. };
  84. template< typename ArgT0 >
  85. struct make_arg_list< ArgT0 >
  86. {
  87. typedef boost::parameter::aux::arg_list< ArgT0 > type;
  88. };
  89. #else
  90. //! The metafunction generates argument pack
  91. template< typename ArgT0, BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), typename T, = void BOOST_PP_INTERCEPT) >
  92. struct make_arg_list
  93. {
  94. typedef boost::parameter::aux::arg_list< ArgT0, typename make_arg_list< BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), T) >::type > type;
  95. };
  96. template< typename ArgT0 >
  97. struct make_arg_list< ArgT0, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), void BOOST_PP_INTERCEPT) >
  98. {
  99. typedef boost::parameter::aux::arg_list< ArgT0 > type;
  100. };
  101. #endif
  102. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  103. template< typename T, typename R >
  104. using enable_if_named_parameters = boost::enable_if_c< boost::mpl::or_< boost::is_base_of< boost::parameter::aux::tagged_argument_base, T >, boost::is_base_of< empty_arg_list, T > >::value, R >;
  105. #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  106. template< typename T, typename R >
  107. struct enable_if_named_parameters :
  108. public boost::enable_if_c< boost::mpl::or_< boost::is_base_of< boost::parameter::aux::tagged_argument_base, T >, boost::is_base_of< empty_arg_list, T > >::value, R >
  109. {
  110. };
  111. #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  112. } // namespace aux
  113. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  114. } // namespace boost
  115. #include <boost/log/detail/footer.hpp>
  116. #endif // BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_