frontend_requirements.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 sinks/frontend_requirements.hpp
  9. * \author Andrey Semashev
  10. * \date 22.04.2007
  11. *
  12. * The header contains definition of requirement tags that sink backend may declare
  13. * with regard to frontends. These requirements ensure that a backend will not
  14. * be used with an incompatible frontend.
  15. */
  16. #ifndef BOOST_LOG_SINKS_FRONTEND_REQUIREMENTS_HPP_INCLUDED_
  17. #define BOOST_LOG_SINKS_FRONTEND_REQUIREMENTS_HPP_INCLUDED_
  18. #include <boost/mpl/aux_/na.hpp>
  19. #include <boost/mpl/placeholders.hpp>
  20. #include <boost/mpl/inherit.hpp>
  21. #include <boost/mpl/inherit_linearly.hpp>
  22. #include <boost/mpl/vector.hpp>
  23. #include <boost/preprocessor/repetition/enum_params.hpp>
  24. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  25. #include <boost/type_traits/is_base_of.hpp>
  26. #include <boost/log/detail/config.hpp>
  27. #include <boost/log/detail/header.hpp>
  28. #ifdef BOOST_HAS_PRAGMA_ONCE
  29. #pragma once
  30. #endif
  31. #ifndef BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT
  32. //! The macro specifies the maximum number of requirements that can be combined with the \c combine_requirements metafunction
  33. #define BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT 5
  34. #endif
  35. namespace boost {
  36. BOOST_LOG_OPEN_NAMESPACE
  37. namespace sinks {
  38. /*!
  39. * The sink backend expects pre-synchronized calls, all needed synchronization is implemented
  40. * in the frontend (IOW, only one thread is feeding records to the backend concurrently, but
  41. * it is possible for several threads to write sequentially). Note that if a frontend supports
  42. * synchronized record feeding, it will also report capable of concurrent record feeding.
  43. */
  44. struct synchronized_feeding {};
  45. #if !defined(BOOST_LOG_NO_THREADS)
  46. /*!
  47. * The sink backend ensures all needed synchronization, it is capable to handle multithreaded calls
  48. */
  49. struct concurrent_feeding : synchronized_feeding {};
  50. #else // !defined(BOOST_LOG_NO_THREADS)
  51. // If multithreading is disabled, threading models become redundant
  52. typedef synchronized_feeding concurrent_feeding;
  53. #endif // !defined(BOOST_LOG_NO_THREADS)
  54. /*!
  55. * The sink backend requires the frontend to perform log record formatting before feeding
  56. */
  57. struct formatted_records {};
  58. /*!
  59. * The sink backend supports flushing
  60. */
  61. struct flushing {};
  62. #ifdef BOOST_LOG_DOXYGEN_PASS
  63. /*!
  64. * The metafunction combines multiple requirement tags into one type. The resulting type will
  65. * satisfy all specified requirements (i.e. \c has_requirement metafunction will return positive result).
  66. */
  67. template< typename... RequirementsT >
  68. struct combine_requirements;
  69. #else
  70. template< BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT, typename ReqT, mpl::na) >
  71. struct combine_requirements :
  72. mpl::inherit_linearly<
  73. mpl::vector< BOOST_PP_ENUM_PARAMS(BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT, ReqT) >,
  74. mpl::inherit2< mpl::_1, mpl::_2 >
  75. >
  76. {
  77. };
  78. #endif // BOOST_LOG_DOXYGEN_PASS
  79. /*!
  80. * A helper metafunction to check if a requirement is satisfied. The \c TestedT template argument
  81. * should be the type combining one or several requirements and \c RequiredT is the requirement
  82. * to test against. The metafunction will yield a positive result if \c TestedT supports \c RequiredT.
  83. */
  84. template< typename TestedT, typename RequiredT >
  85. struct has_requirement :
  86. public is_base_of< RequiredT, TestedT >
  87. {
  88. };
  89. } // namespace sinks
  90. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  91. } // namespace boost
  92. #include <boost/log/detail/footer.hpp>
  93. #endif // BOOST_LOG_SINKS_FRONTEND_REQUIREMENTS_HPP_INCLUDED_