| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 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) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/capy | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_CAPY_COND_HPP | ||
| 11 | #define BOOST_CAPY_COND_HPP | ||
| 12 | |||
| 13 | #include <boost/capy/detail/config.hpp> | ||
| 14 | #include <boost/system/error_category.hpp> | ||
| 15 | #include <boost/system/is_error_condition_enum.hpp> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace capy { | ||
| 19 | |||
| 20 | /** Portable error conditions. | ||
| 21 | |||
| 22 | Use these conditions for portable error comparisons: | ||
| 23 | |||
| 24 | - Return `error::eof` when originating an eof error. | ||
| 25 | Check `ec == cond::eof` to portably test for eof. | ||
| 26 | |||
| 27 | - Return the platform canceled error when originating canceled. | ||
| 28 | Check `ec == cond::canceled` to portably test for cancellation. | ||
| 29 | */ | ||
| 30 | enum class cond | ||
| 31 | { | ||
| 32 | eof = 1, | ||
| 33 | canceled = 2 | ||
| 34 | }; | ||
| 35 | |||
| 36 | //----------------------------------------------- | ||
| 37 | |||
| 38 | } // capy | ||
| 39 | |||
| 40 | namespace system { | ||
| 41 | template<> | ||
| 42 | struct is_error_condition_enum< | ||
| 43 | ::boost::capy::cond> | ||
| 44 | { | ||
| 45 | static bool const value = true; | ||
| 46 | }; | ||
| 47 | } // system | ||
| 48 | |||
| 49 | namespace capy { | ||
| 50 | |||
| 51 | //----------------------------------------------- | ||
| 52 | |||
| 53 | namespace detail { | ||
| 54 | |||
| 55 | struct BOOST_SYMBOL_VISIBLE | ||
| 56 | cond_cat_type | ||
| 57 | : system::error_category | ||
| 58 | { | ||
| 59 | BOOST_CAPY_DECL const char* name( | ||
| 60 | ) const noexcept override; | ||
| 61 | BOOST_CAPY_DECL std::string message( | ||
| 62 | int) const override; | ||
| 63 | BOOST_CAPY_DECL char const* message( | ||
| 64 | int, char*, std::size_t | ||
| 65 | ) const noexcept override; | ||
| 66 | BOOST_CAPY_DECL bool equivalent( | ||
| 67 | system::error_code const& ec, | ||
| 68 | int condition) const noexcept override; | ||
| 69 | BOOST_SYSTEM_CONSTEXPR cond_cat_type() | ||
| 70 | : error_category(0x2f7a9b3c4e8d1a05) | ||
| 71 | { | ||
| 72 | } | ||
| 73 | }; | ||
| 74 | |||
| 75 | BOOST_CAPY_DECL extern cond_cat_type cond_cat; | ||
| 76 | |||
| 77 | } // detail | ||
| 78 | |||
| 79 | //----------------------------------------------- | ||
| 80 | |||
| 81 | inline | ||
| 82 | BOOST_SYSTEM_CONSTEXPR | ||
| 83 | system::error_condition | ||
| 84 | 10 | make_error_condition( | |
| 85 | cond ev) noexcept | ||
| 86 | { | ||
| 87 | 10 | return system::error_condition{ | |
| 88 | static_cast<std::underlying_type< | ||
| 89 | cond>::type>(ev), | ||
| 90 | 10 | detail::cond_cat}; | |
| 91 | } | ||
| 92 | |||
| 93 | } // capy | ||
| 94 | } // boost | ||
| 95 | |||
| 96 | #endif | ||
| 97 |