TLA Line data 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 : #include <boost/capy/cond.hpp>
11 : #include <boost/capy/error.hpp>
12 : #include <system_error>
13 :
14 : namespace boost {
15 : namespace capy {
16 :
17 : namespace detail {
18 :
19 : const char*
20 HIT 1 : cond_cat_type::
21 : name() const noexcept
22 : {
23 1 : return "boost.capy";
24 : }
25 :
26 : std::string
27 5 : cond_cat_type::
28 : message(int code) const
29 : {
30 5 : switch(static_cast<cond>(code))
31 : {
32 3 : case cond::eof: return "end of file";
33 3 : case cond::canceled: return "operation canceled";
34 3 : case cond::stream_truncated: return "stream truncated";
35 3 : case cond::timeout: return "operation timed out";
36 1 : default:
37 2 : return "unknown";
38 : }
39 : }
40 :
41 : bool
42 128 : cond_cat_type::
43 : equivalent(
44 : std::error_code const& ec,
45 : int condition) const noexcept
46 : {
47 128 : switch(static_cast<cond>(condition))
48 : {
49 9 : case cond::eof:
50 9 : return ec == capy::error::eof;
51 :
52 114 : case cond::canceled:
53 114 : if(ec == capy::error::canceled)
54 31 : return true;
55 83 : if(ec == std::errc::operation_canceled)
56 2 : return true;
57 81 : return false;
58 :
59 1 : case cond::stream_truncated:
60 1 : return ec == capy::error::stream_truncated;
61 :
62 3 : case cond::timeout:
63 3 : if(ec == capy::error::timeout)
64 1 : return true;
65 2 : if(ec == std::errc::timed_out)
66 2 : return true;
67 MIS 0 : return false;
68 :
69 HIT 1 : default:
70 1 : return false;
71 : }
72 : }
73 :
74 : //-----------------------------------------------
75 :
76 : // msvc 14.0 has a bug that warns about inability
77 : // to use constexpr construction here, even though
78 : // there's no constexpr construction
79 : #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900)
80 : BOOST_CAPY_MSVC_WARNING_PUSH
81 : BOOST_CAPY_MSVC_WARNING_DISABLE(4592)
82 : #endif
83 :
84 : #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
85 : constinit cond_cat_type cond_cat;
86 : #else
87 : cond_cat_type cond_cat;
88 : #endif
89 :
90 : #if BOOST_CAPY_WORKAROUND(_MSC_VER, <= 1900)
91 : BOOST_CAPY_MSVC_WARNING_POP
92 : #endif
93 :
94 : } // detail
95 :
96 : } // capy
97 : } // boost
|