123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- #ifndef BOOST_LOG_ATTRIBUTES_MUTABLE_CONSTANT_HPP_INCLUDED_
- #define BOOST_LOG_ATTRIBUTES_MUTABLE_CONSTANT_HPP_INCLUDED_
- #include <boost/smart_ptr/intrusive_ptr.hpp>
- #include <boost/move/core.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/type_traits/is_void.hpp>
- #include <boost/type_traits/conditional.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/detail/locks.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 {
- #ifdef BOOST_LOG_DOXYGEN_PASS
- template< typename T, typename MutexT = void, typename ScopedWriteLockT = auto, typename ScopedReadLockT = auto >
- #else
- template<
- typename T,
- typename MutexT = void,
- typename ScopedWriteLockT =
- #ifndef BOOST_LOG_NO_THREADS
- typename boost::conditional<
- boost::log::aux::is_exclusively_lockable< MutexT >::value,
- boost::log::aux::exclusive_lock_guard< MutexT >,
- void
- >::type,
- #else
- void,
- #endif
- typename ScopedReadLockT =
- #ifndef BOOST_LOG_NO_THREADS
- typename boost::conditional<
- boost::log::aux::is_shared_lockable< MutexT >::value,
- boost::log::aux::shared_lock_guard< MutexT >,
- ScopedWriteLockT
- >::type
- #else
- ScopedWriteLockT
- #endif
- #endif
- >
- class mutable_constant :
- public attribute
- {
- public:
-
- typedef T value_type;
- protected:
-
- class BOOST_SYMBOL_VISIBLE impl :
- public attribute::impl
- {
- private:
-
- typedef MutexT mutex_type;
-
- typedef ScopedReadLockT scoped_read_lock;
-
- typedef ScopedWriteLockT scoped_write_lock;
- static_assert(!(is_void< mutex_type >::value || is_void< scoped_read_lock >::value || is_void< scoped_write_lock >::value), "Boost.Log: Mutex and both lock types either must not be void or must all be void");
-
- typedef attribute_value_impl< value_type > attr_value;
- private:
-
- mutable mutex_type m_Mutex;
-
- intrusive_ptr< attr_value > m_Value;
- public:
-
- explicit impl(value_type const& value) : m_Value(new attr_value(value))
- {
- }
-
- explicit impl(BOOST_RV_REF(value_type) value) : m_Value(new attr_value(boost::move(value)))
- {
- }
- attribute_value get_value()
- {
- scoped_read_lock lock(m_Mutex);
- return attribute_value(m_Value);
- }
- void set(value_type const& value)
- {
- intrusive_ptr< attr_value > p = new attr_value(value);
- scoped_write_lock lock(m_Mutex);
- m_Value.swap(p);
- }
- void set(BOOST_RV_REF(value_type) value)
- {
- intrusive_ptr< attr_value > p = new attr_value(boost::move(value));
- scoped_write_lock lock(m_Mutex);
- m_Value.swap(p);
- }
- value_type get() const
- {
- scoped_read_lock lock(m_Mutex);
- return m_Value->get();
- }
- };
- public:
-
- explicit mutable_constant(value_type const& value) : attribute(new impl(value))
- {
- }
-
- explicit mutable_constant(BOOST_RV_REF(value_type) value) : attribute(new impl(boost::move(value)))
- {
- }
-
- explicit mutable_constant(cast_source const& source) : attribute(source.as< impl >())
- {
- }
-
- void set(value_type const& value)
- {
- get_impl()->set(value);
- }
-
- void set(BOOST_RV_REF(value_type) value)
- {
- get_impl()->set(boost::move(value));
- }
-
- value_type get() const
- {
- return get_impl()->get();
- }
- protected:
-
- impl* get_impl() const
- {
- return static_cast< impl* >(attribute::get_impl());
- }
- };
- template< typename T >
- class mutable_constant< T, void, void, void > :
- public attribute
- {
- public:
-
- typedef T value_type;
- protected:
-
- class BOOST_SYMBOL_VISIBLE impl :
- public attribute::impl
- {
- private:
-
- typedef attribute_value_impl< value_type > attr_value;
- private:
-
- intrusive_ptr< attr_value > m_Value;
- public:
-
- explicit impl(value_type const& value) : m_Value(new attr_value(value))
- {
- }
-
- explicit impl(BOOST_RV_REF(value_type) value) : m_Value(new attr_value(boost::move(value)))
- {
- }
- attribute_value get_value()
- {
- return attribute_value(m_Value);
- }
- void set(value_type const& value)
- {
- m_Value = new attr_value(value);
- }
- void set(BOOST_RV_REF(value_type) value)
- {
- m_Value = new attr_value(boost::move(value));
- }
- value_type get() const
- {
- return m_Value->get();
- }
- };
- public:
-
- explicit mutable_constant(value_type const& value) : attribute(new impl(value))
- {
- }
-
- explicit mutable_constant(BOOST_RV_REF(value_type) value) : attribute(new impl(boost::move(value)))
- {
- }
-
- explicit mutable_constant(cast_source const& source) : attribute(source.as< impl >())
- {
- }
-
- void set(value_type const& value)
- {
- get_impl()->set(value);
- }
-
- void set(BOOST_RV_REF(value_type) value)
- {
- get_impl()->set(boost::move(value));
- }
-
- value_type get() const
- {
- return get_impl()->get();
- }
- protected:
-
- impl* get_impl() const
- {
- return static_cast< impl* >(attribute::get_impl());
- }
- };
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|