src/corosio/src/ip_address.cpp
100.0% Lines (14/14)
100.0% List of functions (3/3)
100.0% Branches (11/11)
Functions (3)
Function
Calls
Lines
Branches
Blocks
boost::corosio::ip_address::to_buffer(char*, unsigned long long) const
:19
3x
100.0%
100.0%
91.7%
boost::corosio::operator<<(std::ostream&, boost::corosio::ip_address const&)
:30
2x
100.0%
100.0%
100.0%
boost::corosio::make_ip_address(std::basic_string_view<char, std::char_traits<char> >)
:36
37x
100.0%
100.0%
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2026 Vinnie Falco ([email protected]) | |||
| 3 | // Copyright (c) 2026 Steve Gerbino | |||
| 4 | // | |||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 7 | // | |||
| 8 | // Official repository: https://github.com/cppalliance/corosio | |||
| 9 | // | |||
| 10 | ||||
| 11 | #include <boost/corosio/ip_address.hpp> | |||
| 12 | ||||
| 13 | #include <ostream> | |||
| 14 | #include <stdexcept> | |||
| 15 | ||||
| 16 | namespace boost::corosio { | |||
| 17 | ||||
| 18 | std::string_view | |||
| 19 | 3x | ip_address::to_buffer(char* dest, std::size_t dest_size) const | ||
| 20 | { | |||
| 21 | // Uniform capacity requirement: a v4 value in an ip_address | |||
| 22 | // still requires the family-independent max_str_len. | |||
| 23 |
2/2✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 2 times.
|
3x | if (dest_size < max_str_len) | |
| 24 |
1/1✓ Branch 4 → 5 taken 1 time.
|
1x | throw std::length_error("buffer too small for IP address"); | |
| 25 |
2/2✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 1 time.
|
2x | return is_v4() ? v4_.to_buffer(dest, dest_size) | |
| 26 | 2x | : v6_.to_buffer(dest, dest_size); | ||
| 27 | } | |||
| 28 | ||||
| 29 | std::ostream& | |||
| 30 | 2x | operator<<(std::ostream& os, ip_address const& addr) | ||
| 31 | { | |||
| 32 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 1 time.
|
2x | return addr.is_v4() ? os << addr.v4_ : os << addr.v6_; | |
| 33 | } | |||
| 34 | ||||
| 35 | capy::io_result<ip_address> | |||
| 36 | 37x | make_ip_address(std::string_view s) noexcept | ||
| 37 | { | |||
| 38 |
2/2✓ Branch 6 → 7 taken 9 times.
✓ Branch 6 → 11 taken 28 times.
|
37x | if (auto [ec, v4] = make_ipv4_address(s); !ec) | |
| 39 | 9x | return {std::error_code{}, ip_address(v4)}; | ||
| 40 | 28x | auto [ec, v6] = make_ipv6_address(s); | ||
| 41 |
2/2✓ Branch 15 → 16 taken 11 times.
✓ Branch 15 → 19 taken 17 times.
|
28x | if (ec) | |
| 42 | 11x | return {ec, ip_address{}}; | ||
| 43 | 17x | return {std::error_code{}, ip_address(v6)}; | ||
| 44 | } | |||
| 45 | ||||
| 46 | } // namespace boost::corosio | |||
| 47 |