Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1095d71e5d961b532c150a3f76b0863ef5fa1256 (plain) (blame)
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
79
80
81
82
83
84
85
/*******************************************************************************
 * Copyright (c) 2012 Draeger Medical GmbH (http://www.draeger.com).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * CONTRIBUTORS:
 * 		Peter Karlitschek (initial contribution)
 *
 *******************************************************************************/

#include "common/messaging/Address.h"
#include <string>

namespace etRuntime {

const Address Address::EMPTY(0, 0, 0);

Address::Address() :
	m_nodeID(0),
	m_threadID(0),
	m_objectID(0) {
}

Address::Address(int nodeID, int threadID, int objectID) :
		m_nodeID(nodeID),
		m_threadID(threadID),
		m_objectID(objectID) {
}

Address::Address(const Address & right) :
		m_nodeID(right.m_nodeID),
		m_threadID(right.m_threadID),
		m_objectID(right.m_objectID) {
}

Address::~Address() {
	*this = EMPTY;
}

Address& Address::operator=(const Address& right) {
	if (this != &right) {
		m_nodeID = right.m_nodeID;
		m_threadID = right.m_threadID;
		m_objectID = right.m_objectID;
	}
	return *this;
}

bool Address::operator==(const Address& right) const {
	return m_nodeID == right.m_nodeID && m_threadID == right.m_threadID && m_objectID == right.m_objectID;
}

bool Address::operator!=(const Address& right) const {
	return !(*this == right);
}

// needed for ordered containers e.g. std::map
bool Address::operator<(const Address& right) const {
	if (m_nodeID == right.m_nodeID) {
		if (m_threadID == right.m_threadID) {
			return (m_objectID < right.m_objectID);
		}
		else {
			return (m_threadID < right.m_threadID);
		}
	}
	else {
		return (m_nodeID < right.m_nodeID);
	}
}

std::string Address::toID() const {
	char buffer[50];
	sprintf(buffer, "%i_%i_%i", m_nodeID, m_threadID, m_objectID);

	return std::string(buffer);
}

Address Address::createInc() const {
	return Address(m_nodeID, m_threadID, m_objectID + 1);
}

} /* namespace etRuntime */

Back to the top