Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 08:51:44

0001 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
0002 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
0003 
0004 #pragma once
0005 
0006 #ifndef SPDLOG_HEADER_ONLY
0007     #include <spdlog/common.h>
0008 #endif
0009 
0010 #include <algorithm>
0011 #include <iterator>
0012 
0013 namespace spdlog {
0014 namespace level {
0015 
0016 #if __cplusplus >= 201703L
0017 constexpr
0018 #endif
0019     static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
0020 
0021 static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;
0022 
0023 SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT {
0024     return level_string_views[l];
0025 }
0026 
0027 SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT {
0028     return short_level_names[l];
0029 }
0030 
0031 SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT {
0032     auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
0033     if (it != std::end(level_string_views))
0034         return static_cast<level::level_enum>(std::distance(std::begin(level_string_views), it));
0035 
0036     // check also for "warn" and "err" before giving up..
0037     if (name == "warn") {
0038         return level::warn;
0039     }
0040     if (name == "err") {
0041         return level::err;
0042     }
0043     return level::off;
0044 }
0045 }  // namespace level
0046 
0047 SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
0048     : msg_(std::move(msg)) {}
0049 
0050 SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) {
0051 #ifdef SPDLOG_USE_STD_FORMAT
0052     msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
0053 #else
0054     memory_buf_t outbuf;
0055     fmt::format_system_error(outbuf, last_errno, msg.c_str());
0056     msg_ = fmt::to_string(outbuf);
0057 #endif
0058 }
0059 
0060 SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT { return msg_.c_str(); }
0061 
0062 SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) {
0063     SPDLOG_THROW(spdlog_ex(msg, last_errno));
0064 }
0065 
0066 SPDLOG_INLINE void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); }
0067 
0068 }  // namespace spdlog