src/cond.cpp
72.4% Lines (21/29)
100.0% Functions (3/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 | 4x | cond_cat_type:: | |
| 28 | message(int code) const | ||
| 29 | { | ||
| 30 | 4x | switch(static_cast<cond>(code)) | |
| 31 | { | ||
| 32 | 3x | case cond::eof: return "end of file"; | |
| 33 | 3x | case cond::canceled: return "operation canceled"; | |
| 34 | ✗ | case cond::stream_truncated: return "stream truncated"; | |
| 35 | 3x | case cond::not_found: return "not found"; | |
| 36 | 3x | case cond::timeout: return "operation timed out"; | |
| 37 | ✗ | default: | |
| 38 | ✗ | return "unknown"; | |
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | bool | ||
| 43 | 1395x | cond_cat_type:: | |
| 44 | equivalent( | ||
| 45 | std::error_code const& ec, | ||
| 46 | int condition) const noexcept | ||
| 47 | { | ||
| 48 | 1395x | switch(static_cast<cond>(condition)) | |
| 49 | { | ||
| 50 | 1373x | case cond::eof: | |
| 51 | 1373x | return ec == capy::error::eof; | |
| 52 | |||
| 53 | 6x | case cond::canceled: | |
| 54 | 6x | if(ec == capy::error::canceled) | |
| 55 | ✗ | return true; | |
| 56 | 6x | if(ec == std::errc::operation_canceled) | |
| 57 | 2x | return true; | |
| 58 | 4x | return false; | |
| 59 | |||
| 60 | ✗ | case cond::stream_truncated: | |
| 61 | ✗ | return ec == capy::error::stream_truncated; | |
| 62 | |||
| 63 | 14x | case cond::not_found: | |
| 64 | 14x | return ec == capy::error::not_found; | |
| 65 | |||
| 66 | 2x | case cond::timeout: | |
| 67 | 2x | return ec == capy::error::timeout; | |
| 68 | |||
| 69 | ✗ | default: | |
| 70 | ✗ | 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 | ||
| 98 |