forked from sonic-net/sonic-swss-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipaddresses.cpp
More file actions
78 lines (63 loc) · 1.31 KB
/
Copy pathipaddresses.cpp
File metadata and controls
78 lines (63 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "ipaddresses.h"
#include "tokenize.h"
#include <sstream>
using namespace std;
using namespace swss;
#define IP_DELIMITER ','
IpAddresses::IpAddresses(const string &ipsStr)
{
auto ips = tokenize(ipsStr, IP_DELIMITER);
for (const auto &ip : ips)
m_ips.insert(ip);
}
void IpAddresses::add(const string &ipStr)
{
IpAddress ip(ipStr);
m_ips.insert(ip);
}
void IpAddresses::add(const IpAddress &ip)
{
m_ips.insert(ip);
}
bool IpAddresses::contains(const std::string &ipStr) const
{
IpAddress ip(ipStr);
return m_ips.find(ip) != m_ips.end();
}
bool IpAddresses::contains(const IpAddress &ip) const
{
return m_ips.find(ip) != m_ips.end();
}
bool IpAddresses::contains(const IpAddresses &ips) const
{
for (auto ip : ips.getIpAddresses())
{
if (!contains(ip))
{
return false;
}
}
return true;
}
void IpAddresses::remove(const string &ipStr)
{
IpAddress ip(ipStr);
m_ips.erase(ip);
}
void IpAddresses::remove(const IpAddress &ip)
{
m_ips.erase(ip);
}
const string IpAddresses::to_string() const
{
string ips_str;
for (auto it = m_ips.begin(); it != m_ips.end(); ++it)
{
if (it != m_ips.begin())
{
ips_str += ",";
}
ips_str += it->to_string();
}
return ips_str;
}