2
* Copyright Andrey Semashev 2007 - 2013.
3
* Distributed under the Boost Software License, Version 1.0.
4
* (See accompanying file LICENSE_1_0.txt or copy at
5
* http://www.boost.org/LICENSE_1_0.txt)
8
* \file attribute_cast.hpp
9
* \author Andrey Semashev
12
* The header contains utilities for casting between attribute factories.
15
#ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
16
#define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
18
#include <boost/log/detail/config.hpp>
19
#include <boost/log/attributes/attribute.hpp>
20
#include <boost/log/detail/header.hpp>
22
#ifdef BOOST_LOG_HAS_PRAGMA_ONCE
28
BOOST_LOG_OPEN_NAMESPACE
30
namespace attributes {
33
* The class holds a reference to the attribute factory implementation being casted
38
attribute::impl* m_pImpl;
42
* Initializing constructor. Creates a source that refers to the specified factory implementation.
44
explicit cast_source(attribute::impl* p) : m_pImpl(p)
49
* The function attempts to cast the aggregated pointer to the implementation to the specified type.
51
* \return The converted pointer or \c NULL, if the conversion fails.
53
template< typename T >
54
T* as() const { return dynamic_cast< T* >(m_pImpl); }
57
} // namespace attributes
60
* The function casts one attribute factory to another
62
template< typename T >
63
inline T attribute_cast(attribute const& attr)
65
return T(attributes::cast_source(attr.get_impl()));
68
BOOST_LOG_CLOSE_NAMESPACE // namespace log
72
#include <boost/log/detail/footer.hpp>
74
#endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_