parameter_tools.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2013.
  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/parameter/keyword.hpp>
  18. #include <boost/preprocessor/repetition/enum_params.hpp>
  19. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  20. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  21. #include <boost/preprocessor/facilities/intercept.hpp>
  22. #include <boost/preprocessor/arithmetic/dec.hpp>
  23. #include <boost/preprocessor/tuple/elem.hpp>
  24. #include <boost/log/detail/config.hpp>
  25. #include <boost/log/detail/header.hpp>
  26. #ifdef BOOST_HAS_PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29. #ifndef BOOST_LOG_MAX_PARAMETER_ARGS
  30. //! The maximum number of named arguments that are accepted by constructors and functions
  31. #define BOOST_LOG_MAX_PARAMETER_ARGS 16
  32. #endif
  33. // The macro applies the passed macro with the specified arguments BOOST_LOG_MAX_PARAMETER_ARGS times
  34. #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(macro, args)\
  35. public:\
  36. BOOST_PP_REPEAT_FROM_TO(1, BOOST_LOG_MAX_PARAMETER_ARGS, macro, args)
  37. #define BOOST_LOG_CTOR_FORWARD(z, n, types)\
  38. template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
  39. explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg)) :\
  40. BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))) {}
  41. // The macro expands to a number of templated constructors that aggregate their named arguments
  42. // into an ArgumentsPack and pass it to the base class constructor.
  43. #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_FORWARD(class_type, base_type)\
  44. BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_CTOR_FORWARD, (class_type, base_type))
  45. #define BOOST_LOG_CTOR_CALL(z, n, types)\
  46. template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
  47. explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg))\
  48. { BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))); }
  49. // The macro expands to a number of templated constructors that aggregate their named arguments
  50. // into an ArgumentsPack and pass it to a function call.
  51. #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(class_type, fun)\
  52. BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_CTOR_CALL, (class_type, fun))
  53. namespace boost {
  54. BOOST_LOG_OPEN_NAMESPACE
  55. namespace aux {
  56. // Yeah, not too cute. The empty_arg_list class should really be public.
  57. typedef boost::parameter::aux::empty_arg_list empty_arg_list;
  58. #if !(defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_LOG_NO_CXX11_ARG_PACKS_TO_NON_VARIADIC_ARGS_EXPANSION))
  59. //! The metafunction generates argument pack
  60. template< typename ArgT0, typename... ArgsT >
  61. struct make_arg_list
  62. {
  63. typedef boost::parameter::aux::arg_list< ArgT0, typename make_arg_list< ArgsT... >::type > type;
  64. };
  65. template< typename ArgT0 >
  66. struct make_arg_list< ArgT0 >
  67. {
  68. typedef boost::parameter::aux::arg_list< ArgT0 > type;
  69. };
  70. #else
  71. //! The metafunction generates argument pack
  72. template< typename ArgT0, BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), typename T, = void BOOST_PP_INTERCEPT) >
  73. struct make_arg_list
  74. {
  75. 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;
  76. };
  77. template< typename ArgT0 >
  78. struct make_arg_list< ArgT0, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), void BOOST_PP_INTERCEPT) >
  79. {
  80. typedef boost::parameter::aux::arg_list< ArgT0 > type;
  81. };
  82. #endif
  83. } // namespace aux
  84. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  85. } // namespace boost
  86. #include <boost/log/detail/footer.hpp>
  87. #endif // BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_