Jpp 21.0.0-rc.1
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 * Append constructor.
52 * The secondary key is appended to the end of the primary keys.
53 *
54 * \param first primary keys and value
55 * \param second secondary key
56 */
62
63
64 /**
65 * Insert constructor.
66 * The primary key is inserted at the start of the secondary keys.
67 *
68 * \param first primary key
69 * \param second secondary keys and value
70 */
76
77
78 /**
79 * Shift constructor.
80 * The first of the secondary keys is removed and the primary key is inserted in the remainder of the primary keys.
81 *
82 * \param first primary key
83 * \param second secondary keys and value
84 */
89
90
91 /**
92 * Constructor.
93 *
94 * \param key multidimensional key
95 * \param value value
96 */
99 first (key.first),
100 second(mapped_type(key.second, value))
101 {}
102
103
104 /**
105 * Get multidimensional key.
106 *
107 * \return multidimensional key
108 */
110 {
111 return multikey_type(this->first, this->second.getKey());
112 }
113
114
115 /**
116 * Get value.
117 *
118 * \return value
119 */
120 reference_type getValue()
121 {
122 return this->second.getValue();
123 }
124
125
126 /**
127 * Get value.
128 *
129 * \return value
130 */
131 const reference_type getValue() const
132 {
133 return this->second.getValue();
134 }
135
136
137 key_type first;
139 };
140
141
142 /**
143 * One-dimensional pair.
144 */
145 template<class JKey_t, class JValue_t>
146 class JMultiPair<1, JKey_t, JValue_t>
147 {
148 public:
149
150 typedef JKey_t key_type;
151 typedef JValue_t value_type;
152 typedef JValue_t mapped_type;
155
156
157 /**
158 * Default constructor.
159 */
161 first (),
162 second()
163 {}
164
165
166 /**
167 * Constructor.
168 *
169 * \param first key
170 * \param second value
171 */
177
178
179 /**
180 * Constructor.
181 *
182 * \param key multidimensional key
183 * \param value value
184 */
186 typename JClass<value_type> ::argument_type value) :
187 first (key.first),
188 second(value)
189 {}
190
191
192 /**
193 * Shift constructor.
194 * The first of the secondary keys is removed and the primary key is inserted in the remainder of the primary keys.
195 *
196 * \param first primary key
197 * \param second secondary keys and value
198 */
203
204
205 /**
206 * Get multidimensional key.
207 *
208 * \return multidimensional key
209 */
211 {
212 return JMultiKey<1, key_type>(this->first);
213 }
214
215
216 /**
217 * Get value.
218 *
219 * \return value
220 */
221 reference_type getValue()
222 {
223 return this->second;
224 }
225
226
227 /**
228 * Get value.
229 *
230 * \return value
231 */
232 const reference_type getValue() const
233 {
234 return this->second;
235 }
236
237
238 key_type first;
240 };
241
242
243 /**
244 * Empty pair.
245 */
246 template<class JKey_t, class JValue_t>
247 class JMultiPair<0, JKey_t, JValue_t>
248 {};
249}
250
251#endif
Multidimensional key.
Definition JMultiKey.hh:44
reference_type getValue()
Get value.
JMultiPair(typename JClass< key_type > ::argument_type first, typename JClass< value_type >::argument_type second)
Constructor.
const reference_type getValue() const
Get value.
JClass< value_type >::reference_type reference_type
JMultiPair(typename JClass< key_type >::argument_type first, const JMultiPair &second)
Shift 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
Multidimensional pair.
Definition JMultiPair.hh:31
multikey_type getKey() const
Get multidimensional key.
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:97
JMultiPair(typename JClass< key_type > ::argument_type first, typename JClass< mapped_type >::argument_type second)
Insert 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
JMultiPair(typename JClass< mapped_type >::argument_type first, typename JClass< key_type > ::argument_type second)
Append constructor.
Definition JMultiPair.hh:57
reference_type getValue()
Get value.
JMultiPair(typename JClass< key_type >::argument_type first, const JMultiPair &second)
Shift constructor.
Definition JMultiPair.hh:85
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