-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstanceHandle.h
188 lines (151 loc) · 4.66 KB
/
InstanceHandle.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#ifndef BaseLib_InstanceHandle_h_IsIncluded
#define BaseLib_InstanceHandle_h_IsIncluded
#include"BaseLib/CommonDefines.h"
#include"BaseLib/Export.h"
namespace BaseLib
{
typedef HANDLE_TYPE_NATIVE InstanceHandleType;
const InstanceHandleType HANDLE_NIL = HANDLE_NIL_NATIVE;
/* --------------------------------------------------------------
Type used to represent the identity of a data-object whose
changes in value are communicated by the RTPS protocol.
In DDS, the value of the fields labeled as key within the
data uniquely identify each data-object.
In RTPS::Cache::HistoryCache: Identifies the instance of the
data-object to which the change applies.
----------------------------------------------------------------*/
class DLL_STATE InstanceHandle
{
public:
InstanceHandle(InstanceHandleType handle = HANDLE_NIL);
virtual ~InstanceHandle();
public:
InstanceHandleType GetHandle() const { return handle_; }
void SetHandle(const InstanceHandleType &handle) { handle_ = handle; }
public:
// ------------------------------------------------
// Convenience Functions
// ------------------------------------------------
InstanceHandle GetPrevious() const
{
return InstanceHandle(handle_ - 1);
}
InstanceHandle GetNext() const
{
return InstanceHandle(handle_ + 1);
}
bool IsNil() const
{
return handle_ == HANDLE_NIL;
}
public:
// ------------------------------------------------
// operator manipulations
// ------------------------------------------------
// Pre-increment
InstanceHandle& operator++()
{
this->handle_++;
return *this;
}
// Post-increment
InstanceHandle operator++(int)
{
InstanceHandle result(*this);
++(*this);
return result;
}
// Pre-decrement
InstanceHandle& operator--()
{
this->handle_--;
return *this;
}
// Post-decrement
InstanceHandle operator--(int)
{
InstanceHandle result(*this);
--(*this);
return result;
}
InstanceHandle& operator+=(const InstanceHandle &other)
{
this->handle_ = this->handle_ + other.handle_;
return *this;
}
InstanceHandle operator+(const InstanceHandle &other) const
{
return InstanceHandle(*this) += other;
}
public:
// ------------------------------------------------
// operator comparisons
// ------------------------------------------------
bool operator==(const InstanceHandle &rvalue) const
{
return this->handle_ == rvalue.handle_;
}
bool operator!=(const InstanceHandle &rvalue) const
{
return this->handle_ != rvalue.handle_;
}
bool operator<(const InstanceHandle &rvalue) const
{
return this->handle_ < rvalue.handle_;
}
bool operator<=(const InstanceHandle &rvalue) const
{
return this->handle_ <= rvalue.handle_;
}
bool operator>(const InstanceHandle &rvalue) const
{
return this->handle_ > rvalue.handle_;
}
bool operator>=(const InstanceHandle &rvalue) const
{
return this->handle_ >= rvalue.handle_;
}
public:
friend std::ostream& operator<<(std::ostream &ostr, const BaseLib::InstanceHandle &handle)
{
ostr << handle.GetHandle();
return ostr;
}
public:
// ------------------------------------------------
// static functions
// ------------------------------------------------
static InstanceHandle NIL()
{
static InstanceHandle handle(HANDLE_NIL);
return handle;
}
static unsigned int SIZE()
{
static unsigned int elementSize = 4; // long = 4 bytes
return elementSize;
}
static InstanceHandle GenerateNext(const InstanceHandle &prev)
{
InstanceHandle next(prev.GetNext());
return next;
}
static InstanceHandle Create(InstanceHandleType handle)
{
return InstanceHandle(handle);
}
private:
InstanceHandleType handle_;
};
//typedef std::vector<InstanceHandleType> InstanceHandleTypeSeq;
typedef std::vector<InstanceHandle> InstanceHandleSeq;
typedef std::set<InstanceHandle> InstanceHandleSet;
DLL_STATE std::ostream& operator<<(std::ostream &ostr, const BaseLib::InstanceHandleSeq &handleSeq);
DLL_STATE std::ostream& operator<<(std::ostream &ostr, const BaseLib::InstanceHandleSet &handleSeq);
} // namespace BaseLib
//DLL_STATE inline std::ostream& operator<<(std::ostream &ostr, const BaseLib::InstanceHandle &handle)
//{
// ostr << handle.GetHandle();
// return ostr;
//}
#endif // BaseLib_InstanceHandle_h_IsIncluded