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