123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_
- #define BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_
- #include <boost/static_assert.hpp>
- #include <boost/utility/result_of.hpp>
- #include <boost/type_traits/is_void.hpp>
- #include <boost/type_traits/remove_cv.hpp>
- #include <boost/type_traits/remove_reference.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/attributes/attribute.hpp>
- #include <boost/log/attributes/attribute_cast.hpp>
- #include <boost/log/attributes/attribute_value_impl.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace attributes {
- template< typename R >
- class function :
- public attribute
- {
- BOOST_STATIC_ASSERT_MSG(!is_void< R >::value, "Boost.Log: Function object return type must not be void");
- public:
-
- typedef R value_type;
- protected:
-
- class BOOST_LOG_NO_VTABLE BOOST_SYMBOL_VISIBLE impl :
- public attribute::impl
- {
- };
-
- template< typename T >
- class impl_template :
- public impl
- {
- private:
-
-
- const T m_Functor;
- public:
-
- explicit impl_template(T const& fun) : m_Functor(fun) {}
- attribute_value get_value()
- {
- return attributes::make_attribute_value(m_Functor());
- }
- };
- public:
-
- template< typename T >
- explicit function(T const& fun) : attribute(new impl_template< T >(fun))
- {
- }
-
- explicit function(cast_source const& source) :
- attribute(source.as< impl >())
- {
- }
- };
- #ifndef BOOST_NO_RESULT_OF
- template< typename T >
- inline function<
- typename remove_cv<
- typename remove_reference<
- typename boost::result_of< T() >::type
- >::type
- >::type
- > make_function(T const& fun)
- {
- typedef typename remove_cv<
- typename remove_reference<
- typename boost::result_of< T() >::type
- >::type
- >::type result_type;
- typedef function< result_type > function_type;
- return function_type(fun);
- }
- #endif
- #ifndef BOOST_LOG_DOXYGEN_PASS
- template< typename R, typename T >
- inline function<
- typename remove_cv<
- typename remove_reference< R >::type
- >::type
- > make_function(T const& fun)
- {
- typedef typename remove_cv<
- typename remove_reference< R >::type
- >::type result_type;
- typedef function< result_type > function_type;
- return function_type(fun);
- }
- #endif
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|