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_cast.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 06.08.2010 Chris@16: * Chris@16: * The header contains utilities for casting between attribute factories. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include 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: * The class holds a reference to the attribute factory implementation being casted Chris@16: */ Chris@16: class cast_source Chris@16: { Chris@16: private: Chris@16: attribute::impl* m_pImpl; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Initializing constructor. Creates a source that refers to the specified factory implementation. Chris@16: */ Chris@16: explicit cast_source(attribute::impl* p) : m_pImpl(p) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function attempts to cast the aggregated pointer to the implementation to the specified type. Chris@16: * Chris@16: * \return The converted pointer or \c NULL, if the conversion fails. Chris@16: */ Chris@16: template< typename T > Chris@16: T* as() const { return dynamic_cast< T* >(m_pImpl); } Chris@16: }; Chris@16: Chris@16: } // namespace attributes Chris@16: Chris@16: /*! Chris@16: * The function casts one attribute factory to another Chris@16: */ Chris@16: template< typename T > Chris@16: inline T attribute_cast(attribute const& attr) Chris@16: { Chris@16: return T(attributes::cast_source(attr.get_impl())); Chris@16: } 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_CAST_HPP_INCLUDED_