100.00% Lines (20/20) 100.00% Functions (3/3)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
  3 + // Copyright (c) 2026 Michael Vandeberg
3   // 4   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // 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   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 7   //
7   // Official repository: https://github.com/cppalliance/capy 8   // Official repository: https://github.com/cppalliance/capy
8   // 9   //
9   10  
10   #include <boost/capy/error.hpp> 11   #include <boost/capy/error.hpp>
  12 + #include <boost/capy/cond.hpp>
11   13  
12   namespace boost { 14   namespace boost {
13   namespace capy { 15   namespace capy {
14   16  
15   namespace detail { 17   namespace detail {
16   18  
17   const char* 19   const char*
HITCBC 18   2 error_cat_type:: 20   2 error_cat_type::
19   name() const noexcept 21   name() const noexcept
20   { 22   {
HITCBC 21   2 return "boost.capy"; 23   2 return "boost.capy";
22   } 24   }
23   25  
24   std::string 26   std::string
HITCBC 25   1037 error_cat_type:: 27   1037 error_cat_type::
26   message(int code) const 28   message(int code) const
27   { 29   {
HITCBC 28   1037 switch(static_cast<error>(code)) 30   1037 switch(static_cast<error>(code))
29   { 31   {
HITCBC 30   6 case error::eof: return "eof"; 32   6 case error::eof: return "eof";
HITCBC 31   3 case error::canceled: return "operation canceled"; 33   3 case error::canceled: return "operation canceled";
HITCBC 32   3090 case error::test_failure: return "test failure"; 34   3090 case error::test_failure: return "test failure";
HITCBC 33   3 case error::stream_truncated: return "stream truncated"; 35   3 case error::stream_truncated: return "stream truncated";
HITCBC 34   3 case error::not_found: return "not found"; 36   3 case error::not_found: return "not found";
HITCBC 35   3 case error::timeout: return "timeout"; 37   3 case error::timeout: return "timeout";
HITCBC 36   1 default: 38   1 default:
HITCBC 37   2 return "unknown"; 39   2 return "unknown";
  40 + }
  41 + }
  42 +
  43 + // Map each capy error code to its canonical portable condition.
  44 + // canceled and timeout have standard equivalents, so they map to the
  45 + // generic conditions rather than capy's own cond enumerators; this is
  46 + // what lets, e.g., error::canceled compare equal to
  47 + // std::errc::operation_canceled.
  48 + std::error_condition
HITGNC   49 + 546 error_cat_type::
  50 + default_error_condition(int code) const noexcept
  51 + {
HITGNC   52 + 546 switch(static_cast<error>(code))
  53 + {
HITGNC   54 + 301 case error::eof: return make_error_condition(cond::eof);
HITGNC   55 + 4 case error::canceled: return std::make_error_condition(std::errc::operation_canceled);
HITGNC   56 + 1 case error::stream_truncated: return make_error_condition(cond::stream_truncated);
HITGNC   57 + 12 case error::not_found: return make_error_condition(cond::not_found);
HITGNC   58 + 7 case error::timeout: return std::make_error_condition(std::errc::timed_out);
HITGNC   59 + 221 default: return std::error_condition(code, *this);
38   } 60   }
39   } 61   }
40   62  
41   //----------------------------------------------- 63   //-----------------------------------------------
42   64  
43   // msvc 14.0 has a bug that warns about inability 65   // msvc 14.0 has a bug that warns about inability
44   // to use constexpr construction here, even though 66   // to use constexpr construction here, even though
45   // there's no constexpr construction 67   // there's no constexpr construction
46   #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900) 68   #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900)
47   BOOST_CAPY_MSVC_WARNING_PUSH 69   BOOST_CAPY_MSVC_WARNING_PUSH
48   BOOST_CAPY_MSVC_WARNING_DISABLE(4592) 70   BOOST_CAPY_MSVC_WARNING_DISABLE(4592)
49   #endif 71   #endif
50   72  
51   #if defined(__cpp_constinit) && __cpp_constinit >= 201907L 73   #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
52   constinit error_cat_type error_cat; 74   constinit error_cat_type error_cat;
53   #else 75   #else
54   error_cat_type error_cat; 76   error_cat_type error_cat;
55   #endif 77   #endif
56   78  
57   #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900) 79   #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900)
58   BOOST_CAPY_MSVC_WARNING_POP 80   BOOST_CAPY_MSVC_WARNING_POP
59   #endif 81   #endif
60   82  
61   } // detail 83   } // detail
62   84  
63   } // capy 85   } // capy
64   } // boost 86   } // boost