PLCnext API Documentation 23.6.0.37
IpAddress.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8
9namespace Arp { namespace System { namespace Commons { namespace Net
10{
11
14{
15public: // typedefs
16
19
20public: // construction/destruction
22 IpAddress(void) = default;
23
26 IpAddress(uint32 ip4address);
27
29 IpAddress(const IpAddress& arg) = default;
30
32 IpAddress& operator=(const IpAddress& arg) = default;
33
35 ~IpAddress(void) = default;
36
37public: // operators
38
41 void operator=(Arp::uint32 ip4Address);
42
43public: // static properties
44 static IpAddress Empty;
45
46public: // static operations
47
52 static IpAddress Parse(const String& input);
53
58 static bool TryParse(const String& input, IpAddress& result);
59
60public: // setter/getter operations
63 bool IsEmpty(void)const;
64
67 IpV4Value GetIpv4Value(void)const;
68
69public: // operations
70 String ToString(void)const;
71
72private: // static methods
73 static bool IsLocalhostString(const String& input);
74
75private: // fields
76 IpV4Value ipV4Value = 0;
77
78private: // static fields
79 static const char* localhostString1;
80 static const char* localhostString2;
81 static const char* localhostString3;
82 static const char* localhostAddress;
83};
84
86// inline methods of class IpAddress
87inline IpAddress::IpAddress(uint32 ip4Address) : ipV4Value(ip4Address)
88{
89}
90
91inline bool IpAddress::IsEmpty()const
92{
93 return this->ipV4Value == 0;
94}
95
97{
98 return this->ipV4Value;
99}
100
101inline void IpAddress::operator=(Arp::uint32 ip4Address)
102{
103 this->ipV4Value = ip4Address;
104}
105
107inline std::ostream& operator<<(std::ostream& os, const IpAddress& ipAddress)
108{
109 os << ipAddress.ToString();
110 return os;
111}
112
114inline std::istream& operator>>(std::istream& is, IpAddress& ipAddress)
115{
116 std::string s;
117 is >> s;
118 ipAddress = IpAddress::Parse(s);
119 return is;
120}
121
122}}}} // end of namespace Arp::System::Commons::Net
Unified representation for ip address schemes.
Definition: IpAddress.hpp:14
static IpAddress Parse(const String &input)
Parses an ip address from string bases representation, e.g. "127.0.0.1".
IpAddress & operator=(const IpAddress &arg)=default
Assignment operator.
~IpAddress(void)=default
Destructs this instance and frees all resources.
IpV4Value GetIpv4Value(void) const
Returns the ip address in ip v4 address scheme.
Definition: IpAddress.hpp:96
IpAddress(void)=default
Constructs an IpAddress instance.
IpAddress(const IpAddress &arg)=default
Copy constructor.
uint32 IpV4Value
Value-type-definition for ip addresses using version 4 scheme.
Definition: IpAddress.hpp:18
bool IsEmpty(void) const
Determines if this instance is empty, e.g. the address value is zero.
Definition: IpAddress.hpp:91
static bool TryParse(const String &input, IpAddress &result)
Tries to parse an address from string based representation.
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:36
std::ostream & operator<<(std::ostream &os, const IpAddress &ipAddress)
The ostream operator is used for logging and string formatting.
Definition: IpAddress.hpp:107
std::istream & operator>>(std::istream &is, IpAddress &ipAddress)
The istream operator is used for string parsing.
Definition: IpAddress.hpp:114
Root namespace for the PLCnext API