Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
CIDR.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
6
7 /*
8 ********************************************************************************
9 ******************************** Netowrk::CIDR *********************************
10 ********************************************************************************
11 */
12 inline CIDR::CIDR (const InternetAddress& internetAddress, optional<unsigned int> significantBits)
13 : CIDR{internetAddress, significantBits.value_or (static_cast<unsigned int> (*internetAddress.GetAddressSize () * 8))}
14 {
15 Require (internetAddress.GetAddressFamily () == InternetAddress::AddressFamily::V4 or
16 internetAddress.GetAddressFamily () == InternetAddress::AddressFamily::V6);
17 }
18 inline InternetAddress CIDR::GetBaseInternetAddress () const
19 {
20 return fBaseAddress_;
21 }
22 inline unsigned int CIDR::GetNumberOfSignificantBits () const
23 {
24 return fSignificantBits_;
25 }
26 inline strong_ordering CIDR::operator<=> (const CIDR& rhs) const
27 {
28 /*
29 * NOTE, while it may not make alot of sense for fSignificantBits_ to be the primary part of the default sort key
30 * the reason for this choice is that the part where we compare the base address doesn't make much sense
31 * except when the significant bits on both sides agree.
32 *
33 * Well, suppose not true. COULD just use 'less' or 'greater' of the two sigbits, and compare the other first. Would only
34 * end up with equal after comparing both, so maybe that would still make sense.
35 */
36 strong_ordering r = fSignificantBits_ <=> rhs.fSignificantBits_;
37 if (r == 0) {
38 return fBaseAddress_.KeepSignificantBits (fSignificantBits_) <=> rhs.fBaseAddress_.KeepSignificantBits (fSignificantBits_);
39 }
40 else {
41 return r;
42 }
43 }
44 inline bool CIDR::operator== (const CIDR& rhs) const
45 {
46 return fSignificantBits_ == rhs.fSignificantBits_ and
47 fBaseAddress_.KeepSignificantBits (fSignificantBits_) == rhs.fBaseAddress_.KeepSignificantBits (fSignificantBits_);
48 }
49
50}