include/boost/capy/error.hpp

100.0% Lines (3/3) 100.0% List of functions (1/1)
error.hpp
f(x) Functions (1)
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 /** Error codes for capy I/O operations.
21
22 These codes are produced by capy algorithms and I/O operations.
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.
28
29 @see cond
30 */
31 enum class error
32 {
33 /// End-of-stream reached. Compare with `cond::eof`.
34 eof = 1,
35
36 /// Operation was cancelled. Compare with `cond::canceled`.
37 canceled,
38
39 /// Internal test assertion failed.
40 test_failure,
41
42 /// Peer closed connection without proper TLS shutdown.
43 /// Compare with `cond::stream_truncated`.
44 stream_truncated,
45
46 /// Requested item was not found. Compare with `cond::not_found`.
47 not_found,
48
49 /// Operation timed out. Compare with `cond::timeout`.
50 timeout
51 };
52
53 } // capy
54 } // boost
55
56 namespace std {
57 template<>
58 struct is_error_code_enum<
59 ::boost::capy::error>
60 : std::true_type {};
61 } // std
62
63 namespace boost {
64 namespace capy {
65
66 namespace detail {
67
68 struct BOOST_CAPY_SYMBOL_VISIBLE
69 error_cat_type
70 : std::error_category
71 {
72 BOOST_CAPY_DECL const char* name(
73 ) const noexcept override;
74 BOOST_CAPY_DECL std::string message(
75 int) const override;
76 BOOST_CAPY_DECL std::error_condition default_error_condition(
77 int) const noexcept override;
78 constexpr error_cat_type() noexcept = default;
79 };
80
81 BOOST_CAPY_DECL extern error_cat_type error_cat;
82
83 } // detail
84
85 /// Create an error_code from an error value.
86 inline
87 std::error_code
88 2004x make_error_code(
89 error ev) noexcept
90 {
91 2004x return std::error_code{
92 static_cast<std::underlying_type<
93 error>::type>(ev),
94 2004x detail::error_cat};
95 }
96
97 } // capy
98 } // boost
99
100 #endif
101