Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:18

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   attribute_cast.hpp
0009  * \author Andrey Semashev
0010  * \date   06.08.2010
0011  *
0012  * The header contains utilities for casting between attribute factories.
0013  */
0014 
0015 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
0017 
0018 #include <boost/log/detail/config.hpp>
0019 #include <boost/log/attributes/attribute.hpp>
0020 #include <boost/log/detail/header.hpp>
0021 
0022 #ifdef BOOST_HAS_PRAGMA_ONCE
0023 #pragma once
0024 #endif
0025 
0026 namespace boost {
0027 
0028 BOOST_LOG_OPEN_NAMESPACE
0029 
0030 namespace attributes {
0031 
0032 /*!
0033  * The class holds a reference to the attribute factory implementation being casted
0034  */
0035 class cast_source
0036 {
0037 private:
0038     attribute::impl* m_pImpl;
0039 
0040 public:
0041     /*!
0042      * Initializing constructor. Creates a source that refers to the specified factory implementation.
0043      */
0044     explicit cast_source(attribute::impl* p) : m_pImpl(p)
0045     {
0046     }
0047 
0048     /*!
0049      * The function attempts to cast the aggregated pointer to the implementation to the specified type.
0050      *
0051      * \return The converted pointer or \c NULL, if the conversion fails.
0052      */
0053     template< typename T >
0054     T* as() const { return dynamic_cast< T* >(m_pImpl); }
0055 };
0056 
0057 } // namespace attributes
0058 
0059 /*!
0060  * The function casts one attribute factory to another
0061  */
0062 template< typename T >
0063 inline T attribute_cast(attribute const& attr)
0064 {
0065     return T(attributes::cast_source(attr.get_impl()));
0066 }
0067 
0068 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0069 
0070 } // namespace boost
0071 
0072 #include <boost/log/detail/footer.hpp>
0073 
0074 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_