Thermal Camera SDK 10.1.1
SDK for Optris Thermal Cameras
Loading...
Searching...
No Matches
IpAddress.h
Go to the documentation of this file.
1// Copyright (c) 2008-2025 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
209 bool operator==(const IpAddress& rhs) const noexcept;
211 bool operator==(std::uint32_t rhs) const noexcept;
213 bool operator!=(const IpAddress& rhs) const noexcept;
215 bool operator<(const IpAddress& rhs) const noexcept;
216
217
218private:
220 std::array<std::uint8_t, 4> _bytes;
221
222
232 static std::uint32_t cidrToUInt32(int cidr);
233};
234
235
236// Utility functions
245OTC_SDK_API std::ostream& operator<<(std::ostream& out, const IpAddress& address);
246
247
248// Inline implementations
249inline bool IpAddress::operator==(const IpAddress& rhs) const noexcept
250{
251 return _bytes == rhs._bytes;
252}
253
254inline bool IpAddress::operator==(std::uint32_t rhs) const noexcept
255{
256 return toUInt32() == rhs;
257}
258
259inline bool IpAddress::operator!=(const IpAddress& rhs) const noexcept
260{
261 return !(_bytes == rhs._bytes);
262}
263
264inline bool IpAddress::operator<(const IpAddress& rhs) const noexcept
265{
266 return toUInt32() < rhs.toUInt32();
267}
268
269} // 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
Equality operator.
Definition IpAddress.h:249
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
Less than operator.
Definition IpAddress.h:264
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
Unequality operator.
Definition IpAddress.h:259
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 DeviceInfo.h:24