1  
//
1  
//
2  
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/cppalliance/capy
7  
// Official repository: https://github.com/cppalliance/capy
8  
//
8  
//
9  

9  

10  
#include <boost/capy/cond.hpp>
10  
#include <boost/capy/cond.hpp>
11  
#include <boost/capy/error.hpp>
11  
#include <boost/capy/error.hpp>
12  
#include <system_error>
12  
#include <system_error>
13  

13  

14  
namespace boost {
14  
namespace boost {
15  
namespace capy {
15  
namespace capy {
16  

16  

17  
namespace detail {
17  
namespace detail {
18  

18  

19  
const char*
19  
const char*
20  
cond_cat_type::
20  
cond_cat_type::
21  
name() const noexcept
21  
name() const noexcept
22  
{
22  
{
23  
    return "boost.capy";
23  
    return "boost.capy";
24  
}
24  
}
25  

25  

26  
std::string
26  
std::string
27  
cond_cat_type::
27  
cond_cat_type::
28  
message(int code) const
28  
message(int code) const
29  
{
29  
{
30  
    switch(static_cast<cond>(code))
30  
    switch(static_cast<cond>(code))
31  
    {
31  
    {
32  
    case cond::eof: return "end of file";
32  
    case cond::eof: return "end of file";
33  
    case cond::canceled: return "operation canceled";
33  
    case cond::canceled: return "operation canceled";
34  
    case cond::stream_truncated: return "stream truncated";
34  
    case cond::stream_truncated: return "stream truncated";
35  
    case cond::not_found: return "not found";
35  
    case cond::not_found: return "not found";
36  
    default:
36  
    default:
37  
        return "unknown";
37  
        return "unknown";
38  
    }
38  
    }
39  
}
39  
}
40  

40  

41  
bool
41  
bool
42  
cond_cat_type::
42  
cond_cat_type::
43  
equivalent(
43  
equivalent(
44  
    std::error_code const& ec,
44  
    std::error_code const& ec,
45  
    int condition) const noexcept
45  
    int condition) const noexcept
46  
{
46  
{
47  
    switch(static_cast<cond>(condition))
47  
    switch(static_cast<cond>(condition))
48  
    {
48  
    {
49  
    case cond::eof:
49  
    case cond::eof:
50  
        return ec == capy::error::eof;
50  
        return ec == capy::error::eof;
51  

51  

52  
    case cond::canceled:
52  
    case cond::canceled:
53  
        if(ec == capy::error::canceled)
53  
        if(ec == capy::error::canceled)
54  
            return true;
54  
            return true;
55  
        if(ec == std::errc::operation_canceled)
55  
        if(ec == std::errc::operation_canceled)
56  
            return true;
56  
            return true;
57  
        return false;
57  
        return false;
58  

58  

59  
    case cond::stream_truncated:
59  
    case cond::stream_truncated:
60  
        return ec == capy::error::stream_truncated;
60  
        return ec == capy::error::stream_truncated;
61  

61  

62  
    case cond::not_found:
62  
    case cond::not_found:
63  
        return ec == capy::error::not_found;
63  
        return ec == capy::error::not_found;
64  

64  

65  
    default:
65  
    default:
66  
        return false;
66  
        return false;
67  
    }
67  
    }
68  
}
68  
}
69  

69  

70  
//-----------------------------------------------
70  
//-----------------------------------------------
71  

71  

72  
// msvc 14.0 has a bug that warns about inability
72  
// msvc 14.0 has a bug that warns about inability
73  
// to use constexpr construction here, even though
73  
// to use constexpr construction here, even though
74  
// there's no constexpr construction
74  
// there's no constexpr construction
75  
#if defined(_MSC_VER) && _MSC_VER <= 1900
75  
#if defined(_MSC_VER) && _MSC_VER <= 1900
76  
# pragma warning( push )
76  
# pragma warning( push )
77  
# pragma warning( disable : 4592 )
77  
# pragma warning( disable : 4592 )
78  
#endif
78  
#endif
79  

79  

80  
#if defined(__cpp_constinit) && __cpp_constinit >= 201907L
80  
#if defined(__cpp_constinit) && __cpp_constinit >= 201907L
81  
constinit cond_cat_type cond_cat;
81  
constinit cond_cat_type cond_cat;
82  
#else
82  
#else
83  
cond_cat_type cond_cat;
83  
cond_cat_type cond_cat;
84  
#endif
84  
#endif
85  

85  

86  
#if defined(_MSC_VER) && _MSC_VER <= 1900
86  
#if defined(_MSC_VER) && _MSC_VER <= 1900
87  
# pragma warning( pop )
87  
# pragma warning( pop )
88  
#endif
88  
#endif
89  

89  

90  
} // detail
90  
} // detail
91  

91  

92  
} // capy
92  
} // capy
93  
} // boost
93  
} // boost