Nebula
Loading...
Searching...
No Matches
keyvaluepair.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13#include "core/types.h"
14
15//------------------------------------------------------------------------------
16namespace Util
17{
18template<class KEYTYPE, class VALUETYPE> class KeyValuePair
19{
20public:
24 KeyValuePair(const KEYTYPE& k, const VALUETYPE& v);
26 explicit KeyValuePair(const KEYTYPE& k);
48 bool operator==(const KEYTYPE& rhs) const;
50 bool operator!=(const KEYTYPE& rhs) const;
52 bool operator>(const KEYTYPE& rhs) const;
54 bool operator>=(const KEYTYPE& rhs) const;
56 bool operator<(const KEYTYPE& rhs) const;
58 bool operator<=(const KEYTYPE& rhs) const;
60 VALUETYPE& Value();
62 const KEYTYPE& Key() const;
64 const VALUETYPE& Value() const;
65
66 KEYTYPE keyData = KEYTYPE();
67 VALUETYPE valueData = VALUETYPE();
68};
69
70//------------------------------------------------------------------------------
73template<class KEYTYPE, class VALUETYPE>
78
79//------------------------------------------------------------------------------
82template<class KEYTYPE, class VALUETYPE>
83KeyValuePair<KEYTYPE, VALUETYPE>::KeyValuePair(const KEYTYPE& k, const VALUETYPE& v) :
84 keyData(k),
85 valueData(v)
86{
87 // empty
88}
89
90//------------------------------------------------------------------------------
95template<class KEYTYPE, class VALUETYPE>
97 keyData(k)
98{
99 // empty
100}
101
102//------------------------------------------------------------------------------
105template<class KEYTYPE, class VALUETYPE>
107 keyData(rhs.keyData),
108 valueData(rhs.valueData)
109{
110 // empty
111}
112
113//------------------------------------------------------------------------------
116template<class KEYTYPE, class VALUETYPE>
118 keyData(std::move(rhs.keyData)),
119 valueData(std::move(rhs.valueData))
120{
121 // empty
122}
123
124//------------------------------------------------------------------------------
127template<class KEYTYPE, class VALUETYPE>
128void
130{
131 this->keyData = rhs.keyData;
132 this->valueData = rhs.valueData;
133}
134
135//------------------------------------------------------------------------------
138template<class KEYTYPE, class VALUETYPE>
139void
141{
142 this->keyData = std::move(rhs.keyData);
143 this->valueData = std::move(rhs.valueData);
144}
145
146//------------------------------------------------------------------------------
149template<class KEYTYPE, class VALUETYPE>
150bool
152{
153 return (this->keyData == rhs.keyData);
154}
155
156//------------------------------------------------------------------------------
159template<class KEYTYPE, class VALUETYPE>
160bool
162{
163 return (this->keyData != rhs.keyData);
164}
165
166//------------------------------------------------------------------------------
169template<class KEYTYPE, class VALUETYPE>
170bool
172{
173 return (this->keyData > rhs.keyData);
174}
175
176//------------------------------------------------------------------------------
179template<class KEYTYPE, class VALUETYPE>
180bool
182{
183 return (this->keyData >= rhs.keyData);
184}
185
186//------------------------------------------------------------------------------
189template<class KEYTYPE, class VALUETYPE>
190bool
192{
193 return (this->keyData < rhs.keyData);
194}
195
196//------------------------------------------------------------------------------
199template<class KEYTYPE, class VALUETYPE>
200bool
202{
203 return (this->keyData <= rhs.keyData);
204}
205
206//------------------------------------------------------------------------------
209template<class KEYTYPE, class VALUETYPE>
210bool
212{
213 return (this->keyData == rhs);
214}
215
216//------------------------------------------------------------------------------
219template<class KEYTYPE, class VALUETYPE>
220bool
222{
223 return (this->keyData != rhs);
224}
225
226//------------------------------------------------------------------------------
229template<class KEYTYPE, class VALUETYPE>
230bool
232{
233 return (this->keyData > rhs);
234}
235
236//------------------------------------------------------------------------------
239template<class KEYTYPE, class VALUETYPE>
240bool
242{
243 return (this->keyData >= rhs);
244}
245
246//------------------------------------------------------------------------------
249template<class KEYTYPE, class VALUETYPE>
250bool
251KeyValuePair<KEYTYPE, VALUETYPE>::operator<(const KEYTYPE& rhs) const
252{
253 return (this->keyData < rhs);
254}
255
256//------------------------------------------------------------------------------
259template<class KEYTYPE, class VALUETYPE>
260bool
261KeyValuePair<KEYTYPE, VALUETYPE>::operator<=(const KEYTYPE& rhs) const
262{
263 return (this->keyData <= rhs);
264}
265
266
267//------------------------------------------------------------------------------
270template<class KEYTYPE, class VALUETYPE>
271VALUETYPE&
273{
274 return this->valueData;
275}
276
277//------------------------------------------------------------------------------
280template<class KEYTYPE, class VALUETYPE>
281const KEYTYPE&
283{
284 return this->keyData;
285}
286
287//------------------------------------------------------------------------------
290template<class KEYTYPE, class VALUETYPE>
291const VALUETYPE&
293{
294 return this->valueData;
295}
296
297} // namespace Util
298//------------------------------------------------------------------------------
Key/Value pair objects are used by most assiociative container classes, like Dictionary or HashTable.
Definition keyvaluepair.h:19
KeyValuePair(KeyValuePair< KEYTYPE, VALUETYPE > &&rhs) noexcept
move constructor
Definition keyvaluepair.h:117
bool operator==(const KEYTYPE &rhs) const
equality operator
Definition keyvaluepair.h:211
void operator=(KeyValuePair< KEYTYPE, VALUETYPE > &&rhs) noexcept
move assignment operator
Definition keyvaluepair.h:140
const KEYTYPE & Key() const
read access to key
Definition keyvaluepair.h:282
KEYTYPE keyData
Definition keyvaluepair.h:66
bool operator>=(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs) const
greater-or-equal operator
Definition keyvaluepair.h:181
bool operator==(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs) const
equality operator
Definition keyvaluepair.h:151
VALUETYPE valueData
Definition keyvaluepair.h:67
bool operator!=(const KEYTYPE &rhs) const
inequality operator
Definition keyvaluepair.h:221
bool operator>(const KEYTYPE &rhs) const
greater operator
Definition keyvaluepair.h:231
void operator=(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs)
assignment operator
Definition keyvaluepair.h:129
bool operator<=(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs) const
lesser-or-equal operator
Definition keyvaluepair.h:201
bool operator<(const KEYTYPE &rhs) const
lesser operator
Definition keyvaluepair.h:251
bool operator<=(const KEYTYPE &rhs) const
lesser-or-equal operator
Definition keyvaluepair.h:261
bool operator!=(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs) const
inequality operator
Definition keyvaluepair.h:161
KeyValuePair(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs)
copy constructor
Definition keyvaluepair.h:106
KeyValuePair()
default constructor
Definition keyvaluepair.h:74
KeyValuePair(const KEYTYPE &k)
constructor with key and undefined value
Definition keyvaluepair.h:96
bool operator>(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs) const
greater operator
Definition keyvaluepair.h:171
VALUETYPE & Value()
read/write access to value
Definition keyvaluepair.h:272
bool operator<(const KeyValuePair< KEYTYPE, VALUETYPE > &rhs) const
lesser operator
Definition keyvaluepair.h:191
KeyValuePair(const KEYTYPE &k, const VALUETYPE &v)
constructor with key and value
Definition keyvaluepair.h:83
bool operator>=(const KEYTYPE &rhs) const
greater-or-equal operator
Definition keyvaluepair.h:241
const VALUETYPE & Value() const
read access to key
Definition keyvaluepair.h:292
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6