3#include "../../global.hpp"
4#include "../../string.hpp"
18 inline uint32_t IPV4AddressStringToInt(
const std::string &ip)
20 std::istringstream iss(ip);
23 for (
int i = 0; i < 4; ++i)
27 if (iss.fail() || part > 255)
28 throw std::runtime_error(
"Invalid IP address");
30 ipv4 |= part << (8 * (3 - i));
36 if (iss.fail() || delimiter !=
'.')
37 throw std::runtime_error(
"Invalid IP address");
44 inline std::string IPV4AddressIntToString(uint32_t ip)
46 std::ostringstream oss;
47 oss << ((ip & 0xFF000000) >> 24) <<
'.'
48 << ((ip & 0x00FF0000) >> 16) <<
'.'
49 << ((ip & 0x0000FF00) >> 8) <<
'.'
55 class MacAddress final
65 explicit MacAddress(int64_t addr)
noexcept
71 explicit MacAddress(
const String &addr) noexcept
78 explicit MacAddress(
const QString &addr) noexcept
84 bool operator==(
const MacAddress &addr)
const noexcept
86 return (address_ == addr.address_);
89 bool operator!=(
const MacAddress &addr)
const noexcept
91 return !(*
this == addr);
106 if (address_.isEmpty())
114 return !(ToInt64() == 0);
117 void SetDelimiter(
const MacDelimiter delimiter)
119 separator_ = delimiter;
122 MacDelimiter Delimiter()
130 QRegularExpression rx(macRegExp);
131 auto match = rx.match(address_);
132 if (!match.hasMatch())
133 address_ = defaultAddress_;
138 void ChangeSeparator()
140 if (address_.count(Separator()) == 5)
147 address_.replace(
'-',
':');
151 address_.replace(
':',
'-');
157 void Convert(int64_t value)
159 auto tmp = QString(
"%1").arg(value, 8, 16, QLatin1Char(
'0'));
160 auto pos = tmp.size() - 2;
164 tmp.insert(pos, Separator());
170 tmp.insert(0, Separator()).insert(0,
"00");
179 tmp.remove(
':').remove(
'-');
181 return static_cast<int64_t
>(tmp.toLongLong(&valid, 16));
186 if (separator_ == Colon)
192 const QString defaultAddress_ =
"00-00-00-00-00-00";
193 MacDelimiter separator_ = Minus;
194 const QString macRegExp =
"([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})";
Namespace for user interface components.
Definition decl_image_scene.hpp:39
Cvb::String QtToCvb(const QString text) noexcept
Convenience converter for strings.
Definition ui.hpp:242
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition ui.hpp:257
Root namespace for the Image Manager interface.
Definition version.hpp:11
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49