Skip to content

Commit 602cdce

Browse files
committed
IpAddresses: Adding contains and remove functions (#23)
1 parent 1de6658 commit 602cdce

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

common/ipaddresses.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ void IpAddresses::add(const IpAddress &ip)
2828
m_ips.insert(ip);
2929
}
3030

31+
bool IpAddresses::contains(const std::string &ipStr)
32+
{
33+
IpAddress ip(ipStr);
34+
return m_ips.find(ip) != m_ips.end();
35+
}
36+
37+
bool IpAddresses::contains(const IpAddress &ip)
38+
{
39+
return m_ips.find(ip) != m_ips.end();
40+
}
41+
42+
void IpAddresses::remove(const string &ipStr)
43+
{
44+
IpAddress ip(ipStr);
45+
m_ips.erase(ip);
46+
}
47+
48+
void IpAddresses::remove(const IpAddress &ip)
49+
{
50+
m_ips.erase(ip);
51+
}
52+
3153
const string IpAddresses::to_string() const
3254
{
3355
string ips_str;

common/ipaddresses.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ class IpAddresses
4444

4545
void add(const IpAddress &ip);
4646

47+
bool contains(const std::string &ip);
48+
49+
bool contains(const IpAddress &ip);
50+
51+
void remove(const std::string &ip);
52+
53+
void remove(const IpAddress &ip);
54+
4755
const std::string to_string() const;
4856

4957

0 commit comments

Comments
 (0)