-
Notifications
You must be signed in to change notification settings - Fork 16
/
Node.Tc
57 lines (47 loc) · 1.42 KB
/
Node.Tc
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
#include "Node.h"
Node::Node() {}
Node::~Node() {}
Node::Node(rpc_node newnode) {
set_from_rpc_node(newnode);
}
Node::Node(string newip, unsigned int newport, ID_Value newid) :
ip(newip), port(newport), id(newid) {}
rpc_node Node::get_rpc_node() {
rpc_node ret;
ret.ip = ip.c_str();
ret.id = id.get_rpc_id();
ret.port = port;
return ret;
}
void Node::set_from_rpc_node(rpc_node newnode) {
ip = newnode.ip;
ID_Value newid(newnode.id);
id = newid;
port = newnode.port;
}
void Node::set_from_string(string s) {
istringstream iss(s, istringstream::in);
iss >> ip;
iss >> port;
string id_str;
iss >> id_str;
id.fromString(id_str);
}
const string Node::toString() const {
ostringstream ss;
ss << "(" << ip
<< ":" << port
<< " - " << id.toString()
<< ")";
return ss.str();
}
string Node::getIp() { return ip; }
unsigned int Node::getPort() { return port; }
ID_Value Node::getId() const { return id; }
void Node::setIp(string newip) { ip = newip; }
void Node::setPort(unsigned int newport) { port = newport; }
void Node::setId(ID_Value newid) { id = newid; }
bool Node::operator == (const Node &other) const { return (other.getId() == this->getId()); }
bool Node::operator != (const Node &other) const { return !(*this == other); }
bool Node::operator < (const Node &other) const { return (other.getId() < this->getId()); }
bool Node::operator > (const Node &other) const { return (other.getId() > this->getId()); }