sink_init_helpers.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 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/utility/enable_if.hpp>
  22. #include <boost/phoenix/core/is_actor.hpp>
  23. #include <boost/log/detail/config.hpp>
  24. #include <boost/log/core/core.hpp>
  25. #include <boost/log/expressions/filter.hpp>
  26. #include <boost/log/expressions/formatter.hpp>
  27. #include <boost/log/utility/setup/filter_parser.hpp>
  28. #include <boost/log/utility/setup/formatter_parser.hpp>
  29. #include <boost/log/keywords/filter.hpp>
  30. #include <boost/log/keywords/format.hpp>
  31. #include <boost/log/detail/header.hpp>
  32. #ifdef BOOST_HAS_PRAGMA_ONCE
  33. #pragma once
  34. #endif
  35. namespace boost {
  36. BOOST_LOG_OPEN_NAMESPACE
  37. namespace aux {
  38. // The function creates a filter functional object from the provided argument
  39. template< typename CharT >
  40. inline filter acquire_filter(const CharT* filter)
  41. {
  42. return boost::log::parse_filter(filter);
  43. }
  44. template< typename CharT, typename TraitsT, typename AllocatorT >
  45. inline filter acquire_filter(std::basic_string< CharT, TraitsT, AllocatorT > const& filter)
  46. {
  47. return boost::log::parse_filter(filter);
  48. }
  49. template< typename FilterT >
  50. inline typename enable_if<
  51. phoenix::is_actor< FilterT >,
  52. FilterT const&
  53. >::type acquire_filter(FilterT const& filter)
  54. {
  55. return filter;
  56. }
  57. // The function installs filter into the sink, if provided in the arguments pack
  58. template< typename SinkT, typename ArgsT >
  59. inline void setup_filter(SinkT&, ArgsT const&, mpl::true_)
  60. {
  61. }
  62. template< typename SinkT, typename ArgsT >
  63. inline void setup_filter(SinkT& s, ArgsT const& args, mpl::false_)
  64. {
  65. s.set_filter(aux::acquire_filter(args[keywords::filter]));
  66. }
  67. // The function creates a filter functional object from the provided argument
  68. template< typename CharT >
  69. inline basic_formatter< CharT > acquire_formatter(const CharT* formatter)
  70. {
  71. return boost::log::parse_formatter(formatter);
  72. }
  73. template< typename CharT, typename TraitsT, typename AllocatorT >
  74. inline basic_formatter< CharT > acquire_formatter(std::basic_string< CharT, TraitsT, AllocatorT > const& formatter)
  75. {
  76. return boost::log::parse_formatter(formatter);
  77. }
  78. template< typename FormatterT >
  79. inline typename enable_if<
  80. phoenix::is_actor< FormatterT >,
  81. FormatterT const&
  82. >::type acquire_formatter(FormatterT const& formatter)
  83. {
  84. return formatter;
  85. }
  86. // The function installs filter into the sink, if provided in the arguments pack
  87. template< typename SinkT, typename ArgsT >
  88. inline void setup_formatter(SinkT&, ArgsT const&, mpl::true_)
  89. {
  90. }
  91. template< typename SinkT, typename ArgsT >
  92. inline void setup_formatter(SinkT& s, ArgsT const& args, mpl::false_)
  93. {
  94. s.set_formatter(aux::acquire_formatter(args[keywords::format]));
  95. }
  96. } // namespace aux
  97. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  98. } // namespace boost
  99. #include <boost/log/detail/footer.hpp>
  100. #endif // BOOST_LOG_DETAIL_SINK_INIT_HELPERS_HPP_INCLUDED_