src/cond.cpp

96.7% Lines (29/30) 100.0% List of functions (3/3)
cond.cpp
f(x) Functions (3)
Line TLA Hits 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 1x cond_cat_type::
21 name() const noexcept
22 {
23 1x return "boost.capy";
24 }
25
26 std::string
27 5x cond_cat_type::
28 message(int code) const
29 {
30 5x switch(static_cast<cond>(code))
31 {
32 3x case cond::eof: return "end of file";
33 3x case cond::canceled: return "operation canceled";
34 3x case cond::stream_truncated: return "stream truncated";
35 3x case cond::timeout: return "operation timed out";
36 1x default:
37 2x return "unknown";
38 }
39 }
40
41 bool
42 913x cond_cat_type::
43 equivalent(
44 std::error_code const& ec,
45 int condition) const noexcept
46 {
47 913x switch(static_cast<cond>(condition))
48 {
49 785x case cond::eof:
50 785x return ec == capy::error::eof;
51
52 123x case cond::canceled:
53 123x if(ec == capy::error::canceled)
54 48x return true;
55 75x if(ec == std::errc::operation_canceled)
56 2x return true;
57 73x return false;
58
59 1x case cond::stream_truncated:
60 1x return ec == capy::error::stream_truncated;
61
62 3x case cond::timeout:
63 3x if(ec == capy::error::timeout)
64 1x return true;
65 2x if(ec == std::errc::timed_out)
66 2x return true;
67 return false;
68
69 1x default:
70 1x 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
98