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 4 : cond_cat_type::
28 : message(int code) const
29 : {
30 4 : switch(static_cast<cond>(code))
31 : {
32 3 : case cond::eof: return "end of file";
33 3 : case cond::canceled: return "operation canceled";
34 MIS 0 : case cond::stream_truncated: return "stream truncated";
35 HIT 3 : case cond::not_found: return "not found";
36 3 : case cond::timeout: return "operation timed out";
37 MIS 0 : default:
38 0 : return "unknown";
39 : }
40 : }
41 :
42 : bool
43 HIT 1365 : cond_cat_type::
44 : equivalent(
45 : std::error_code const& ec,
46 : int condition) const noexcept
47 : {
48 1365 : switch(static_cast<cond>(condition))
49 : {
50 1343 : case cond::eof:
51 1343 : return ec == capy::error::eof;
52 :
53 6 : case cond::canceled:
54 6 : if(ec == capy::error::canceled)
55 MIS 0 : return true;
56 HIT 6 : if(ec == std::errc::operation_canceled)
57 2 : return true;
58 4 : return false;
59 :
60 MIS 0 : case cond::stream_truncated:
61 0 : return ec == capy::error::stream_truncated;
62 :
63 HIT 14 : case cond::not_found:
64 14 : return ec == capy::error::not_found;
65 :
66 2 : case cond::timeout:
67 2 : return ec == capy::error::timeout;
68 :
69 MIS 0 : default:
70 0 : 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 defined(_MSC_VER) && _MSC_VER <= 1900
80 : # pragma warning( push )
81 : # pragma 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 defined(_MSC_VER) && _MSC_VER <= 1900
91 : # pragma warning( pop )
92 : #endif
93 :
94 : } // detail
95 :
96 : } // capy
97 : } // boost
|