File indexing completed on 2025-01-18 09:39:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_
0017
0018 #include <boost/utility/result_of.hpp>
0019 #include <boost/type_traits/is_void.hpp>
0020 #include <boost/type_traits/remove_cv.hpp>
0021 #include <boost/type_traits/remove_reference.hpp>
0022 #include <boost/log/detail/config.hpp>
0023 #include <boost/log/attributes/attribute.hpp>
0024 #include <boost/log/attributes/attribute_cast.hpp>
0025 #include <boost/log/attributes/attribute_value_impl.hpp>
0026 #include <boost/log/detail/header.hpp>
0027
0028 #ifdef BOOST_HAS_PRAGMA_ONCE
0029 #pragma once
0030 #endif
0031
0032 namespace boost {
0033
0034 BOOST_LOG_OPEN_NAMESPACE
0035
0036 namespace attributes {
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 template< typename R >
0048 class function :
0049 public attribute
0050 {
0051 static_assert(!is_void< R >::value, "Boost.Log: Function object return type must not be void");
0052
0053 public:
0054
0055 typedef R value_type;
0056
0057 protected:
0058
0059 class BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE impl :
0060 public attribute::impl
0061 {
0062 };
0063
0064
0065 template< typename T >
0066 class impl_template :
0067 public impl
0068 {
0069 private:
0070
0071
0072
0073
0074
0075 const T m_Functor;
0076
0077 public:
0078
0079
0080
0081 explicit impl_template(T const& fun) : m_Functor(fun) {}
0082
0083 attribute_value get_value()
0084 {
0085 return attributes::make_attribute_value(m_Functor());
0086 }
0087 };
0088
0089 public:
0090
0091
0092
0093 template< typename T >
0094 explicit function(T const& fun) : attribute(new impl_template< T >(fun))
0095 {
0096 }
0097
0098
0099
0100 explicit function(cast_source const& source) :
0101 attribute(source.as< impl >())
0102 {
0103 }
0104 };
0105
0106 #ifndef BOOST_NO_RESULT_OF
0107
0108
0109
0110
0111
0112
0113
0114 template< typename T >
0115 inline function<
0116 typename remove_cv<
0117 typename remove_reference<
0118 typename boost::result_of< T() >::type
0119 >::type
0120 >::type
0121 > make_function(T const& fun)
0122 {
0123 typedef typename remove_cv<
0124 typename remove_reference<
0125 typename boost::result_of< T() >::type
0126 >::type
0127 >::type result_type;
0128
0129 typedef function< result_type > function_type;
0130 return function_type(fun);
0131 }
0132
0133 #endif
0134
0135 #ifndef BOOST_LOG_DOXYGEN_PASS
0136
0137
0138
0139
0140
0141
0142
0143
0144 template< typename R, typename T >
0145 inline function<
0146 typename remove_cv<
0147 typename remove_reference< R >::type
0148 >::type
0149 > make_function(T const& fun)
0150 {
0151 typedef typename remove_cv<
0152 typename remove_reference< R >::type
0153 >::type result_type;
0154
0155 typedef function< result_type > function_type;
0156 return function_type(fun);
0157 }
0158
0159 #endif
0160
0161 }
0162
0163 BOOST_LOG_CLOSE_NAMESPACE
0164
0165 }
0166
0167 #include <boost/log/detail/footer.hpp>
0168
0169 #endif