GCC Code Coverage Report


Directory: ./
File: libs/capy/include/boost/capy/cond.hpp
Date: 2026-01-22 22:47:31
Exec Total Coverage
Lines: 3 3 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

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 - Return `error::stream_truncated` when peer closes without TLS shutdown.
31 Check `ec == cond::stream_truncated` to portably test for truncation.
32 */
33 enum class cond
34 {
35 eof = 1,
36 canceled = 2,
37 stream_truncated = 3
38 };
39
40 //-----------------------------------------------
41
42 } // capy
43
44 namespace system {
45 template<>
46 struct is_error_condition_enum<
47 ::boost::capy::cond>
48 {
49 static bool const value = true;
50 };
51 } // system
52
53 namespace capy {
54
55 //-----------------------------------------------
56
57 namespace detail {
58
59 struct BOOST_SYMBOL_VISIBLE
60 cond_cat_type
61 : system::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 char const* message(
68 int, char*, std::size_t
69 ) const noexcept override;
70 BOOST_CAPY_DECL bool equivalent(
71 system::error_code const& ec,
72 int condition) const noexcept override;
73 BOOST_SYSTEM_CONSTEXPR cond_cat_type()
74 : error_category(0x2f7a9b3c4e8d1a05)
75 {
76 }
77 };
78
79 BOOST_CAPY_DECL extern cond_cat_type cond_cat;
80
81 } // detail
82
83 //-----------------------------------------------
84
85 inline
86 BOOST_SYSTEM_CONSTEXPR
87 system::error_condition
88 10 make_error_condition(
89 cond ev) noexcept
90 {
91 10 return system::error_condition{
92 static_cast<std::underlying_type<
93 cond>::type>(ev),
94 10 detail::cond_cat};
95 }
96
97 } // capy
98 } // boost
99
100 #endif
101