include/boost/capy/error.hpp
100.0% Lines (3 / 3)
100.0% Functions (1 / 1)
Functions (1)
Function
Calls
Lines
Blocks
boost::capy::make_error_code(boost::capy::error)
:93
3703x
100.0%
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2026 Michael Vandeberg | ||
| 4 | // | ||
| 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) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/capy | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_CAPY_ERROR_HPP | ||
| 12 | #define BOOST_CAPY_ERROR_HPP | ||
| 13 | |||
| 14 | #include <boost/capy/detail/config.hpp> | ||
| 15 | #include <system_error> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace capy { | ||
| 19 | |||
| 20 | /** Identify failures reported by capy algorithms and I/O operations. | ||
| 21 | |||
| 22 | Capy algorithms and I/O operations produce these codes. | ||
| 23 | |||
| 24 | @warning Callers must never compare received `error_code` values | ||
| 25 | directly against this enum. Always compare against the portable | ||
| 26 | @ref cond error conditions instead. These enum values are | ||
| 27 | implementation details subject to change. The exception is | ||
| 28 | `test_failure`, which has no @ref cond equivalent and is compared | ||
| 29 | directly. | ||
| 30 | |||
| 31 | @see @ref cond | ||
| 32 | */ | ||
| 33 | enum class error | ||
| 34 | { | ||
| 35 | /// End-of-stream reached. Compare with `cond::eof`. | ||
| 36 | eof = 1, | ||
| 37 | |||
| 38 | /// Operation was canceled. Compare with `cond::canceled`. | ||
| 39 | canceled, | ||
| 40 | |||
| 41 | /// Internal test assertion failed. | ||
| 42 | test_failure, | ||
| 43 | |||
| 44 | /// Peer closed connection without proper TLS shutdown. | ||
| 45 | /// Compare with `cond::stream_truncated`. | ||
| 46 | stream_truncated, | ||
| 47 | |||
| 48 | /// Operation timed out. Compare with `cond::timeout`. | ||
| 49 | timeout | ||
| 50 | }; | ||
| 51 | |||
| 52 | } // capy | ||
| 53 | } // boost | ||
| 54 | |||
| 55 | namespace std { | ||
| 56 | template<> | ||
| 57 | struct is_error_code_enum< | ||
| 58 | ::boost::capy::error> | ||
| 59 | : std::true_type {}; | ||
| 60 | } // std | ||
| 61 | |||
| 62 | namespace boost { | ||
| 63 | namespace capy { | ||
| 64 | |||
| 65 | namespace detail { | ||
| 66 | |||
| 67 | struct BOOST_CAPY_SYMBOL_VISIBLE | ||
| 68 | error_cat_type | ||
| 69 | : std::error_category | ||
| 70 | { | ||
| 71 | BOOST_CAPY_DECL const char* name( | ||
| 72 | ) const noexcept override; | ||
| 73 | BOOST_CAPY_DECL std::string message( | ||
| 74 | int) const override; | ||
| 75 | BOOST_CAPY_DECL std::error_condition default_error_condition( | ||
| 76 | int) const noexcept override; | ||
| 77 | constexpr error_cat_type() noexcept = default; | ||
| 78 | }; | ||
| 79 | |||
| 80 | BOOST_CAPY_DECL extern error_cat_type error_cat; | ||
| 81 | |||
| 82 | } // detail | ||
| 83 | |||
| 84 | /** Create an error_code from an error value. | ||
| 85 | |||
| 86 | @param ev The library error value. | ||
| 87 | |||
| 88 | @return An `std::error_code` holding `ev` in the library's | ||
| 89 | error category. | ||
| 90 | */ | ||
| 91 | inline | ||
| 92 | std::error_code | ||
| 93 | 3703x | make_error_code( | |
| 94 | error ev) noexcept | ||
| 95 | { | ||
| 96 | 3703x | return std::error_code{ | |
| 97 | static_cast<std::underlying_type< | ||
| 98 | error>::type>(ev), | ||
| 99 | 3703x | detail::error_cat}; | |
| 100 | } | ||
| 101 | |||
| 102 | } // capy | ||
| 103 | } // boost | ||
| 104 | |||
| 105 | #endif | ||
| 106 |