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