Blame view

3rdparty/boost_1_81_0/libs/log/src/trivial.cpp 4.76 KB
73ef4ff3   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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  /*
   *          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   trivial.cpp
   * \author Andrey Semashev
   * \date   07.11.2009
   *
   * \brief  This header is the Boost.Log library implementation, see the library documentation
   *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
   */
  
  #include <boost/log/detail/config.hpp>
  
  #if defined(BOOST_LOG_USE_CHAR)
  
  #include <string>
  #include <istream>
  #include <boost/log/trivial.hpp>
  #include <boost/log/sources/global_logger_storage.hpp>
  #include <boost/log/detail/header.hpp>
  
  namespace boost {
  
  BOOST_LOG_OPEN_NAMESPACE
  
  namespace trivial {
  
  //! Initialization routine
  BOOST_LOG_API logger::logger_type logger::construct_logger()
  {
      return logger_type(keywords::severity = info);
  }
  
  //! Returns a reference to the trivial logger instance
  BOOST_LOG_API logger::logger_type& logger::get()
  {
      return log::sources::aux::logger_singleton< logger >::get();
  }
  
  BOOST_LOG_ANONYMOUS_NAMESPACE {
  
  BOOST_CONSTEXPR_OR_CONST unsigned int names_count = 6;
  
  template< typename CharT >
  struct severity_level_names
  {
      static const CharT names[names_count][8];
  };
  
  template< typename CharT >
  const CharT severity_level_names< CharT >::names[names_count][8] =
  {
      { 't', 'r', 'a', 'c', 'e', 0 },
      { 'd', 'e', 'b', 'u', 'g', 0 },
      { 'i', 'n', 'f', 'o', 0 },
      { 'w', 'a', 'r', 'n', 'i', 'n', 'g', 0 },
      { 'e', 'r', 'r', 'o', 'r', 0 },
      { 'f', 'a', 't', 'a', 'l', 0 }
  };
  
  } // namespace
  
  template< typename CharT >
  BOOST_LOG_API const CharT* to_string(severity_level lvl)
  {
      typedef severity_level_names< CharT > level_names;
      if (BOOST_LIKELY(static_cast< unsigned int >(lvl) < names_count))
          return level_names::names[static_cast< unsigned int >(lvl)];
      return NULL;
  }
  
  //! Parses enumeration value from string and returns \c true on success and \c false otherwise
  template< typename CharT >
  BOOST_LOG_API bool from_string(const CharT* str, std::size_t len, severity_level& lvl)
  {
      typedef severity_level_names< CharT > level_names;
      typedef std::char_traits< CharT > char_traits;
  
      if (len == 5u)
      {
          if (char_traits::compare(str, level_names::names[0], len) == 0)
              lvl = static_cast< severity_level >(0);
          else if (char_traits::compare(str, level_names::names[1], len) == 0)
              lvl = static_cast< severity_level >(1);
          else if (char_traits::compare(str, level_names::names[4], len) == 0)
              lvl = static_cast< severity_level >(4);
          else if (char_traits::compare(str, level_names::names[5], len) == 0)
              lvl = static_cast< severity_level >(5);
          else
              goto no_match;
          return true;
      }
      else if (len == 4u)
      {
          if (char_traits::compare(str, level_names::names[2], len) == 0)
              lvl = static_cast< severity_level >(2);
          else
              goto no_match;
          return true;
      }
      else if (len == 7u)
      {
          if (char_traits::compare(str, level_names::names[3], len) == 0)
              lvl = static_cast< severity_level >(3);
          else
              goto no_match;
          return true;
      }
  
  no_match:
      return false;
  }
  
  template< typename CharT, typename TraitsT >
  BOOST_LOG_API std::basic_istream< CharT, TraitsT >& operator>> (
      std::basic_istream< CharT, TraitsT >& strm, severity_level& lvl)
  {
      if (BOOST_LIKELY(strm.good()))
      {
          typedef std::basic_string< CharT, TraitsT > string_type;
          string_type str;
          strm >> str;
          if (BOOST_UNLIKELY(!boost::log::trivial::from_string(str.data(), str.size(), lvl)))
              strm.setstate(std::ios_base::failbit);
      }
  
      return strm;
  }
  
  template BOOST_LOG_API const char* to_string< char >(severity_level lvl);
  template BOOST_LOG_API bool from_string< char >(const char* begin, std::size_t len, severity_level& lvl);
  template BOOST_LOG_API std::basic_istream< char, std::char_traits< char > >&
      operator>> < char, std::char_traits< char > > (
          std::basic_istream< char, std::char_traits< char > >& strm, severity_level& lvl);
  #ifdef BOOST_LOG_USE_WCHAR_T
  template BOOST_LOG_API const wchar_t* to_string< wchar_t >(severity_level lvl);
  template BOOST_LOG_API bool from_string< wchar_t >(const wchar_t* begin, std::size_t len, severity_level& lvl);
  template BOOST_LOG_API std::basic_istream< wchar_t, std::char_traits< wchar_t > >&
      operator>> < wchar_t, std::char_traits< wchar_t > > (
          std::basic_istream< wchar_t, std::char_traits< wchar_t > >& strm, severity_level& lvl);
  #endif
  
  } // namespace trivial
  
  BOOST_LOG_CLOSE_NAMESPACE // namespace log
  
  } // namespace boost
  
  #include <boost/log/detail/footer.hpp>
  
  #endif // defined(BOOST_LOG_USE_CHAR)