sink_init_helpers.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 sink_init_helpers.hpp
  9. * \author Andrey Semashev
  10. * \date 14.03.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_SINK_INIT_HELPERS_HPP_INCLUDED_
  16. #define BOOST_LOG_DETAIL_SINK_INIT_HELPERS_HPP_INCLUDED_
  17. #include <string>
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/parameter/binding.hpp>
  20. #include <boost/type_traits/is_void.hpp>
  21. #include <boost/type_traits/is_array.hpp>
  22. #include <boost/core/enable_if.hpp>
  23. #include <boost/utility/string_view_fwd.hpp>
  24. #include <boost/log/detail/config.hpp>
  25. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  26. #include <string_view>
  27. #endif
  28. #include <boost/log/core/core.hpp>
  29. #include <boost/log/expressions/filter.hpp>
  30. #include <boost/log/expressions/formatter.hpp>
  31. #include <boost/log/utility/setup/filter_parser.hpp>
  32. #include <boost/log/utility/setup/formatter_parser.hpp>
  33. #include <boost/log/keywords/filter.hpp>
  34. #include <boost/log/keywords/format.hpp>
  35. #include <boost/log/detail/is_character_type.hpp>
  36. #include <boost/log/detail/header.hpp>
  37. #ifdef BOOST_HAS_PRAGMA_ONCE
  38. #pragma once
  39. #endif
  40. namespace boost {
  41. BOOST_LOG_OPEN_NAMESPACE
  42. namespace aux {
  43. // The function creates a filter functional object from the provided argument
  44. template< typename CharT >
  45. inline typename boost::enable_if_c<
  46. log::aux::is_character_type< CharT >::value,
  47. filter
  48. >::type acquire_filter(const CharT* filter)
  49. {
  50. return boost::log::parse_filter(filter);
  51. }
  52. template< typename CharT, typename TraitsT, typename AllocatorT >
  53. inline filter acquire_filter(std::basic_string< CharT, TraitsT, AllocatorT > const& filter)
  54. {
  55. return boost::log::parse_filter(filter);
  56. }
  57. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  58. template< typename CharT, typename TraitsT >
  59. inline filter acquire_filter(std::basic_string_view< CharT, TraitsT > const& filter)
  60. {
  61. const CharT* p = filter.data();
  62. return boost::log::parse_filter(p, p + filter.size());
  63. }
  64. #endif // !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  65. template< typename CharT, typename TraitsT >
  66. inline filter acquire_filter(boost::basic_string_view< CharT, TraitsT > const& filter)
  67. {
  68. const CharT* p = filter.data();
  69. return boost::log::parse_filter(p, p + filter.size());
  70. }
  71. template< typename FilterT >
  72. inline typename boost::disable_if_c<
  73. boost::is_array< FilterT >::value,
  74. FilterT const&
  75. >::type acquire_filter(FilterT const& filter)
  76. {
  77. return filter;
  78. }
  79. // The function installs filter into the sink, if provided in the arguments pack
  80. template< typename SinkT, typename ArgsT >
  81. inline void setup_filter(SinkT&, ArgsT const&, mpl::true_)
  82. {
  83. }
  84. template< typename SinkT, typename ArgsT >
  85. inline void setup_filter(SinkT& s, ArgsT const& args, mpl::false_)
  86. {
  87. s.set_filter(aux::acquire_filter(args[keywords::filter]));
  88. }
  89. // The function creates a formatter functional object from the provided argument
  90. template< typename CharT >
  91. inline typename boost::enable_if_c<
  92. log::aux::is_character_type< CharT >::value,
  93. basic_formatter< CharT >
  94. >::type acquire_formatter(const CharT* formatter)
  95. {
  96. return boost::log::parse_formatter(formatter);
  97. }
  98. template< typename CharT, typename TraitsT, typename AllocatorT >
  99. inline basic_formatter< CharT > acquire_formatter(std::basic_string< CharT, TraitsT, AllocatorT > const& formatter)
  100. {
  101. return boost::log::parse_formatter(formatter);
  102. }
  103. #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  104. template< typename CharT, typename TraitsT >
  105. inline basic_formatter< CharT > acquire_formatter(std::basic_string_view< CharT, TraitsT > const& formatter)
  106. {
  107. const CharT* p = formatter.data();
  108. return boost::log::parse_formatter(p, p + formatter.size());
  109. }
  110. #endif // !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
  111. template< typename CharT, typename TraitsT >
  112. inline basic_formatter< CharT > acquire_formatter(boost::basic_string_view< CharT, TraitsT > const& formatter)
  113. {
  114. const CharT* p = formatter.data();
  115. return boost::log::parse_formatter(p, p + formatter.size());
  116. }
  117. template< typename FormatterT >
  118. inline typename boost::disable_if_c<
  119. boost::is_array< FormatterT >::value,
  120. FormatterT const&
  121. >::type acquire_formatter(FormatterT const& formatter)
  122. {
  123. return formatter;
  124. }
  125. // The function installs filter into the sink, if provided in the arguments pack
  126. template< typename SinkT, typename ArgsT >
  127. inline void setup_formatter(SinkT&, ArgsT const&, mpl::true_)
  128. {
  129. }
  130. template< typename SinkT, typename ArgsT >
  131. inline void setup_formatter(SinkT& s, ArgsT const& args, mpl::false_)
  132. {
  133. s.set_formatter(aux::acquire_formatter(args[keywords::format]));
  134. }
  135. } // namespace aux
  136. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  137. } // namespace boost
  138. #include <boost/log/detail/footer.hpp>
  139. #endif // BOOST_LOG_DETAIL_SINK_INIT_HELPERS_HPP_INCLUDED_