src/cond.cpp
69.2% Lines (18/26)
100.0% List of functions (3/3)
63.2% Branches (12/19)
Functions (3)
Function
Calls
Lines
Branches
Blocks
boost::capy::detail::cond_cat_type::name() const
:20
1x
100.0%
–
100.0%
boost::capy::detail::cond_cat_type::message[abi:cxx11](int) const
:27
3x
62.5%
60.0%
43.0%
boost::capy::detail::cond_cat_type::equivalent(std::error_code const&, int) const
:42
1328x
68.8%
66.7%
76.0%
| Line | Branch | 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 | 3x | cond_cat_type:: | ||
| 28 | message(int code) const | |||
| 29 | { | |||
| 30 |
3/5✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
3x | switch(static_cast<cond>(code)) | |
| 31 | { | |||
| 32 |
1/1✓ Branch 1 taken 1 time.
|
3x | case cond::eof: return "end of file"; | |
| 33 |
1/1✓ Branch 1 taken 1 time.
|
3x | case cond::canceled: return "operation canceled"; | |
| 34 | ✗ | case cond::stream_truncated: return "stream truncated"; | ||
| 35 |
1/1✓ Branch 1 taken 1 time.
|
3x | case cond::not_found: return "not found"; | |
| 36 | ✗ | default: | ||
| 37 | ✗ | return "unknown"; | ||
| 38 | } | |||
| 39 | } | |||
| 40 | ||||
| 41 | bool | |||
| 42 | 1328x | cond_cat_type:: | ||
| 43 | equivalent( | |||
| 44 | std::error_code const& ec, | |||
| 45 | int condition) const noexcept | |||
| 46 | { | |||
| 47 |
3/5✓ Branch 0 taken 1309 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
|
1328x | switch(static_cast<cond>(condition)) | |
| 48 | { | |||
| 49 | 1309x | case cond::eof: | ||
| 50 | 1309x | return ec == capy::error::eof; | ||
| 51 | ||||
| 52 | 5x | case cond::canceled: | ||
| 53 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5x | if(ec == capy::error::canceled) | |
| 54 | ✗ | return true; | ||
| 55 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
|
5x | if(ec == std::errc::operation_canceled) | |
| 56 | 2x | return true; | ||
| 57 | 3x | return false; | ||
| 58 | ||||
| 59 | ✗ | case cond::stream_truncated: | ||
| 60 | ✗ | return ec == capy::error::stream_truncated; | ||
| 61 | ||||
| 62 | 14x | case cond::not_found: | ||
| 63 | 14x | return ec == capy::error::not_found; | ||
| 64 | ||||
| 65 | ✗ | default: | ||
| 66 | ✗ | return false; | ||
| 67 | } | |||
| 68 | } | |||
| 69 | ||||
| 70 | //----------------------------------------------- | |||
| 71 | ||||
| 72 | // msvc 14.0 has a bug that warns about inability | |||
| 73 | // to use constexpr construction here, even though | |||
| 74 | // there's no constexpr construction | |||
| 75 | #if defined(_MSC_VER) && _MSC_VER <= 1900 | |||
| 76 | # pragma warning( push ) | |||
| 77 | # pragma warning( disable : 4592 ) | |||
| 78 | #endif | |||
| 79 | ||||
| 80 | #if defined(__cpp_constinit) && __cpp_constinit >= 201907L | |||
| 81 | constinit cond_cat_type cond_cat; | |||
| 82 | #else | |||
| 83 | cond_cat_type cond_cat; | |||
| 84 | #endif | |||
| 85 | ||||
| 86 | #if defined(_MSC_VER) && _MSC_VER <= 1900 | |||
| 87 | # pragma warning( pop ) | |||
| 88 | #endif | |||
| 89 | ||||
| 90 | } // detail | |||
| 91 | ||||
| 92 | } // capy | |||
| 93 | } // boost | |||
| 94 |