Blame view

3rdparty/boost_1_81_0/boost/log/attributes/constant.hpp 3.46 KB
63e88f80   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  /*
   *          Copyright Andrey Semashev 2007 - 2015.
   * Distributed under the Boost Software License, Version 1.0.
   *    (See accompanying file LICENSE_1_0.txt or copy at
   *          http://www.boost.org/LICENSE_1_0.txt)
   */
  /*!
   * \file   constant.hpp
   * \author Andrey Semashev
   * \date   15.04.2007
   *
   * The header contains implementation of a constant attribute.
   */
  
  #ifndef BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_
  #define BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_
  
  #include <boost/move/core.hpp>
  #include <boost/move/utility_core.hpp>
  #include <boost/type_traits/remove_reference.hpp>
  #include <boost/type_traits/is_nothrow_move_constructible.hpp>
  #include <boost/log/detail/config.hpp>
  #include <boost/log/detail/embedded_string_type.hpp>
  #include <boost/log/attributes/attribute.hpp>
  #include <boost/log/attributes/attribute_cast.hpp>
  #include <boost/log/attributes/attribute_value_impl.hpp>
  #include <boost/log/detail/header.hpp>
  
  #ifdef BOOST_HAS_PRAGMA_ONCE
  #pragma once
  #endif
  
  namespace boost {
  
  BOOST_LOG_OPEN_NAMESPACE
  
  namespace attributes {
  
  /*!
   * \brief A class of an attribute that holds a single constant value
   *
   * The constant is a simplest and one of the most frequently used types of attributes.
   * It stores a constant value, which it eventually returns as its value each time
   * requested.
   */
  template< typename T >
  class constant :
      public attribute
  {
  public:
      //! Attribute value type
      typedef T value_type;
  
  protected:
      //! Factory implementation
      class BOOST_SYMBOL_VISIBLE impl :
          public attribute_value_impl< value_type >
      {
          //! Base type
          typedef attribute_value_impl< value_type > base_type;
  
      public:
          /*!
           * Constructor with the stored value initialization
           */
          explicit impl(value_type const& value) : base_type(value) {}
          /*!
           * Constructor with the stored value initialization
           */
          explicit impl(BOOST_RV_REF(value_type) value) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< value_type >::value) :
              base_type(boost::move(value))
          {
          }
      };
  
  public:
      /*!
       * Constructor with the stored value initialization
       */
      explicit constant(value_type const& value) : attribute(new impl(value)) {}
      /*!
       * Constructor with the stored value initialization
       */
      explicit constant(BOOST_RV_REF(value_type) value) : attribute(new impl(boost::move(value))) {}
      /*!
       * Constructor for casting support
       */
      explicit constant(cast_source const& source) : attribute(source.as< impl >())
      {
      }
  
      /*!
       * \return Reference to the contained value.
       */
      value_type const& get() const
      {
          return static_cast< impl* >(this->get_impl())->get();
      }
  };
  
  /*!
   * The function constructs a \c constant attribute containing the provided value.
   * The function automatically converts C string arguments to \c std::basic_string objects.
   */
  template< typename T >
  inline constant<
      typename boost::log::aux::make_embedded_string_type<
          typename remove_reference< T >::type
      >::type
  > make_constant(BOOST_FWD_REF(T) val)
  {
      typedef typename boost::log::aux::make_embedded_string_type<
          typename remove_reference< T >::type
      >::type value_type;
      return constant< value_type >(boost::forward< T >(val));
  }
  
  } // namespace attributes
  
  BOOST_LOG_CLOSE_NAMESPACE // namespace log
  
  } // namespace boost
  
  #include <boost/log/detail/footer.hpp>
  
  #endif // BOOST_LOG_ATTRIBUTES_CONSTANT_HPP_INCLUDED_