Thermal Camera SDK 11.3.0
SDK for Optris Thermal Cameras
Loading...
Searching...
No Matches
IpAddress.h
Go to the documentation of this file.
1// Copyright (c) 2008-2026 Optris GmbH & Co. KG
2
10
11#pragma once
12
13#include <array>
14#include <ostream>
15#include <cstdint>
16#include <string>
17
18#include "otcsdk/Api.h"
19#include "otcsdk/Exceptions.h"
20
21
22namespace optris
23{
24
33{
34public:
41
47 OTC_SDK_API IpAddress(std::uint32_t address) noexcept;
48
56 OTC_SDK_API IpAddress(const std::string& address);
57
66 OTC_SDK_API IpAddress(std::uint8_t a, std::uint8_t b, std::uint8_t c, std::uint8_t d) noexcept;
67
68
71
79 OTC_SDK_API void setFromUInt32(std::uint32_t address) noexcept;
80
88 OTC_SDK_API std::uint32_t toUInt32() const noexcept;
89
97 OTC_SDK_API void setFromString(const std::string& address);
98
108 OTC_SDK_API int setFromCidrString(const std::string& address);
109
115 OTC_SDK_API std::string toString() const noexcept;
116
124 OTC_SDK_API std::string toCidrString(int cidr) const noexcept;
125
134 OTC_SDK_API void setByte(int index, std::uint8_t value);
135
145 OTC_SDK_API std::uint8_t getByte(int index) const;
146
154 OTC_SDK_API IpAddress getNetworkPortion(const IpAddress& subnetMask) const noexcept;
155
166
174 OTC_SDK_API IpAddress getHostPortion(const IpAddress& subnetMask) const noexcept;
175
186
194 OTC_SDK_API IpAddress getBroadcastAddress(const IpAddress& subnetMask) const noexcept;
195
206
207
215 bool operator==(const IpAddress& rhs) const noexcept;
216
224 bool operator==(std::uint32_t rhs) const noexcept;
225
233 bool operator!=(const IpAddress& rhs) const noexcept;
234
244 bool operator<(const IpAddress& rhs) const noexcept;
245
246
247private:
249 std::array<std::uint8_t, 4> _bytes;
250
251
261 static std::uint32_t cidrToUInt32(int cidr);
262};
263
264
265// Utility functions
274OTC_SDK_API std::ostream& operator<<(std::ostream& out, const IpAddress& address);
275
276
277// Inline implementations
278inline bool IpAddress::operator==(const IpAddress& rhs) const noexcept
279{
280 return _bytes == rhs._bytes;
281}
282
283inline bool IpAddress::operator==(std::uint32_t rhs) const noexcept
284{
285 return toUInt32() == rhs;
286}
287
288inline bool IpAddress::operator!=(const IpAddress& rhs) const noexcept
289{
290 return !(_bytes == rhs._bytes);
291}
292
293inline bool IpAddress::operator<(const IpAddress& rhs) const noexcept
294{
295 return toUInt32() < rhs.toUInt32();
296}
297
298} // namespace optris
Contains defines controlling the Windows DLL export and import of symbols.
#define OTC_SDK_API
Only needed when working with Windows DLLs.
Definition Api.h:65
Contains the exceptions raised by the SDK.
Encapsulates an IP v4 address.
Definition IpAddress.h:33
bool operator==(const IpAddress &rhs) const noexcept
Returns whether this IP address equals the provided one.
Definition IpAddress.h:278
OTC_SDK_API void setFromUInt32(std::uint32_t address) noexcept
Sets the address from an unsigned 32 bit integer in network byte order.
OTC_SDK_API int setFromCidrString(const std::string &address)
Sets the address from a string in classless inter-domain routing (CIDR) notation (a....
OTC_SDK_API IpAddress getBroadcastAddress(const IpAddress &subnetMask) const noexcept
Returns the broadcast address for this IP address with the given subnet mask.
OTC_SDK_API std::uint8_t getByte(int index) const
Returns the value of the byte with the given index.
OTC_SDK_API void reset()
Resets all the bytes of the IP address to 0 (0.0.0.0).
OTC_SDK_API void setByte(int index, std::uint8_t value)
Sets the value of the byte with the given index.
OTC_SDK_API void setFromString(const std::string &address)
Sets the address from a string in dot notation (a.b.c.d).
OTC_SDK_API IpAddress() noexcept
Constructor.
bool operator<(const IpAddress &rhs) const noexcept
Returns whether this IP address has a smaller unsigned 32 bit integer representation than the provide...
Definition IpAddress.h:293
OTC_SDK_API std::string toString() const noexcept
Returns the address as a string in dot notation (a.b.c.d).
OTC_SDK_API std::string toCidrString(int cidr) const noexcept
Returns the address as a string in classless inter-domain routing (CIDR) notation (a....
OTC_SDK_API std::uint32_t toUInt32() const noexcept
Returns the address as an unsigned 32 bit integer in network byte order.
OTC_SDK_API IpAddress getHostPortion(const IpAddress &subnetMask) const noexcept
Returns the host portion of the IP address according to the given subnet mask.
bool operator!=(const IpAddress &rhs) const noexcept
Returns whether this IP address is different from the provided one.
Definition IpAddress.h:288
OTC_SDK_API IpAddress getNetworkPortion(const IpAddress &subnetMask) const noexcept
Returns the network portion of the IP address according to the given subnet mask.
Main SDK namespace.
Definition AlarmChannel.h:21