libs/capy/include/boost/capy/cond.hpp
100.0% Lines (3/3)
100.0% Functions (1/1)
-% Branches (0/0)
libs/capy/include/boost/capy/cond.hpp
| Line | Hits | Source Code |
|---|---|---|
| 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 <system_error> | |
| 15 | ||
| 16 | namespace boost { | |
| 17 | namespace capy { | |
| 18 | ||
| 19 | /** Portable error conditions. | |
| 20 | ||
| 21 | Use these conditions for portable error comparisons: | |
| 22 | ||
| 23 | - Return `error::eof` when originating an eof error. | |
| 24 | Check `ec == cond::eof` to portably test for eof. | |
| 25 | ||
| 26 | - Return the platform canceled error when originating canceled. | |
| 27 | Check `ec == cond::canceled` to portably test for cancellation. | |
| 28 | ||
| 29 | - Return `error::stream_truncated` when peer closes without TLS shutdown. | |
| 30 | Check `ec == cond::stream_truncated` to portably test for truncation. | |
| 31 | */ | |
| 32 | enum class cond | |
| 33 | { | |
| 34 | eof = 1, | |
| 35 | canceled = 2, | |
| 36 | stream_truncated = 3, | |
| 37 | not_found = 4 | |
| 38 | }; | |
| 39 | ||
| 40 | //----------------------------------------------- | |
| 41 | ||
| 42 | } // capy | |
| 43 | } // boost | |
| 44 | ||
| 45 | namespace std { | |
| 46 | template<> | |
| 47 | struct is_error_condition_enum< | |
| 48 | ::boost::capy::cond> | |
| 49 | : std::true_type {}; | |
| 50 | } // std | |
| 51 | ||
| 52 | namespace boost { | |
| 53 | namespace capy { | |
| 54 | ||
| 55 | //----------------------------------------------- | |
| 56 | ||
| 57 | namespace detail { | |
| 58 | ||
| 59 | struct BOOST_CAPY_SYMBOL_VISIBLE | |
| 60 | cond_cat_type | |
| 61 | : std::error_category | |
| 62 | { | |
| 63 | BOOST_CAPY_DECL const char* name( | |
| 64 | ) const noexcept override; | |
| 65 | BOOST_CAPY_DECL std::string message( | |
| 66 | int) const override; | |
| 67 | BOOST_CAPY_DECL bool equivalent( | |
| 68 | std::error_code const& ec, | |
| 69 | int condition) const noexcept override; | |
| 70 | constexpr cond_cat_type() noexcept = default; | |
| 71 | }; | |
| 72 | ||
| 73 | BOOST_CAPY_DECL extern cond_cat_type cond_cat; | |
| 74 | ||
| 75 | } // detail | |
| 76 | ||
| 77 | //----------------------------------------------- | |
| 78 | ||
| 79 | inline | |
| 80 | std::error_condition | |
| 81 | 1010 | make_error_condition( |
| 82 | cond ev) noexcept | |
| 83 | { | |
| 84 | 1010 | return std::error_condition{ |
| 85 | static_cast<std::underlying_type< | |
| 86 | cond>::type>(ev), | |
| 87 | 1010 | detail::cond_cat}; |
| 88 | } | |
| 89 | ||
| 90 | } // capy | |
| 91 | } // boost | |
| 92 | ||
| 93 | #endif | |
| 94 |