Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file attribute_cast.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 06.08.2010
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains utilities for casting between attribute factories.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/log/detail/config.hpp>
|
Chris@16
|
19 #include <boost/log/attributes/attribute.hpp>
|
Chris@16
|
20 #include <boost/log/detail/header.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
23 #pragma once
|
Chris@16
|
24 #endif
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost {
|
Chris@16
|
27
|
Chris@16
|
28 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
29
|
Chris@16
|
30 namespace attributes {
|
Chris@16
|
31
|
Chris@16
|
32 /*!
|
Chris@16
|
33 * The class holds a reference to the attribute factory implementation being casted
|
Chris@16
|
34 */
|
Chris@16
|
35 class cast_source
|
Chris@16
|
36 {
|
Chris@16
|
37 private:
|
Chris@16
|
38 attribute::impl* m_pImpl;
|
Chris@16
|
39
|
Chris@16
|
40 public:
|
Chris@16
|
41 /*!
|
Chris@16
|
42 * Initializing constructor. Creates a source that refers to the specified factory implementation.
|
Chris@16
|
43 */
|
Chris@16
|
44 explicit cast_source(attribute::impl* p) : m_pImpl(p)
|
Chris@16
|
45 {
|
Chris@16
|
46 }
|
Chris@16
|
47
|
Chris@16
|
48 /*!
|
Chris@16
|
49 * The function attempts to cast the aggregated pointer to the implementation to the specified type.
|
Chris@16
|
50 *
|
Chris@16
|
51 * \return The converted pointer or \c NULL, if the conversion fails.
|
Chris@16
|
52 */
|
Chris@16
|
53 template< typename T >
|
Chris@16
|
54 T* as() const { return dynamic_cast< T* >(m_pImpl); }
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 } // namespace attributes
|
Chris@16
|
58
|
Chris@16
|
59 /*!
|
Chris@16
|
60 * The function casts one attribute factory to another
|
Chris@16
|
61 */
|
Chris@16
|
62 template< typename T >
|
Chris@16
|
63 inline T attribute_cast(attribute const& attr)
|
Chris@16
|
64 {
|
Chris@16
|
65 return T(attributes::cast_source(attr.get_impl()));
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
69
|
Chris@16
|
70 } // namespace boost
|
Chris@16
|
71
|
Chris@16
|
72 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
73
|
Chris@16
|
74 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_CAST_HPP_INCLUDED_
|