| 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 | |
| 17 | #ifndef BOOST_LOG_SINKS_FRONTEND_REQUIREMENTS_HPP_INCLUDED_ |
| 18 | #define BOOST_LOG_SINKS_FRONTEND_REQUIREMENTS_HPP_INCLUDED_ |
| 19 | |
| 20 | #include <boost/type_traits/is_base_of.hpp> |
| 21 | #include <boost/log/detail/config.hpp> |
| 22 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) |
| 23 | #include <boost/mpl/aux_/na.hpp> |
| 24 | #include <boost/mpl/placeholders.hpp> |
| 25 | #include <boost/mpl/inherit.hpp> |
| 26 | #include <boost/mpl/inherit_linearly.hpp> |
| 27 | #include <boost/mpl/vector.hpp> |
| 28 | #include <boost/preprocessor/repetition/enum_params.hpp> |
| 29 | #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp> |
| 30 | #endif |
| 31 | #include <boost/log/detail/header.hpp> |
| 32 | |
| 33 | #ifdef BOOST_HAS_PRAGMA_ONCE |
| 34 | #pragma once |
| 35 | #endif |
| 36 | |
| 37 | #ifndef BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT |
| 38 | //! The macro specifies the maximum number of requirements that can be combined with the \c combine_requirements metafunction |
| 39 | #define BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT 5 |
| 40 | #endif |
| 41 | |
| 42 | namespace boost { |
| 43 | |
| 44 | BOOST_LOG_OPEN_NAMESPACE |
| 45 | |
| 46 | namespace sinks { |
| 47 | |
| 48 | /*! |
| 49 | * The sink backend expects pre-synchronized calls, all needed synchronization is implemented |
| 50 | * in the frontend (IOW, only one thread is feeding records to the backend concurrently, but |
| 51 | * it is possible for several threads to write sequentially). Note that if a frontend supports |
| 52 | * synchronized record feeding, it will also report capable of concurrent record feeding. |
| 53 | */ |
| 54 | struct synchronized_feeding {}; |
| 55 | |
| 56 | #if !defined(BOOST_LOG_NO_THREADS) |
| 57 | |
| 58 | /*! |
| 59 | * The sink backend ensures all needed synchronization, it is capable to handle multithreaded calls |
| 60 | */ |
| 61 | struct concurrent_feeding : synchronized_feeding {}; |
| 62 | |
| 63 | #else // !defined(BOOST_LOG_NO_THREADS) |
| 64 | |
| 65 | // If multithreading is disabled, threading models become redundant |
| 66 | typedef synchronized_feeding concurrent_feeding; |
| 67 | |
| 68 | #endif // !defined(BOOST_LOG_NO_THREADS) |
| 69 | |
| 70 | /*! |
| 71 | * The sink backend requires the frontend to perform log record formatting before feeding |
| 72 | */ |
| 73 | struct formatted_records {}; |
| 74 | |
| 75 | /*! |
| 76 | * The sink backend supports flushing |
| 77 | */ |
| 78 | struct flushing {}; |
| 79 | |
| 80 | #if defined(BOOST_LOG_DOXYGEN_PASS) |
| 81 | |
| 82 | /*! |
| 83 | * The metafunction combines multiple requirement tags into one type. The resulting type will |
| 84 | * satisfy all specified requirements (i.e. \c has_requirement metafunction will return positive result). |
| 85 | */ |
| 86 | template< typename... RequirementsT > |
| 87 | struct combine_requirements; |
| 88 | |
| 89 | #elif !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) |
| 90 | |
| 91 | namespace aux { |
| 92 | |
| 93 | template< typename... RequirementsT > |
| 94 | struct combined_requirements : |
| 95 | public RequirementsT... |
| 96 | { |
| 97 | }; |
| 98 | |
| 99 | } // namespace aux |
| 100 | |
| 101 | template< typename... RequirementsT > |
| 102 | struct combine_requirements |
| 103 | { |
| 104 | typedef sinks::aux::combined_requirements< RequirementsT... > type; |
| 105 | }; |
| 106 | |
| 107 | #else |
| 108 | |
| 109 | template< BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT, typename ReqT, mpl::na) > |
| 110 | struct combine_requirements : |
| 111 | mpl::inherit_linearly< |
| 112 | mpl::vector< BOOST_PP_ENUM_PARAMS(BOOST_LOG_COMBINE_REQUIREMENTS_LIMIT, ReqT) >, |
| 113 | mpl::inherit2< mpl::_1, mpl::_2 > |
| 114 | > |
| 115 | { |
| 116 | }; |
| 117 | |
| 118 | #endif // BOOST_LOG_DOXYGEN_PASS |
| 119 | |
| 120 | /*! |
| 121 | * A helper metafunction to check if a requirement is satisfied. The \c TestedT template argument |
| 122 | * should be the type combining one or several requirements and \c RequiredT is the requirement |
| 123 | * to test against. The metafunction will yield a positive result if \c TestedT supports \c RequiredT. |
| 124 | */ |
| 125 | template< typename TestedT, typename RequiredT > |
| 126 | struct has_requirement : |
| 127 | public is_base_of< RequiredT, TestedT > |
| 128 | { |
| 129 | }; |
| 130 | |
| 131 | } // namespace sinks |
| 132 | |
| 133 | BOOST_LOG_CLOSE_NAMESPACE // namespace log |
| 134 | |
| 135 | } // namespace boost |
| 136 | |
| 137 | #include <boost/log/detail/footer.hpp> |
| 138 | |
| 139 | #endif // BOOST_LOG_SINKS_FRONTEND_REQUIREMENTS_HPP_INCLUDED_ |
| 140 | |