100.00% Lines (3/3)
100.00% Functions (1/1)
| 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 | // | 4 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 5 | // 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) | |||||
| 6 | // | 7 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/capy | 8 | // Official repository: https://github.com/cppalliance/capy | |||||
| 8 | // | 9 | // | |||||
| 9 | 10 | |||||||
| 10 | #ifndef BOOST_CAPY_ERROR_HPP | 11 | #ifndef BOOST_CAPY_ERROR_HPP | |||||
| 11 | #define BOOST_CAPY_ERROR_HPP | 12 | #define BOOST_CAPY_ERROR_HPP | |||||
| 12 | 13 | |||||||
| 13 | #include <boost/capy/detail/config.hpp> | 14 | #include <boost/capy/detail/config.hpp> | |||||
| 14 | #include <system_error> | 15 | #include <system_error> | |||||
| 15 | 16 | |||||||
| 16 | namespace boost { | 17 | namespace boost { | |||||
| 17 | namespace capy { | 18 | namespace capy { | |||||
| 18 | 19 | |||||||
| 19 | /** Error codes for capy I/O operations. | 20 | /** Error codes for capy I/O operations. | |||||
| 20 | 21 | |||||||
| 21 | These codes are produced by capy algorithms and I/O operations. | 22 | These codes are produced by capy algorithms and I/O operations. | |||||
| 22 | 23 | |||||||
| 23 | @warning Callers must never compare received `error_code` values | 24 | @warning Callers must never compare received `error_code` values | |||||
| 24 | directly against this enum. Always compare against the portable | 25 | directly against this enum. Always compare against the portable | |||||
| 25 | @ref cond error conditions instead. These enum values are | 26 | @ref cond error conditions instead. These enum values are | |||||
| 26 | implementation details subject to change. | 27 | implementation details subject to change. | |||||
| 27 | 28 | |||||||
| 28 | @see cond | 29 | @see cond | |||||
| 29 | */ | 30 | */ | |||||
| 30 | enum class error | 31 | enum class error | |||||
| 31 | { | 32 | { | |||||
| 32 | /// End-of-stream reached. Compare with `cond::eof`. | 33 | /// End-of-stream reached. Compare with `cond::eof`. | |||||
| 33 | eof = 1, | 34 | eof = 1, | |||||
| 34 | 35 | |||||||
| 35 | /// Operation was cancelled. Compare with `cond::canceled`. | 36 | /// Operation was cancelled. Compare with `cond::canceled`. | |||||
| 36 | canceled, | 37 | canceled, | |||||
| 37 | 38 | |||||||
| 38 | /// Internal test assertion failed. | 39 | /// Internal test assertion failed. | |||||
| 39 | test_failure, | 40 | test_failure, | |||||
| 40 | 41 | |||||||
| 41 | /// Peer closed connection without proper TLS shutdown. | 42 | /// Peer closed connection without proper TLS shutdown. | |||||
| 42 | /// Compare with `cond::stream_truncated`. | 43 | /// Compare with `cond::stream_truncated`. | |||||
| 43 | stream_truncated, | 44 | stream_truncated, | |||||
| 44 | 45 | |||||||
| 45 | /// Requested item was not found. Compare with `cond::not_found`. | 46 | /// Requested item was not found. Compare with `cond::not_found`. | |||||
| 46 | not_found, | 47 | not_found, | |||||
| 47 | 48 | |||||||
| 48 | /// Operation timed out. Compare with `cond::timeout`. | 49 | /// Operation timed out. Compare with `cond::timeout`. | |||||
| 49 | timeout | 50 | timeout | |||||
| 50 | }; | 51 | }; | |||||
| 51 | 52 | |||||||
| 52 | } // capy | 53 | } // capy | |||||
| 53 | } // boost | 54 | } // boost | |||||
| 54 | 55 | |||||||
| 55 | namespace std { | 56 | namespace std { | |||||
| 56 | template<> | 57 | template<> | |||||
| 57 | struct is_error_code_enum< | 58 | struct is_error_code_enum< | |||||
| 58 | ::boost::capy::error> | 59 | ::boost::capy::error> | |||||
| 59 | : std::true_type {}; | 60 | : std::true_type {}; | |||||
| 60 | } // std | 61 | } // std | |||||
| 61 | 62 | |||||||
| 62 | namespace boost { | 63 | namespace boost { | |||||
| 63 | namespace capy { | 64 | namespace capy { | |||||
| 64 | 65 | |||||||
| 65 | namespace detail { | 66 | namespace detail { | |||||
| 66 | 67 | |||||||
| 67 | struct BOOST_CAPY_SYMBOL_VISIBLE | 68 | struct BOOST_CAPY_SYMBOL_VISIBLE | |||||
| 68 | error_cat_type | 69 | error_cat_type | |||||
| 69 | : std::error_category | 70 | : std::error_category | |||||
| 70 | { | 71 | { | |||||
| 71 | BOOST_CAPY_DECL const char* name( | 72 | BOOST_CAPY_DECL const char* name( | |||||
| 72 | ) const noexcept override; | 73 | ) const noexcept override; | |||||
| 73 | BOOST_CAPY_DECL std::string message( | 74 | BOOST_CAPY_DECL std::string message( | |||||
| 74 | int) const override; | 75 | int) const override; | |||||
| 76 | + | BOOST_CAPY_DECL std::error_condition default_error_condition( | ||||||
| 77 | + | int) const noexcept override; | ||||||
| 75 | constexpr error_cat_type() noexcept = default; | 78 | constexpr error_cat_type() noexcept = default; | |||||
| 76 | }; | 79 | }; | |||||
| 77 | 80 | |||||||
| 78 | BOOST_CAPY_DECL extern error_cat_type error_cat; | 81 | BOOST_CAPY_DECL extern error_cat_type error_cat; | |||||
| 79 | 82 | |||||||
| 80 | } // detail | 83 | } // detail | |||||
| 81 | 84 | |||||||
| 82 | /// Create an error_code from an error value. | 85 | /// Create an error_code from an error value. | |||||
| 83 | inline | 86 | inline | |||||
| 84 | std::error_code | 87 | std::error_code | |||||
| HITCBC | 85 | 2305 | make_error_code( | 88 | 2004 | make_error_code( | ||
| 86 | error ev) noexcept | 89 | error ev) noexcept | |||||
| 87 | { | 90 | { | |||||
| HITCBC | 88 | 2305 | return std::error_code{ | 91 | 2004 | return std::error_code{ | ||
| 89 | static_cast<std::underlying_type< | 92 | static_cast<std::underlying_type< | |||||
| 90 | error>::type>(ev), | 93 | error>::type>(ev), | |||||
| HITCBC | 91 | 2305 | detail::error_cat}; | 94 | 2004 | detail::error_cat}; | ||
| 92 | } | 95 | } | |||||
| 93 | 96 | |||||||
| 94 | } // capy | 97 | } // capy | |||||
| 95 | } // boost | 98 | } // boost | |||||
| 96 | 99 | |||||||
| 97 | #endif | 100 | #endif | |||||