annotate DEPENDENCIES/generic/include/boost/log/attributes/attribute_value_impl.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
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_value_impl.hpp
Chris@16 9 * \author Andrey Semashev
Chris@16 10 * \date 24.06.2007
Chris@16 11 *
Chris@16 12 * The header contains an implementation of a basic attribute value implementation class.
Chris@16 13 */
Chris@16 14
Chris@16 15 #ifndef BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
Chris@16 16 #define BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_
Chris@16 17
Chris@16 18 #include <boost/move/core.hpp>
Chris@16 19 #include <boost/move/utility.hpp>
Chris@16 20 #include <boost/type_traits/remove_cv.hpp>
Chris@16 21 #include <boost/log/detail/config.hpp>
Chris@16 22 #include <boost/log/attributes/attribute_value.hpp>
Chris@16 23 #include <boost/log/utility/type_dispatch/type_dispatcher.hpp>
Chris@16 24 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Chris@16 25 #include <boost/type_traits/remove_reference.hpp>
Chris@16 26 #endif
Chris@16 27 #include <boost/log/detail/header.hpp>
Chris@16 28
Chris@16 29 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@16 30 #pragma once
Chris@16 31 #endif
Chris@16 32
Chris@16 33 namespace boost {
Chris@16 34
Chris@16 35 BOOST_LOG_OPEN_NAMESPACE
Chris@16 36
Chris@16 37 namespace attributes {
Chris@16 38
Chris@16 39 /*!
Chris@16 40 * \brief Basic attribute value implementation class
Chris@16 41 *
Chris@16 42 * This class can be used as a boilerplate for simple attribute values. The class implements all needed
Chris@16 43 * interfaces of attribute values and allows to store a single value of the type specified as a template parameter.
Chris@16 44 * The stored value can be dispatched with type dispatching mechanism.
Chris@16 45 */
Chris@16 46 template< typename T >
Chris@16 47 class attribute_value_impl :
Chris@16 48 public attribute_value::impl
Chris@16 49 {
Chris@16 50 public:
Chris@16 51 //! Value type
Chris@16 52 typedef T value_type;
Chris@16 53
Chris@16 54 private:
Chris@16 55 //! Attribute value
Chris@16 56 const value_type m_value;
Chris@16 57
Chris@16 58 public:
Chris@16 59 /*!
Chris@16 60 * Constructor with initialization of the stored value
Chris@16 61 */
Chris@16 62 explicit attribute_value_impl(value_type const& v) : m_value(v) {}
Chris@16 63 /*!
Chris@16 64 * Constructor with initialization of the stored value
Chris@16 65 */
Chris@16 66 explicit attribute_value_impl(BOOST_RV_REF(value_type) v) : m_value(v) {}
Chris@16 67
Chris@16 68 /*!
Chris@16 69 * Attribute value dispatching method.
Chris@16 70 *
Chris@16 71 * \param dispatcher The dispatcher that receives the stored value
Chris@16 72 *
Chris@16 73 * \return \c true if the value has been dispatched, \c false otherwise
Chris@16 74 */
Chris@16 75 virtual bool dispatch(type_dispatcher& dispatcher)
Chris@16 76 {
Chris@16 77 type_dispatcher::callback< value_type > callback = dispatcher.get_callback< value_type >();
Chris@16 78 if (callback)
Chris@16 79 {
Chris@16 80 callback(m_value);
Chris@16 81 return true;
Chris@16 82 }
Chris@16 83 else
Chris@16 84 return false;
Chris@16 85 }
Chris@16 86
Chris@16 87 /*!
Chris@16 88 * \return The attribute value type
Chris@16 89 */
Chris@16 90 type_info_wrapper get_type() const { return type_info_wrapper(typeid(value_type)); }
Chris@16 91
Chris@16 92 /*!
Chris@16 93 * \return Reference to the contained value.
Chris@16 94 */
Chris@16 95 value_type const& get() const { return m_value; }
Chris@16 96 };
Chris@16 97
Chris@16 98 /*!
Chris@16 99 * The function creates an attribute value from the specified object.
Chris@16 100 */
Chris@16 101 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Chris@16 102
Chris@16 103 template< typename T >
Chris@16 104 inline attribute_value make_attribute_value(T&& v)
Chris@16 105 {
Chris@16 106 typedef typename remove_cv< typename remove_reference< T >::type >::type value_type;
Chris@16 107 return attribute_value(new attribute_value_impl< value_type >(boost::forward< T >(v)));
Chris@16 108 }
Chris@16 109
Chris@16 110 #else // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Chris@16 111
Chris@16 112 template< typename T >
Chris@16 113 inline attribute_value make_attribute_value(T const& v)
Chris@16 114 {
Chris@16 115 typedef typename remove_cv< T >::type value_type;
Chris@16 116 return attribute_value(new attribute_value_impl< value_type >(v));
Chris@16 117 }
Chris@16 118
Chris@16 119 template< typename T >
Chris@16 120 inline attribute_value make_attribute_value(rv< T > const& v)
Chris@16 121 {
Chris@16 122 typedef typename remove_cv< T >::type value_type;
Chris@16 123 return attribute_value(new attribute_value_impl< value_type >(v));
Chris@16 124 }
Chris@16 125
Chris@16 126 #endif // !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Chris@16 127
Chris@16 128 } // namespace attributes
Chris@16 129
Chris@16 130 BOOST_LOG_CLOSE_NAMESPACE // namespace log
Chris@16 131
Chris@16 132 } // namespace boost
Chris@16 133
Chris@16 134 #include <boost/log/detail/footer.hpp>
Chris@16 135
Chris@16 136 #endif // BOOST_LOG_ATTRIBUTES_ATTRIBUTE_VALUE_IMPL_HPP_INCLUDED_