-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIpAddress.cpp
More file actions
60 lines (50 loc) · 1.25 KB
/
Copy pathIpAddress.cpp
File metadata and controls
60 lines (50 loc) · 1.25 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
#include "IpAddress.h"
#include <iostream>
#include <stdexcept>
IPAddress::IPAddress() : iPAddress({ 0, 0, 0, 0 })
{
}
IPAddress::IPAddress(int a, int b, int c, int d) : iPAddress({ a, b, c, d })
{
}
int IPAddress::at(int index) const
{
if (index >= 0 && index < 4)
return iPAddress[index];
else
throw std::out_of_range("Index out of range");
}
int IPAddress::operator[](int index) const
{
if (index >= 0 && index < 4)
return iPAddress[index];
else
throw std::out_of_range("Index out of range");
}
int& IPAddress::operator[](int index)
{
if (index >= 0 && index < 4)
return iPAddress[index];
else
throw std::out_of_range("Index out of range");
}
std::array<int, 4>::iterator IPAddress::begin()
{
return iPAddress.begin();
}
std::array<int, 4>::iterator IPAddress::end()
{
return iPAddress.end();
}
std::array<int, 4>::const_iterator IPAddress::cbegin() const
{
return iPAddress.begin();
}
std::array<int, 4>::const_iterator IPAddress::cend() const
{
return iPAddress.end();
}
void IPAddress::print() const
{
std::cout << iPAddress[0] << "." << iPAddress[1] << "." << iPAddress[2] << "." << iPAddress[3] << std::endl;
}