123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- #ifndef BOOST_LOG_ATTRIBUTES_FALLBACK_POLICY_HPP_INCLUDED_
- #define BOOST_LOG_ATTRIBUTES_FALLBACK_POLICY_HPP_INCLUDED_
- #include <boost/type_index.hpp>
- #include <boost/type_traits/remove_cv.hpp>
- #include <boost/type_traits/remove_reference.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/exceptions.hpp>
- #include <boost/log/attributes/fallback_policy_fwd.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- struct fallback_to_none
- {
- enum { guaranteed_result = false };
-
- template< typename FunT >
- static bool apply_default(FunT&)
- {
- return false;
- }
-
- template< typename FunT >
- static bool apply_default(FunT const&)
- {
- return false;
- }
-
- static void on_invalid_type(typeindex::type_index const&)
- {
- }
-
- static void on_missing_value()
- {
- }
- };
- struct fallback_to_throw
- {
- enum { guaranteed_result = true };
-
- template< typename FunT >
- static bool apply_default(FunT&)
- {
- return false;
- }
-
- template< typename FunT >
- static bool apply_default(FunT const&)
- {
- return false;
- }
-
- static void on_invalid_type(typeindex::type_index const& t)
- {
- BOOST_LOG_THROW_DESCR_PARAMS(invalid_type, "Attribute value has incompatible type", (t));
- }
-
- static void on_missing_value()
- {
- BOOST_LOG_THROW_DESCR(missing_value, "Attribute value not found");
- }
- };
- template< typename DefaultT >
- struct fallback_to_default
- {
- enum { guaranteed_result = true };
-
- typedef typename remove_cv< typename remove_reference< DefaultT >::type >::type default_type;
-
- fallback_to_default() : m_default()
- {
- }
-
- explicit fallback_to_default(default_type const& def_val) : m_default(def_val)
- {
- }
-
- template< typename FunT >
- bool apply_default(FunT& fun) const
- {
- fun(m_default);
- return true;
- }
-
- template< typename FunT >
- bool apply_default(FunT const& fun) const
- {
- fun(m_default);
- return true;
- }
-
- static void on_invalid_type(typeindex::type_index const&)
- {
- }
-
- static void on_missing_value()
- {
- }
- private:
-
- DefaultT m_default;
- };
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|