100.00% Lines (3/3) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2 - // Copyright (c) 2026 Michael Vandeberg  
3   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
4   // 3   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 4   // 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) 5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 6   //
8   // Official repository: https://github.com/cppalliance/capy 7   // Official repository: https://github.com/cppalliance/capy
9   // 8   //
10   9  
11   #ifndef BOOST_CAPY_ERROR_HPP 10   #ifndef BOOST_CAPY_ERROR_HPP
12   #define BOOST_CAPY_ERROR_HPP 11   #define BOOST_CAPY_ERROR_HPP
13   12  
14   #include <boost/capy/detail/config.hpp> 13   #include <boost/capy/detail/config.hpp>
15   #include <system_error> 14   #include <system_error>
16   15  
17   namespace boost { 16   namespace boost {
18   namespace capy { 17   namespace capy {
19   18  
20   /** Error codes for capy I/O operations. 19   /** Error codes for capy I/O operations.
21   20  
22   These codes are produced by capy algorithms and I/O operations. 21   These codes are produced by capy algorithms and I/O operations.
23   22  
24   @warning Callers must never compare received `error_code` values 23   @warning Callers must never compare received `error_code` values
25   directly against this enum. Always compare against the portable 24   directly against this enum. Always compare against the portable
26   @ref cond error conditions instead. These enum values are 25   @ref cond error conditions instead. These enum values are
27   implementation details subject to change. 26   implementation details subject to change.
28   27  
29   @see cond 28   @see cond
30   */ 29   */
31   enum class error 30   enum class error
32   { 31   {
33   /// End-of-stream reached. Compare with `cond::eof`. 32   /// End-of-stream reached. Compare with `cond::eof`.
34   eof = 1, 33   eof = 1,
35   34  
36   /// Operation was cancelled. Compare with `cond::canceled`. 35   /// Operation was cancelled. Compare with `cond::canceled`.
37   canceled, 36   canceled,
38   37  
39   /// Internal test assertion failed. 38   /// Internal test assertion failed.
40   test_failure, 39   test_failure,
41   40  
42   /// Peer closed connection without proper TLS shutdown. 41   /// Peer closed connection without proper TLS shutdown.
43   /// Compare with `cond::stream_truncated`. 42   /// Compare with `cond::stream_truncated`.
44   stream_truncated, 43   stream_truncated,
45   44  
46   /// Requested item was not found. Compare with `cond::not_found`. 45   /// Requested item was not found. Compare with `cond::not_found`.
47   not_found, 46   not_found,
48   47  
49   /// Operation timed out. Compare with `cond::timeout`. 48   /// Operation timed out. Compare with `cond::timeout`.
50   timeout 49   timeout
51   }; 50   };
52   51  
53   } // capy 52   } // capy
54   } // boost 53   } // boost
55   54  
56   namespace std { 55   namespace std {
57   template<> 56   template<>
58   struct is_error_code_enum< 57   struct is_error_code_enum<
59   ::boost::capy::error> 58   ::boost::capy::error>
60   : std::true_type {}; 59   : std::true_type {};
61   } // std 60   } // std
62   61  
63   namespace boost { 62   namespace boost {
64   namespace capy { 63   namespace capy {
65   64  
66   namespace detail { 65   namespace detail {
67   66  
68   struct BOOST_CAPY_SYMBOL_VISIBLE 67   struct BOOST_CAPY_SYMBOL_VISIBLE
69   error_cat_type 68   error_cat_type
70   : std::error_category 69   : std::error_category
71   { 70   {
72   BOOST_CAPY_DECL const char* name( 71   BOOST_CAPY_DECL const char* name(
73   ) const noexcept override; 72   ) const noexcept override;
74   BOOST_CAPY_DECL std::string message( 73   BOOST_CAPY_DECL std::string message(
75 - BOOST_CAPY_DECL std::error_condition default_error_condition(  
76 - int) const noexcept override;  
77   int) const override; 74   int) const override;
78   constexpr error_cat_type() noexcept = default; 75   constexpr error_cat_type() noexcept = default;
79   }; 76   };
80   77  
81   BOOST_CAPY_DECL extern error_cat_type error_cat; 78   BOOST_CAPY_DECL extern error_cat_type error_cat;
82   79  
83   } // detail 80   } // detail
84   81  
85   /// Create an error_code from an error value. 82   /// Create an error_code from an error value.
86   inline 83   inline
87   std::error_code 84   std::error_code
HITCBC 88   2006 make_error_code( 85   2305 make_error_code(
89   error ev) noexcept 86   error ev) noexcept
90   { 87   {
HITCBC 91   2006 return std::error_code{ 88   2305 return std::error_code{
92   static_cast<std::underlying_type< 89   static_cast<std::underlying_type<
93   error>::type>(ev), 90   error>::type>(ev),
HITCBC 94   2006 detail::error_cat}; 91   2305 detail::error_cat};
95   } 92   }
96   93  
97   } // capy 94   } // capy
98   } // boost 95   } // boost
99   96  
100   #endif 97   #endif