100.00% Lines (18/18)
100.00% Functions (3/3)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // Copyright (c) 2026 Michael Vandeberg | 3 | // Copyright (c) 2026 Michael Vandeberg | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/cppalliance/capy | 8 | // Official repository: https://github.com/cppalliance/capy | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #include <boost/capy/error.hpp> | 11 | #include <boost/capy/error.hpp> | |||||
| 12 | #include <boost/capy/cond.hpp> | 12 | #include <boost/capy/cond.hpp> | |||||
| 13 | 13 | |||||||
| 14 | namespace boost { | 14 | namespace boost { | |||||
| 15 | namespace capy { | 15 | namespace capy { | |||||
| 16 | 16 | |||||||
| 17 | namespace detail { | 17 | namespace detail { | |||||
| 18 | 18 | |||||||
| 19 | const char* | 19 | const char* | |||||
| HITCBC | 20 | 2 | error_cat_type:: | 20 | 2 | error_cat_type:: | ||
| 21 | name() const noexcept | 21 | name() const noexcept | |||||
| 22 | { | 22 | { | |||||
| HITCBC | 23 | 2 | return "boost.capy"; | 23 | 2 | return "boost.capy"; | ||
| 24 | } | 24 | } | |||||
| 25 | 25 | |||||||
| 26 | std::string | 26 | std::string | |||||
| HITCBC | 27 | 888 | error_cat_type:: | 27 | 896 | error_cat_type:: | ||
| 28 | message(int code) const | 28 | message(int code) const | |||||
| 29 | { | 29 | { | |||||
| HITCBC | 30 | 888 | switch(static_cast<error>(code)) | 30 | 896 | switch(static_cast<error>(code)) | ||
| 31 | { | 31 | { | |||||
| HITCBC | 32 | 6 | case error::eof: return "eof"; | 32 | 6 | case error::eof: return "eof"; | ||
| HITCBC | 33 | 3 | case error::canceled: return "operation canceled"; | 33 | 3 | case error::canceled: return "operation canceled"; | ||
| HITCBC | 34 | 2646 | case error::test_failure: return "test failure"; | 34 | 2670 | case error::test_failure: return "test failure"; | ||
| HITCBC | 35 | 3 | case error::stream_truncated: return "stream truncated"; | 35 | 3 | case error::stream_truncated: return "stream truncated"; | ||
| HITCBC | 36 | 3 | case error::timeout: return "timeout"; | 36 | 3 | case error::timeout: return "timeout"; | ||
| HITCBC | 37 | 1 | default: | 37 | 1 | default: | ||
| HITCBC | 38 | 2 | return "unknown"; | 38 | 2 | return "unknown"; | ||
| 39 | } | 39 | } | |||||
| 40 | } | 40 | } | |||||
| 41 | 41 | |||||||
| 42 | // Map each capy error code to its canonical portable condition. | 42 | // Map each capy error code to its canonical portable condition. | |||||
| 43 | // canceled and timeout have standard equivalents, so they map to the | 43 | // canceled and timeout have standard equivalents, so they map to the | |||||
| 44 | // generic conditions rather than capy's own cond enumerators; this is | 44 | // generic conditions rather than capy's own cond enumerators; this is | |||||
| 45 | // what lets, e.g., error::canceled compare equal to | 45 | // what lets, e.g., error::canceled compare equal to | |||||
| 46 | // std::errc::operation_canceled. | 46 | // std::errc::operation_canceled. | |||||
| 47 | std::error_condition | 47 | std::error_condition | |||||
| HITCBC | 48 | 421 | error_cat_type:: | 48 | 404 | error_cat_type:: | ||
| 49 | default_error_condition(int code) const noexcept | 49 | default_error_condition(int code) const noexcept | |||||
| 50 | { | 50 | { | |||||
| HITCBC | 51 | 421 | switch(static_cast<error>(code)) | 51 | 404 | switch(static_cast<error>(code)) | ||
| 52 | { | 52 | { | |||||
| HITCBC | 53 | 251 | case error::eof: return make_error_condition(cond::eof); | 53 | 251 | case error::eof: return make_error_condition(cond::eof); | ||
| HITCBC | 54 | 58 | case error::canceled: return std::make_error_condition(std::errc::operation_canceled); | 54 | 41 | case error::canceled: return std::make_error_condition(std::errc::operation_canceled); | ||
| HITCBC | 55 | 1 | case error::stream_truncated: return make_error_condition(cond::stream_truncated); | 55 | 1 | case error::stream_truncated: return make_error_condition(cond::stream_truncated); | ||
| HITCBC | 56 | 2 | case error::timeout: return std::make_error_condition(std::errc::timed_out); | 56 | 2 | case error::timeout: return std::make_error_condition(std::errc::timed_out); | ||
| HITCBC | 57 | 109 | default: return std::error_condition(code, *this); | 57 | 109 | default: return std::error_condition(code, *this); | ||
| 58 | } | 58 | } | |||||
| 59 | } | 59 | } | |||||
| 60 | 60 | |||||||
| 61 | //----------------------------------------------- | 61 | //----------------------------------------------- | |||||
| 62 | 62 | |||||||
| 63 | // msvc 14.0 has a bug that warns about inability | 63 | // msvc 14.0 has a bug that warns about inability | |||||
| 64 | // to use constexpr construction here, even though | 64 | // to use constexpr construction here, even though | |||||
| 65 | // there's no constexpr construction | 65 | // there's no constexpr construction | |||||
| 66 | #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900) | 66 | #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900) | |||||
| 67 | BOOST_CAPY_MSVC_WARNING_PUSH | 67 | BOOST_CAPY_MSVC_WARNING_PUSH | |||||
| 68 | BOOST_CAPY_MSVC_WARNING_DISABLE(4592) | 68 | BOOST_CAPY_MSVC_WARNING_DISABLE(4592) | |||||
| 69 | #endif | 69 | #endif | |||||
| 70 | 70 | |||||||
| 71 | #if defined(__cpp_constinit) && __cpp_constinit >= 201907L | 71 | #if defined(__cpp_constinit) && __cpp_constinit >= 201907L | |||||
| 72 | constinit error_cat_type error_cat; | 72 | constinit error_cat_type error_cat; | |||||
| 73 | #else | 73 | #else | |||||
| 74 | error_cat_type error_cat; | 74 | error_cat_type error_cat; | |||||
| 75 | #endif | 75 | #endif | |||||
| 76 | 76 | |||||||
| 77 | #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900) | 77 | #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900) | |||||
| 78 | BOOST_CAPY_MSVC_WARNING_POP | 78 | BOOST_CAPY_MSVC_WARNING_POP | |||||
| 79 | #endif | 79 | #endif | |||||
| 80 | 80 | |||||||
| 81 | } // detail | 81 | } // detail | |||||
| 82 | 82 | |||||||
| 83 | } // capy | 83 | } // capy | |||||
| 84 | } // boost | 84 | } // boost | |||||