value_ref_visitation.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 value_ref_visitation.hpp
  9. * \author Andrey Semashev
  10. * \date 28.07.2012
  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. In this file
  14. * internal configuration macros are defined.
  15. */
  16. #ifndef BOOST_LOG_DETAIL_VALUE_REF_VISITATION_HPP_INCLUDED_
  17. #define BOOST_LOG_DETAIL_VALUE_REF_VISITATION_HPP_INCLUDED_
  18. #include <boost/mpl/at.hpp>
  19. #include <boost/mpl/begin.hpp>
  20. #include <boost/mpl/end.hpp>
  21. #include <boost/mpl/advance.hpp>
  22. #include <boost/mpl/erase.hpp>
  23. #include <boost/mpl/size.hpp>
  24. #include <boost/preprocessor/arithmetic/inc.hpp>
  25. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  26. #include <boost/preprocessor/iteration/iterate.hpp>
  27. #include <boost/log/detail/config.hpp>
  28. #include <boost/log/detail/header.hpp>
  29. #ifndef BOOST_LOG_VALUE_REF_VISITATION_UNROLL_COUNT
  30. #define BOOST_LOG_VALUE_REF_VISITATION_UNROLL_COUNT 8
  31. #endif
  32. namespace boost {
  33. BOOST_LOG_OPEN_NAMESPACE
  34. namespace aux {
  35. template< typename SequenceT, typename VisitorT, unsigned int SizeV = mpl::size< SequenceT >::value >
  36. struct apply_visitor_dispatch
  37. {
  38. typedef typename VisitorT::result_type result_type;
  39. static BOOST_FORCEINLINE result_type call(const void* p, unsigned int type_index, VisitorT& visitor)
  40. {
  41. typedef typename mpl::begin< SequenceT >::type begin_type;
  42. typedef typename mpl::advance_c< begin_type, SizeV / 2u >::type middle_type;
  43. if (type_index < (SizeV / 2u))
  44. {
  45. typedef typename mpl::erase< SequenceT, middle_type, typename mpl::end< SequenceT >::type >::type new_sequence;
  46. typedef apply_visitor_dispatch< new_sequence, VisitorT > new_dispatch;
  47. return new_dispatch::call(p, type_index, visitor);
  48. }
  49. else
  50. {
  51. typedef typename mpl::erase< SequenceT, begin_type, middle_type >::type new_sequence;
  52. typedef apply_visitor_dispatch< new_sequence, VisitorT > new_dispatch;
  53. return new_dispatch::call(p, type_index - (SizeV / 2u), visitor);
  54. }
  55. }
  56. };
  57. #define BOOST_LOG_AUX_CASE_ENTRY(z, i, data)\
  58. case i: return visitor(*static_cast< typename mpl::at_c< SequenceT, i >::type const* >(p));
  59. #define BOOST_PP_FILENAME_1 <boost/log/detail/value_ref_visitation.hpp>
  60. #define BOOST_PP_ITERATION_LIMITS (1, BOOST_PP_INC(BOOST_LOG_VALUE_REF_VISITATION_VTABLE_SIZE))
  61. #include BOOST_PP_ITERATE()
  62. #undef BOOST_LOG_AUX_CASE_ENTRY
  63. } // namespace aux
  64. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  65. } // namespace boost
  66. #include <boost/log/detail/footer.hpp>
  67. #endif // BOOST_LOG_DETAIL_VALUE_REF_VISITATION_HPP_INCLUDED_
  68. #ifdef BOOST_PP_IS_ITERATING
  69. #define BOOST_LOG_AUX_SWITCH_SIZE BOOST_PP_ITERATION()
  70. template< typename SequenceT, typename VisitorT >
  71. struct apply_visitor_dispatch< SequenceT, VisitorT, BOOST_LOG_AUX_SWITCH_SIZE >
  72. {
  73. typedef typename VisitorT::result_type result_type;
  74. static BOOST_FORCEINLINE result_type call(const void* p, unsigned int type_index, VisitorT& visitor)
  75. {
  76. switch (type_index)
  77. {
  78. BOOST_PP_REPEAT_FROM_TO(1, BOOST_LOG_AUX_SWITCH_SIZE, BOOST_LOG_AUX_CASE_ENTRY, ~)
  79. default:
  80. return visitor(*static_cast< typename mpl::at_c< SequenceT, 0 >::type const* >(p));
  81. }
  82. }
  83. };
  84. #undef BOOST_LOG_AUX_SWITCH_SIZE
  85. #endif // BOOST_PP_IS_ITERATING