ipaddress 1.1.0
Loading...
Searching...
No Matches
ipv4-network.hpp
Go to the documentation of this file.
1/**
2 * @file ipv4-network.hpp
3 * @brief Provides a set of functions and classes for handling IPv4 networks
4 * @author Vladimir Shaleev
5 * @copyright MIT License
6 *
7 * This header file defines the ipv4_network_base class and ipv4_network type, which are
8 * part of a library for working with IPv4 network addresses. The ipv4_network_base class
9 * is derived from the base_v4 class and includes methods for manipulating network addresses.
10 * The ipv4_network is a typedef for the ip_network_base class specialized for IPv4,
11 * providing a convenient alias for users of the library.
12 */
13
14#ifndef IPADDRESS_IPV4_NETWORK_HPP
15#define IPADDRESS_IPV4_NETWORK_HPP
16
17#include "ipv4-address.hpp"
19
20namespace IPADDRESS_NAMESPACE {
21
22/**
23 * Base class for IPv4 network address manipulation.
24 *
25 * The ipv4_network_base class provides foundational functionality for IPv4 network
26 * address manipulation by extending the base_v4 class.
27 */
29public:
30 using ip_address_type = ipv4_address; /**< Alias for the IPv4 address type used within the class. */
31
32protected:
33 IPADDRESS_NODISCARD static IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE ip_address_type remove_scope_id(const ip_address_type& address) IPADDRESS_NOEXCEPT {
34 return address;
35 }
36
38 return network;
39 }
40}; // ipv4_network_base
41
42/**
43 * Alias for the specialized ip_network_base class for IPv4.
44 *
45 * The ipv4_network is a convenient alias for the ip_network_base class
46 * specialized with ipv4_network_base. It allows users to work with IPv4
47 * network addresses using a type that is specifically designed for IPv4,
48 * simplifying the interface and usage in code that deals with IPv4 networks.
49 */
51
52#ifdef IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
53
54 /**
55 * User-defined literal operator for creating an ipv4_network object from a string literal.
56 *
57 * This operator allows the creation of ipv4_network objects using a string literal with the
58 * `_ipv4_net` suffix.
59 *
60 * @tparam FixedString A string literal representing the IPv4 network.
61 * @return An ipv4_network object representing the network specified by the string literal.
62 */
63 IPADDRESS_EXPORT template <fixed_string FixedString>
64 IPADDRESS_NODISCARD IPADDRESS_CONSTEVAL IPADDRESS_FORCE_INLINE ipv4_network operator""_ipv4_net() IPADDRESS_NOEXCEPT {
65 return ipv4_network::parse<FixedString>();
66 }
67
68#else // IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
69
70 /**
71 * User-defined literal operator for creating an ipv4_network object from a string literal.
72 *
73 * This operator allows the creation of ipv4_network objects using a string literal with the
74 * `_ipv4_net` suffix.
75 *
76 * @param[in] address The string literal representing the IPv4 network.
77 * @param[in] size The size of the string literal.
78 * @return An ipv4_network object representing the network specified by the string literal.
79 */
80 IPADDRESS_EXPORT IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE ipv4_network operator""_ipv4_net(const char* address, size_t size) IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS {
81 return internal::parse_net_from_literal<ipv4_network_base, char, ipv4_network::base_max_string_len * 2 + 1>(address, size);
82 }
83
84 /**
85 * User-defined literal operator for creating an ipv4_network object from a wide string literal.
86 *
87 * This operator allows the creation of ipv4_network objects using a string literal with the
88 * `_ipv4_net` suffix.
89 *
90 * @param[in] address The string literal representing the IPv4 network.
91 * @param[in] size The size of the string literal.
92 * @return An ipv4_network object representing the network specified by the string literal.
93 */
94 IPADDRESS_EXPORT IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE ipv4_network operator""_ipv4_net(const wchar_t* address, size_t size) IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS {
95 return internal::parse_net_from_literal<ipv4_network_base, wchar_t, ipv4_network::base_max_string_len * 2 + 1>(address, size);
96 }
97
98 /**
99 * User-defined literal operator for creating an ipv4_network object from UTF-16 string literal.
100 *
101 * This operator allows the creation of ipv4_network objects using a string literal with the
102 * `_ipv4_net` suffix.
103 *
104 * @param[in] address The string literal representing the IPv4 network.
105 * @param[in] size The size of the string literal.
106 * @return An ipv4_network object representing the network specified by the string literal.
107 */
108 IPADDRESS_EXPORT IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE ipv4_network operator""_ipv4_net(const char16_t* address, size_t size) IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS {
109 return internal::parse_net_from_literal<ipv4_network_base, char16_t, ipv4_network::base_max_string_len * 2 + 1>(address, size);
110 }
111
112 /**
113 * User-defined literal operator for creating an ipv4_network object from UTF-32 string literal.
114 *
115 * This operator allows the creation of ipv4_network objects using a string literal with the
116 * `_ipv4_net` suffix.
117 *
118 * @param[in] address The string literal representing the IPv4 network.
119 * @param[in] size The size of the string literal.
120 * @return An ipv4_network object representing the network specified by the string literal.
121 */
122 IPADDRESS_EXPORT IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS IPADDRESS_CONSTEXPR IPADDRESS_FORCE_INLINE ipv4_network operator""_ipv4_net(const char32_t* address, size_t size) IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS {
123 return internal::parse_net_from_literal<ipv4_network_base, char32_t, ipv4_network::base_max_string_len * 2 + 1>(address, size);
124 }
125
126#endif // IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
127
128} // namespace IPADDRESS_NAMESPACE
129
130#endif // IPADDRESS_IPV4_NETWORK_HPP
Template base class for representing a network of IP addresses.
Definition ip-network-base.hpp:32
Base class for IPv4 network address manipulation.
Definition ipv4-network.hpp:28
#define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS
Definition config.hpp:93
#define IPADDRESS_EXPORT
Definition config.hpp:42
#define IPADDRESS_NODISCARD
Definition config.hpp:98
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:112
#define IPADDRESS_NAMESPACE
Definition config.hpp:38
#define IPADDRESS_NOEXCEPT
Definition config.hpp:89
#define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS
Definition config.hpp:102