Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file attribute_value_impl.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 24.06.2007 Chris@16: * Chris@16: * The header contains an implementation of a basic attribute value implementation class. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@16: #include Chris@16: #endif Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace attributes { Chris@16: Chris@16: /*! Chris@16: * \brief Basic attribute value implementation class Chris@16: * Chris@16: * This class can be used as a boilerplate for simple attribute values. The class implements all needed Chris@16: * interfaces of attribute values and allows to store a single value of the type specified as a template parameter. Chris@16: * The stored value can be dispatched with type dispatching mechanism. Chris@16: */ Chris@16: template< typename T > Chris@16: class attribute_value_impl : Chris@16: public attribute_value::impl Chris@16: { Chris@16: public: Chris@16: //! Value type Chris@16: typedef T value_type; Chris@16: Chris@16: private: Chris@16: //! Attribute value Chris@16: const value_type m_value; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Constructor with initialization of the stored value Chris@16: */ Chris@16: explicit attribute_value_impl(value_type const& v) : m_value(v) {} Chris@16: /*! Chris@16: * Constructor with initialization of the stored value Chris@16: */ Chris@16: explicit attribute_value_impl(BOOST_RV_REF(value_type) v) : m_value(v) {} Chris@16: Chris@16: /*! Chris@16: * Attribute value dispatching method. Chris@16: * Chris@16: * \param dispatcher The dispatcher that receives the stored value Chris@16: * Chris@16: * \return \c true if the value has been dispatched, \c false otherwise Chris@16: */ Chris@16: virtual bool dispatch(type_dispatcher& dispatcher) Chris@16: { Chris@16: type_dispatcher::callback< value_type > callback = dispatcher.get_callback< value_type >(); Chris@16: if (callback) Chris@16: { Chris@16: callback(m_value); Chris@16: return true; Chris@16: } Chris@16: else Chris@16: return false; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * \return The attribute value type Chris@16: */ Chris@16: type_info_wrapper get_type() const { return type_info_wrapper(typeid(value_type)); } Chris@16: Chris@16: /*! Chris@16: * \return Reference to the contained value. Chris@16: */ Chris@16: value_type const& get() const { return m_value; } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The function creates an attribute value from the specified object. Chris@16: */ Chris@16: #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@16: Chris@16: template< typename T > Chris@16: inline attribute_value make_attribute_value(T&& v) Chris@16: { Chris@16: typedef typename remove_cv< typename remove_reference< T >::type >::type value_type; Chris@16: return attribute_value(new attribute_value_impl< value_type >(boost::forward< T >(v))); Chris@16: } Chris@16: Chris@16: #else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@16: Chris@16: template< typename T > Chris@16: inline attribute_value make_attribute_value(T const& v) Chris@16: { Chris@16: typedef typename remove_cv< T >::type value_type; Chris@16: return attribute_value(new attribute_value_impl< value_type >(v)); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline attribute_value make_attribute_value(rv< T > const& v) Chris@16: { Chris@16: typedef typename remove_cv< T >::type value_type; Chris@16: return attribute_value(new attribute_value_impl< value_type >(v)); Chris@16: } Chris@16: Chris@16: #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@16: Chris@16: } // namespace attributes Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_