Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JMultiPair.hh
Go to the documentation of this file.
1#ifndef __JTOOLS__JMULTIPAIR__
2#define __JTOOLS__JMULTIPAIR__
3
4#include "JTools/JMultiKey.hh"
5#include "JLang/JClass.hh"
6
7
8/**
9 * \author mdejong
10 */
11
12namespace JTOOLS {}
13namespace JPP { using namespace JTOOLS; }
14
15namespace JTOOLS {
16
17 /**
18 * Multidimensional pair.
19 *
20 * This class reproduces the element of a multidimensional map.
21 * The individual data members can be accessed as:
22 * <pre>
23 * JMultiPair<3, key_type, mapped_type> pair;
24 *
25 * pair[[.second].second].first;
26 * pair[[.second].second].second;
27 * </pre>
28 */
29 template<unsigned int N, class JKey_t, class JValue_t>
31 {
32 public:
33
34 typedef JKey_t key_type;
35 typedef JValue_t value_type;
39
40
41 /**
42 * Default constructor.
43 */
45 first (),
46 second()
47 {}
48
49
50 /**
51 * Constructor.
52 * The primary key is inserted at the start of the secondary keys.
53 *
54 * \param __first primary key
55 * \param __second secondary keys and value
56 */
58 typename JClass<mapped_type>::argument_type __second) :
59 first (__first),
60 second(__second)
61 {}
62
63
64 /**
65 * Constructor.
66 * The secondary key is appended to the end of the primary keys.
67 *
68 * \param __first primary keys and value
69 * \param __second secondary key
70 */
72 typename JClass<key_type> ::argument_type __second) :
73 first (__first.first),
74 second(mapped_type(__first.second, __second))
75 {}
76
77
78 /**
79 * Constructor.
80 *
81 * \param key multidimensional key
82 * \param value value
83 */
89
90
91 /**
92 * Get multidimensional key.
93 *
94 * \return multidimensional key
95 */
97 {
98 return multikey_type(this->first, this->second.getKey());
99 }
100
101
102 /**
103 * Get value.
104 *
105 * \return value
106 */
107 reference_type getValue()
108 {
109 return this->second.getValue();
110 }
111
112
113 /**
114 * Get value.
115 *
116 * \return value
117 */
118 const reference_type getValue() const
119 {
120 return this->second.getValue();
121 }
122
123
124 key_type first;
126 };
127
128
129 /**
130 * Two-dimensional pair.
131 */
132 template<class JKey_t, class JValue_t>
133 class JMultiPair<2, JKey_t, JValue_t>
134 {
135 public:
136
137 typedef JKey_t key_type;
138 typedef JValue_t value_type;
142
143
144 /**
145 * Default constructor.
146 */
148 first (),
149 second()
150 {}
151
152
153 /**
154 * Constructor.
155 * The primary key is inserted at the start of the secondary key.
156 *
157 * \param __first primary key
158 * \param __second secondary key and value
159 */
161 typename JClass<mapped_type>::argument_type __second) :
162 first (__first),
163 second(__second)
164 {}
165
166
167 /**
168 * Constructor.
169 * The secondary key is appended to the end of the primary key.
170 *
171 * \param __first primary keys and value
172 * \param __second secondary key
173 */
175 typename JClass<key_type> ::argument_type __second) :
176 first (__first.first),
177 second(mapped_type(__second, __first.second))
178 {}
179
180
181 /**
182 * Constructor.
183 *
184 * \param key multidimensional key
185 * \param value value
186 */
188 typename JClass<value_type> ::argument_type value) :
189 first (key.first),
190 second(mapped_type(key.second, value))
191 {}
192
193
194 /**
195 * Get multidimensional key.
196 *
197 * \return multidimensional key
198 */
200 {
201 return multikey_type(this->first, this->second.getKey());
202 }
203
204
205 /**
206 * Get value.
207 *
208 * \return value
209 */
210 reference_type getValue()
211 {
212 return this->second.getValue();
213 }
214
215
216 /**
217 * Get value.
218 *
219 * \return value
220 */
221 const reference_type getValue() const
222 {
223 return this->second.getValue();
224 }
225
226
227 key_type first;
229 };
230
231
232 /**
233 * One-dimensional pair.
234 */
235 template<class JKey_t, class JValue_t>
236 class JMultiPair<1, JKey_t, JValue_t>
237 {
238 public:
239
240 typedef JKey_t key_type;
241 typedef JValue_t value_type;
242 typedef JValue_t mapped_type;
245
246
247 /**
248 * Default constructor.
249 */
251 first (),
252 second()
253 {}
254
255
256 /**
257 * Constructor.
258 *
259 * \param __first key
260 * \param __second value
261 */
263 typename JClass<value_type>::argument_type __second) :
264 first (__first),
265 second(__second)
266 {}
267
268
269 /**
270 * Constructor.
271 *
272 * \param key multidimensional key
273 * \param value value
274 */
276 typename JClass<value_type> ::argument_type value) :
277 first (key.first),
278 second(value)
279 {}
280
281
282 /**
283 * Get multidimensional key.
284 *
285 * \return multidimensional key
286 */
288 {
289 return JMultiKey<1, key_type>(this->first);
290 }
291
292
293 /**
294 * Get value.
295 *
296 * \return value
297 */
298 reference_type getValue()
299 {
300 return this->second;
301 }
302
303
304 /**
305 * Get value.
306 *
307 * \return value
308 */
309 const reference_type getValue() const
310 {
311 return this->second;
312 }
313
314
315 key_type first;
317 };
318
319
320 /**
321 * Empty pair.
322 */
323 template<class JKey_t, class JValue_t>
324 class JMultiPair<0, JKey_t, JValue_t>
325 {};
326}
327
328#endif
Multidimensional key.
Definition JMultiKey.hh:69
reference_type getValue()
Get value.
const reference_type getValue() const
Get value.
JClass< value_type >::reference_type reference_type
JMultiPair(typename JClass< key_type > ::argument_type __first, typename JClass< value_type >::argument_type __second)
Constructor.
JMultiPair(typename JClass< multikey_type >::argument_type key, typename JClass< value_type > ::argument_type value)
Constructor.
multikey_type getKey() const
Get multidimensional key.
JMultiKey< 1, key_type > multikey_type
JMultiPair(typename JClass< mapped_type >::argument_type __first, typename JClass< key_type > ::argument_type __second)
Constructor.
reference_type getValue()
Get value.
JMultiPair< 1, key_type, value_type > mapped_type
JMultiPair(typename JClass< multikey_type >::argument_type key, typename JClass< value_type > ::argument_type value)
Constructor.
const reference_type getValue() const
Get value.
JClass< value_type >::reference_type reference_type
JMultiPair(typename JClass< key_type > ::argument_type __first, typename JClass< mapped_type >::argument_type __second)
Constructor.
multikey_type getKey() const
Get multidimensional key.
JMultiKey< 2, key_type > multikey_type
Multidimensional pair.
Definition JMultiPair.hh:31
multikey_type getKey() const
Get multidimensional key.
Definition JMultiPair.hh:96
JMultiKey< N, key_type > multikey_type
Definition JMultiPair.hh:38
JMultiPair()
Default constructor.
Definition JMultiPair.hh:44
JMultiPair(typename JClass< multikey_type >::argument_type key, typename JClass< value_type > ::argument_type value)
Constructor.
Definition JMultiPair.hh:84
JMultiPair(typename JClass< mapped_type >::argument_type __first, typename JClass< key_type > ::argument_type __second)
Constructor.
Definition JMultiPair.hh:71
JLANG::JClass< value_type >::reference_type reference_type
Definition JMultiPair.hh:37
const reference_type getValue() const
Get value.
mapped_type second
reference_type getValue()
Get value.
JMultiPair(typename JClass< key_type > ::argument_type __first, typename JClass< mapped_type >::argument_type __second)
Constructor.
Definition JMultiPair.hh:57
JMultiPair< N-1, key_type, value_type > mapped_type
Definition JMultiPair.hh:36
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Template for generic class types.
Definition JClass.hh:80
value_type & reference_type
Definition JClass.hh:84
JArgument< T >::argument_type argument_type
Definition JClass.hh:82