100.00% Lines (2/2)
100.00% Functions (1/1)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2026 Michael Vandeberg | 2 | // Copyright (c) 2026 Michael Vandeberg | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 4 | // 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) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/corosio | 7 | // Official repository: https://github.com/cppalliance/corosio | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_COROSIO_ERROR_HPP | 10 | #ifndef BOOST_COROSIO_ERROR_HPP | |||||
| 11 | #define BOOST_COROSIO_ERROR_HPP | 11 | #define BOOST_COROSIO_ERROR_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/corosio/detail/config.hpp> | 13 | #include <boost/corosio/detail/config.hpp> | |||||
| 14 | 14 | |||||||
| 15 | #include <string> | 15 | #include <string> | |||||
| 16 | #include <system_error> | 16 | #include <system_error> | |||||
| 17 | #include <type_traits> | 17 | #include <type_traits> | |||||
| 18 | 18 | |||||||
| 19 | namespace boost::corosio { | 19 | namespace boost::corosio { | |||||
| 20 | 20 | |||||||
| 21 | /** Identifies failures corosio detects itself. | 21 | /** Identifies failures corosio detects itself. | |||||
| 22 | 22 | |||||||
| 23 | Codes the operating system reports keep their system category. | 23 | Codes the operating system reports keep their system category. | |||||
| 24 | */ | 24 | */ | |||||
| 25 | enum class error | 25 | enum class error | |||||
| 26 | { | 26 | { | |||||
| 27 | /// The target object already holds an open handle. | 27 | /// The target object already holds an open handle. | |||||
| 28 | already_open = 1 | 28 | already_open = 1 | |||||
| 29 | }; | 29 | }; | |||||
| 30 | 30 | |||||||
| 31 | } // namespace boost::corosio | 31 | } // namespace boost::corosio | |||||
| 32 | 32 | |||||||
| 33 | namespace std { | 33 | namespace std { | |||||
| 34 | template<> | 34 | template<> | |||||
| 35 | struct is_error_code_enum<::boost::corosio::error> : std::true_type | 35 | struct is_error_code_enum<::boost::corosio::error> : std::true_type | |||||
| 36 | {}; | 36 | {}; | |||||
| 37 | } // namespace std | 37 | } // namespace std | |||||
| 38 | 38 | |||||||
| 39 | namespace boost::corosio { | 39 | namespace boost::corosio { | |||||
| 40 | namespace detail { | 40 | namespace detail { | |||||
| 41 | 41 | |||||||
| 42 | struct BOOST_COROSIO_SYMBOL_VISIBLE error_cat_type : std::error_category | 42 | struct BOOST_COROSIO_SYMBOL_VISIBLE error_cat_type : std::error_category | |||||
| 43 | { | 43 | { | |||||
| 44 | BOOST_COROSIO_DECL char const* name() const noexcept override; | 44 | BOOST_COROSIO_DECL char const* name() const noexcept override; | |||||
| 45 | BOOST_COROSIO_DECL std::string message(int) const override; | 45 | BOOST_COROSIO_DECL std::string message(int) const override; | |||||
| 46 | constexpr error_cat_type() noexcept = default; | 46 | constexpr error_cat_type() noexcept = default; | |||||
| 47 | }; | 47 | }; | |||||
| 48 | 48 | |||||||
| 49 | BOOST_COROSIO_DECL extern error_cat_type error_cat; | 49 | BOOST_COROSIO_DECL extern error_cat_type error_cat; | |||||
| 50 | 50 | |||||||
| 51 | } // namespace detail | 51 | } // namespace detail | |||||
| 52 | 52 | |||||||
| 53 | /** Create an `std::error_code` from a corosio error value. | 53 | /** Create an `std::error_code` from a corosio error value. | |||||
| 54 | 54 | |||||||
| 55 | @param ev The error value. | 55 | @param ev The error value. | |||||
| 56 | @return An `std::error_code` in corosio's category. | 56 | @return An `std::error_code` in corosio's category. | |||||
| 57 | */ | 57 | */ | |||||
| 58 | inline std::error_code | 58 | inline std::error_code | |||||
| HITCBC | 59 | 120 | make_error_code(error ev) noexcept | 59 | 120 | make_error_code(error ev) noexcept | ||
| 60 | { | 60 | { | |||||
| HITCBC | 61 | 120 | return std::error_code{static_cast<int>(ev), detail::error_cat}; | 61 | 120 | return std::error_code{static_cast<int>(ev), detail::error_cat}; | ||
| 62 | } | 62 | } | |||||
| 63 | 63 | |||||||
| 64 | } // namespace boost::corosio | 64 | } // namespace boost::corosio | |||||
| 65 | 65 | |||||||
| 66 | #endif | 66 | #endif | |||||