1 | // |
2 | // NamedTuple.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Core |
6 | // Module: NamedTuple |
7 | // |
8 | // Definition of the NamedTuple class. |
9 | // |
10 | // Copyright (c) 2007, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_NamedTuple_INCLUDED |
18 | #define Foundation_NamedTuple_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/Tuple.h" |
23 | #include "Poco/TypeList.h" |
24 | #include "Poco/DynamicAny.h" |
25 | #include "Poco/SharedPtr.h" |
26 | #include "Poco/Format.h" |
27 | |
28 | |
29 | namespace Poco { |
30 | |
31 | |
32 | template<class T0, |
33 | class T1 = NullTypeList, |
34 | class T2 = NullTypeList, |
35 | class T3 = NullTypeList, |
36 | class T4 = NullTypeList, |
37 | class T5 = NullTypeList, |
38 | class T6 = NullTypeList, |
39 | class T7 = NullTypeList, |
40 | class T8 = NullTypeList, |
41 | class T9 = NullTypeList, |
42 | class T10 = NullTypeList, |
43 | class T11 = NullTypeList, |
44 | class T12 = NullTypeList, |
45 | class T13 = NullTypeList, |
46 | class T14 = NullTypeList, |
47 | class T15 = NullTypeList, |
48 | class T16 = NullTypeList, |
49 | class T17 = NullTypeList, |
50 | class T18 = NullTypeList, |
51 | class T19 = NullTypeList> |
52 | struct NamedTuple: public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> |
53 | { |
54 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> TupleType; |
55 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>::Type Type; |
56 | typedef std::vector<std::string> NameVec; |
57 | typedef SharedPtr<NameVec> NameVecPtr; |
58 | |
59 | NamedTuple(): _pNames(0) |
60 | { |
61 | init(); |
62 | } |
63 | |
64 | NamedTuple(const NameVecPtr& rNames) |
65 | { |
66 | if (rNames->size() != TupleType::length) |
67 | throw InvalidArgumentException("Wrong names vector length." ); |
68 | |
69 | _pNames = rNames; |
70 | } |
71 | |
72 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
73 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
74 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
75 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
76 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
77 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
78 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
79 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
80 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
81 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
82 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
83 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
84 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
85 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
86 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
87 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
88 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
89 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), |
90 | typename TypeWrapper<T18>::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), |
91 | typename TypeWrapper<T19>::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): |
92 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19), |
93 | _pNames(0) |
94 | { |
95 | init(); |
96 | } |
97 | |
98 | NamedTuple(const NameVecPtr& rNames, |
99 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
100 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
101 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
102 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
103 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
104 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
105 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
106 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
107 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
108 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
109 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
110 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
111 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
112 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
113 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
114 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
115 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
116 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), |
117 | typename TypeWrapper<T18>::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), |
118 | typename TypeWrapper<T19>::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): |
119 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19) |
120 | { |
121 | if (rNames->size() != TupleType::length) |
122 | throw InvalidArgumentException("Wrong names vector length." ); |
123 | |
124 | _pNames = rNames; |
125 | } |
126 | |
127 | NamedTuple(const std::string& n0, |
128 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
129 | const std::string& n1 = "B" , |
130 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
131 | const std::string& n2 = "C" , |
132 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
133 | const std::string& n3 = "D" , |
134 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
135 | const std::string& n4 = "E" , |
136 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
137 | const std::string& n5 = "F" , |
138 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
139 | const std::string& n6 = "G" , |
140 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
141 | const std::string& n7 = "H" , |
142 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
143 | const std::string& n8 = "I" , |
144 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
145 | const std::string& n9 = "J" , |
146 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
147 | const std::string& n10 = "K" , |
148 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
149 | const std::string& n11 = "L" , |
150 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
151 | const std::string& n12 = "M" , |
152 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
153 | const std::string& n13 = "N" , |
154 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
155 | const std::string& n14 = "O" , |
156 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
157 | const std::string& n15 = "P" , |
158 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
159 | const std::string& n16 = "Q" , |
160 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
161 | const std::string& n17 = "R" , |
162 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), |
163 | const std::string& n18 = "S" , |
164 | typename TypeWrapper<T18>::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18), |
165 | const std::string& n19 = "T" , |
166 | typename TypeWrapper<T19>::CONSTTYPE& t19 = POCO_TYPEWRAPPER_DEFAULTVALUE(T19)): |
167 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19), |
168 | _pNames(0) |
169 | { |
170 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19); |
171 | } |
172 | |
173 | const DynamicAny get(const std::string& name) const |
174 | { |
175 | NameVec::const_iterator it = _pNames->begin(); |
176 | NameVec::const_iterator itEnd = _pNames->end(); |
177 | |
178 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
179 | { |
180 | if (name == *it) |
181 | { |
182 | switch (counter) |
183 | { |
184 | case 0: return TupleType::template get<0>(); |
185 | case 1: return TupleType::template get<1>(); |
186 | case 2: return TupleType::template get<2>(); |
187 | case 3: return TupleType::template get<3>(); |
188 | case 4: return TupleType::template get<4>(); |
189 | case 5: return TupleType::template get<5>(); |
190 | case 6: return TupleType::template get<6>(); |
191 | case 7: return TupleType::template get<7>(); |
192 | case 8: return TupleType::template get<8>(); |
193 | case 9: return TupleType::template get<9>(); |
194 | case 10: return TupleType::template get<10>(); |
195 | case 11: return TupleType::template get<11>(); |
196 | case 12: return TupleType::template get<12>(); |
197 | case 13: return TupleType::template get<13>(); |
198 | case 14: return TupleType::template get<14>(); |
199 | case 15: return TupleType::template get<15>(); |
200 | case 16: return TupleType::template get<16>(); |
201 | case 17: return TupleType::template get<17>(); |
202 | case 18: return TupleType::template get<18>(); |
203 | case 19: return TupleType::template get<19>(); |
204 | default: throw RangeException(); |
205 | } |
206 | } |
207 | } |
208 | |
209 | throw NotFoundException("Name not found: " + name); |
210 | } |
211 | |
212 | const DynamicAny operator [] (const std::string& name) const |
213 | { |
214 | return get(name); |
215 | } |
216 | |
217 | template<int N> |
218 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
219 | { |
220 | return TupleType::template get<N>(); |
221 | } |
222 | |
223 | template<int N> |
224 | typename TypeGetter<N, Type>::HeadType& get() |
225 | { |
226 | return TupleType::template get<N>(); |
227 | } |
228 | |
229 | template<int N> |
230 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
231 | { |
232 | return TupleType::template set<N>(val); |
233 | } |
234 | |
235 | const NameVecPtr& names() |
236 | { |
237 | return _pNames; |
238 | } |
239 | |
240 | void setName(std::size_t index, const std::string& name) |
241 | { |
242 | if (index >= _pNames->size()) |
243 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
244 | |
245 | (*_pNames)[index] = name; |
246 | } |
247 | |
248 | const std::string& getName(std::size_t index) |
249 | { |
250 | if (index >= _pNames->size()) |
251 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
252 | |
253 | return (*_pNames)[index]; |
254 | } |
255 | |
256 | bool operator == (const NamedTuple& other) const |
257 | { |
258 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
259 | } |
260 | |
261 | bool operator != (const NamedTuple& other) const |
262 | { |
263 | return !(*this == other); |
264 | } |
265 | |
266 | bool operator < (const NamedTuple& other) const |
267 | { |
268 | TupleType th(*this); |
269 | TupleType oth(other); |
270 | |
271 | return (th < oth && _pNames == other._pNames) || |
272 | (th == oth && _pNames < other._pNames) || |
273 | (th < oth && _pNames < other._pNames); |
274 | } |
275 | |
276 | private: |
277 | void init(const std::string& n0 = "A" , |
278 | const std::string& n1 = "B" , |
279 | const std::string& n2 = "C" , |
280 | const std::string& n3 = "D" , |
281 | const std::string& n4 = "E" , |
282 | const std::string& n5 = "F" , |
283 | const std::string& n6 = "G" , |
284 | const std::string& n7 = "H" , |
285 | const std::string& n8 = "I" , |
286 | const std::string& n9 = "J" , |
287 | const std::string& n10 = "K" , |
288 | const std::string& n11 = "L" , |
289 | const std::string& n12 = "M" , |
290 | const std::string& n13 = "N" , |
291 | const std::string& n14 = "O" , |
292 | const std::string& n15 = "P" , |
293 | const std::string& n16 = "Q" , |
294 | const std::string& n17 = "R" , |
295 | const std::string& n18 = "S" , |
296 | const std::string& n19 = "T" ) |
297 | { |
298 | if (!_pNames) |
299 | { |
300 | _pNames = new NameVec; |
301 | _pNames->push_back(n0); |
302 | _pNames->push_back(n1); |
303 | _pNames->push_back(n2); |
304 | _pNames->push_back(n3); |
305 | _pNames->push_back(n4); |
306 | _pNames->push_back(n5); |
307 | _pNames->push_back(n6); |
308 | _pNames->push_back(n7); |
309 | _pNames->push_back(n8); |
310 | _pNames->push_back(n9); |
311 | _pNames->push_back(n10); |
312 | _pNames->push_back(n11); |
313 | _pNames->push_back(n12); |
314 | _pNames->push_back(n13); |
315 | _pNames->push_back(n14); |
316 | _pNames->push_back(n15); |
317 | _pNames->push_back(n16); |
318 | _pNames->push_back(n17); |
319 | _pNames->push_back(n18); |
320 | _pNames->push_back(n19); |
321 | } |
322 | } |
323 | |
324 | NameVecPtr _pNames; |
325 | }; |
326 | |
327 | |
328 | template<class T0, |
329 | class T1, |
330 | class T2, |
331 | class T3, |
332 | class T4, |
333 | class T5, |
334 | class T6, |
335 | class T7, |
336 | class T8, |
337 | class T9, |
338 | class T10, |
339 | class T11, |
340 | class T12, |
341 | class T13, |
342 | class T14, |
343 | class T15, |
344 | class T16, |
345 | class T17, |
346 | class T18> |
347 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,NullTypeList>: |
348 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18> |
349 | { |
350 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18> TupleType; |
351 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>::Type Type; |
352 | typedef std::vector<std::string> NameVec; |
353 | typedef SharedPtr<NameVec> NameVecPtr; |
354 | |
355 | NamedTuple(): _pNames(0) |
356 | { |
357 | init(); |
358 | } |
359 | |
360 | NamedTuple(const NameVecPtr& rNames) |
361 | { |
362 | if (rNames->size() != TupleType::length) |
363 | throw InvalidArgumentException("Wrong names vector length." ); |
364 | |
365 | _pNames = rNames; |
366 | } |
367 | |
368 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
369 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
370 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
371 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
372 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
373 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
374 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
375 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
376 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
377 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
378 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
379 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
380 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
381 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
382 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
383 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
384 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
385 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), |
386 | typename TypeWrapper<T18>::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): |
387 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18), |
388 | _pNames(0) |
389 | { |
390 | init(); |
391 | } |
392 | |
393 | NamedTuple(const NameVecPtr& rNames, |
394 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
395 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
396 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
397 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
398 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
399 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
400 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
401 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
402 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
403 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
404 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
405 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
406 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
407 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
408 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
409 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
410 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
411 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), |
412 | typename TypeWrapper<T18>::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): |
413 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18) |
414 | { |
415 | if (rNames->size() != TupleType::length) |
416 | throw InvalidArgumentException("Wrong names vector length." ); |
417 | |
418 | _pNames = rNames; |
419 | } |
420 | |
421 | NamedTuple(const std::string& n0, |
422 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
423 | const std::string& n1 = "B" , |
424 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
425 | const std::string& n2 = "C" , |
426 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
427 | const std::string& n3 = "D" , |
428 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
429 | const std::string& n4 = "E" , |
430 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
431 | const std::string& n5 = "F" , |
432 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
433 | const std::string& n6 = "G" , |
434 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
435 | const std::string& n7 = "H" , |
436 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
437 | const std::string& n8 = "I" , |
438 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
439 | const std::string& n9 = "J" , |
440 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
441 | const std::string& n10 = "K" , |
442 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
443 | const std::string& n11 = "L" , |
444 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
445 | const std::string& n12 = "M" , |
446 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
447 | const std::string& n13 = "N" , |
448 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
449 | const std::string& n14 = "O" , |
450 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
451 | const std::string& n15 = "P" , |
452 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
453 | const std::string& n16 = "Q" , |
454 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
455 | const std::string& n17 = "R" , |
456 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17), |
457 | const std::string& n18 = "S" , |
458 | typename TypeWrapper<T18>::CONSTTYPE& t18 = POCO_TYPEWRAPPER_DEFAULTVALUE(T18)): |
459 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18), |
460 | _pNames(0) |
461 | { |
462 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18); |
463 | } |
464 | |
465 | const DynamicAny get(const std::string& name) const |
466 | { |
467 | NameVec::const_iterator it = _pNames->begin(); |
468 | NameVec::const_iterator itEnd = _pNames->end(); |
469 | |
470 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
471 | { |
472 | if (name == *it) |
473 | { |
474 | switch (counter) |
475 | { |
476 | case 0: return TupleType::template get<0>(); |
477 | case 1: return TupleType::template get<1>(); |
478 | case 2: return TupleType::template get<2>(); |
479 | case 3: return TupleType::template get<3>(); |
480 | case 4: return TupleType::template get<4>(); |
481 | case 5: return TupleType::template get<5>(); |
482 | case 6: return TupleType::template get<6>(); |
483 | case 7: return TupleType::template get<7>(); |
484 | case 8: return TupleType::template get<8>(); |
485 | case 9: return TupleType::template get<9>(); |
486 | case 10: return TupleType::template get<10>(); |
487 | case 11: return TupleType::template get<11>(); |
488 | case 12: return TupleType::template get<12>(); |
489 | case 13: return TupleType::template get<13>(); |
490 | case 14: return TupleType::template get<14>(); |
491 | case 15: return TupleType::template get<15>(); |
492 | case 16: return TupleType::template get<16>(); |
493 | case 17: return TupleType::template get<17>(); |
494 | case 18: return TupleType::template get<18>(); |
495 | default: throw RangeException(); |
496 | } |
497 | } |
498 | } |
499 | |
500 | throw NotFoundException("Name not found: " + name); |
501 | } |
502 | |
503 | const DynamicAny operator [] (const std::string& name) const |
504 | { |
505 | return get(name); |
506 | } |
507 | |
508 | template<int N> |
509 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
510 | { |
511 | return TupleType::template get<N>(); |
512 | } |
513 | |
514 | template<int N> |
515 | typename TypeGetter<N, Type>::HeadType& get() |
516 | { |
517 | return TupleType::template get<N>(); |
518 | } |
519 | |
520 | template<int N> |
521 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
522 | { |
523 | return TupleType::template set<N>(val); |
524 | } |
525 | |
526 | const NameVecPtr& names() |
527 | { |
528 | return _pNames; |
529 | } |
530 | |
531 | void setName(std::size_t index, const std::string& name) |
532 | { |
533 | if (index >= _pNames->size()) |
534 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
535 | |
536 | (*_pNames)[index] = name; |
537 | } |
538 | |
539 | const std::string& getName(std::size_t index) |
540 | { |
541 | if (index >= _pNames->size()) |
542 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
543 | |
544 | return (*_pNames)[index]; |
545 | } |
546 | |
547 | bool operator == (const NamedTuple& other) const |
548 | { |
549 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
550 | } |
551 | |
552 | bool operator != (const NamedTuple& other) const |
553 | { |
554 | return !(*this == other); |
555 | } |
556 | |
557 | bool operator < (const NamedTuple& other) const |
558 | { |
559 | TupleType th(*this); |
560 | TupleType oth(other); |
561 | |
562 | return (th < oth && _pNames == other._pNames) || |
563 | (th == oth && _pNames < other._pNames) || |
564 | (th < oth && _pNames < other._pNames); |
565 | } |
566 | |
567 | private: |
568 | void init(const std::string& n0 = "A" , |
569 | const std::string& n1 = "B" , |
570 | const std::string& n2 = "C" , |
571 | const std::string& n3 = "D" , |
572 | const std::string& n4 = "E" , |
573 | const std::string& n5 = "F" , |
574 | const std::string& n6 = "G" , |
575 | const std::string& n7 = "H" , |
576 | const std::string& n8 = "I" , |
577 | const std::string& n9 = "J" , |
578 | const std::string& n10 = "K" , |
579 | const std::string& n11 = "L" , |
580 | const std::string& n12 = "M" , |
581 | const std::string& n13 = "N" , |
582 | const std::string& n14 = "O" , |
583 | const std::string& n15 = "P" , |
584 | const std::string& n16 = "Q" , |
585 | const std::string& n17 = "R" , |
586 | const std::string& n18 = "S" ) |
587 | { |
588 | if (!_pNames) |
589 | { |
590 | _pNames = new NameVec; |
591 | _pNames->push_back(n0); |
592 | _pNames->push_back(n1); |
593 | _pNames->push_back(n2); |
594 | _pNames->push_back(n3); |
595 | _pNames->push_back(n4); |
596 | _pNames->push_back(n5); |
597 | _pNames->push_back(n6); |
598 | _pNames->push_back(n7); |
599 | _pNames->push_back(n8); |
600 | _pNames->push_back(n9); |
601 | _pNames->push_back(n10); |
602 | _pNames->push_back(n11); |
603 | _pNames->push_back(n12); |
604 | _pNames->push_back(n13); |
605 | _pNames->push_back(n14); |
606 | _pNames->push_back(n15); |
607 | _pNames->push_back(n16); |
608 | _pNames->push_back(n17); |
609 | _pNames->push_back(n18); |
610 | } |
611 | } |
612 | |
613 | NameVecPtr _pNames; |
614 | }; |
615 | |
616 | |
617 | template<class T0, |
618 | class T1, |
619 | class T2, |
620 | class T3, |
621 | class T4, |
622 | class T5, |
623 | class T6, |
624 | class T7, |
625 | class T8, |
626 | class T9, |
627 | class T10, |
628 | class T11, |
629 | class T12, |
630 | class T13, |
631 | class T14, |
632 | class T15, |
633 | class T16, |
634 | class T17> |
635 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,NullTypeList>: |
636 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17> |
637 | { |
638 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17> TupleType; |
639 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>::Type Type; |
640 | typedef std::vector<std::string> NameVec; |
641 | typedef SharedPtr<NameVec> NameVecPtr; |
642 | |
643 | NamedTuple(): _pNames(0) |
644 | { |
645 | init(); |
646 | } |
647 | |
648 | NamedTuple(const NameVecPtr& rNames) |
649 | { |
650 | if (rNames->size() != TupleType::length) |
651 | throw InvalidArgumentException("Wrong names vector length." ); |
652 | |
653 | _pNames = rNames; |
654 | } |
655 | |
656 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
657 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
658 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
659 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
660 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
661 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
662 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
663 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
664 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
665 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
666 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
667 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
668 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
669 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
670 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
671 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
672 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
673 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): |
674 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17), |
675 | _pNames(0) |
676 | { |
677 | init(); |
678 | } |
679 | |
680 | NamedTuple(const NameVecPtr& rNames, |
681 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
682 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
683 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
684 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
685 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
686 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
687 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
688 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
689 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
690 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
691 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
692 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
693 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
694 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
695 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
696 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
697 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
698 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): |
699 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17) |
700 | { |
701 | if (rNames->size() != TupleType::length) |
702 | throw InvalidArgumentException("Wrong names vector length." ); |
703 | |
704 | _pNames = rNames; |
705 | } |
706 | |
707 | NamedTuple(const std::string& n0, |
708 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
709 | const std::string& n1 = "B" , |
710 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
711 | const std::string& n2 = "C" , |
712 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
713 | const std::string& n3 = "D" , |
714 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
715 | const std::string& n4 = "E" , |
716 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
717 | const std::string& n5 = "F" , |
718 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
719 | const std::string& n6 = "G" , |
720 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
721 | const std::string& n7 = "H" , |
722 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
723 | const std::string& n8 = "I" , |
724 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
725 | const std::string& n9 = "J" , |
726 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
727 | const std::string& n10 = "K" , |
728 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
729 | const std::string& n11 = "L" , |
730 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
731 | const std::string& n12 = "M" , |
732 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
733 | const std::string& n13 = "N" , |
734 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
735 | const std::string& n14 = "O" , |
736 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
737 | const std::string& n15 = "P" , |
738 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
739 | const std::string& n16 = "Q" , |
740 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16), |
741 | const std::string& n17 = "R" , |
742 | typename TypeWrapper<T17>::CONSTTYPE& t17 = POCO_TYPEWRAPPER_DEFAULTVALUE(T17)): |
743 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17), |
744 | _pNames(0) |
745 | { |
746 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17); |
747 | } |
748 | |
749 | const DynamicAny get(const std::string& name) const |
750 | { |
751 | NameVec::const_iterator it = _pNames->begin(); |
752 | NameVec::const_iterator itEnd = _pNames->end(); |
753 | |
754 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
755 | { |
756 | if (name == *it) |
757 | { |
758 | switch (counter) |
759 | { |
760 | case 0: return TupleType::template get<0>(); |
761 | case 1: return TupleType::template get<1>(); |
762 | case 2: return TupleType::template get<2>(); |
763 | case 3: return TupleType::template get<3>(); |
764 | case 4: return TupleType::template get<4>(); |
765 | case 5: return TupleType::template get<5>(); |
766 | case 6: return TupleType::template get<6>(); |
767 | case 7: return TupleType::template get<7>(); |
768 | case 8: return TupleType::template get<8>(); |
769 | case 9: return TupleType::template get<9>(); |
770 | case 10: return TupleType::template get<10>(); |
771 | case 11: return TupleType::template get<11>(); |
772 | case 12: return TupleType::template get<12>(); |
773 | case 13: return TupleType::template get<13>(); |
774 | case 14: return TupleType::template get<14>(); |
775 | case 15: return TupleType::template get<15>(); |
776 | case 16: return TupleType::template get<16>(); |
777 | case 17: return TupleType::template get<17>(); |
778 | default: throw RangeException(); |
779 | } |
780 | } |
781 | } |
782 | |
783 | throw NotFoundException("Name not found: " + name); |
784 | } |
785 | |
786 | const DynamicAny operator [] (const std::string& name) const |
787 | { |
788 | return get(name); |
789 | } |
790 | |
791 | template<int N> |
792 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
793 | { |
794 | return TupleType::template get<N>(); |
795 | } |
796 | |
797 | template<int N> |
798 | typename TypeGetter<N, Type>::HeadType& get() |
799 | { |
800 | return TupleType::template get<N>(); |
801 | } |
802 | |
803 | template<int N> |
804 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
805 | { |
806 | return TupleType::template set<N>(val); |
807 | } |
808 | |
809 | const NameVecPtr& names() |
810 | { |
811 | return _pNames; |
812 | } |
813 | |
814 | void setName(std::size_t index, const std::string& name) |
815 | { |
816 | if (index >= _pNames->size()) |
817 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
818 | |
819 | (*_pNames)[index] = name; |
820 | } |
821 | |
822 | const std::string& getName(std::size_t index) |
823 | { |
824 | if (index >= _pNames->size()) |
825 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
826 | |
827 | return (*_pNames)[index]; |
828 | } |
829 | |
830 | bool operator == (const NamedTuple& other) const |
831 | { |
832 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
833 | } |
834 | |
835 | bool operator != (const NamedTuple& other) const |
836 | { |
837 | return !(*this == other); |
838 | } |
839 | |
840 | bool operator < (const NamedTuple& other) const |
841 | { |
842 | TupleType th(*this); |
843 | TupleType oth(other); |
844 | |
845 | return (th < oth && _pNames == other._pNames) || |
846 | (th == oth && _pNames < other._pNames) || |
847 | (th < oth && _pNames < other._pNames); |
848 | } |
849 | |
850 | private: |
851 | void init(const std::string& n0 = "A" , |
852 | const std::string& n1 = "B" , |
853 | const std::string& n2 = "C" , |
854 | const std::string& n3 = "D" , |
855 | const std::string& n4 = "E" , |
856 | const std::string& n5 = "F" , |
857 | const std::string& n6 = "G" , |
858 | const std::string& n7 = "H" , |
859 | const std::string& n8 = "I" , |
860 | const std::string& n9 = "J" , |
861 | const std::string& n10 = "K" , |
862 | const std::string& n11 = "L" , |
863 | const std::string& n12 = "M" , |
864 | const std::string& n13 = "N" , |
865 | const std::string& n14 = "O" , |
866 | const std::string& n15 = "P" , |
867 | const std::string& n16 = "Q" , |
868 | const std::string& n17 = "R" ) |
869 | { |
870 | if (!_pNames) |
871 | { |
872 | _pNames = new NameVec; |
873 | _pNames->push_back(n0); |
874 | _pNames->push_back(n1); |
875 | _pNames->push_back(n2); |
876 | _pNames->push_back(n3); |
877 | _pNames->push_back(n4); |
878 | _pNames->push_back(n5); |
879 | _pNames->push_back(n6); |
880 | _pNames->push_back(n7); |
881 | _pNames->push_back(n8); |
882 | _pNames->push_back(n9); |
883 | _pNames->push_back(n10); |
884 | _pNames->push_back(n11); |
885 | _pNames->push_back(n12); |
886 | _pNames->push_back(n13); |
887 | _pNames->push_back(n14); |
888 | _pNames->push_back(n15); |
889 | _pNames->push_back(n16); |
890 | _pNames->push_back(n17); |
891 | } |
892 | } |
893 | |
894 | NameVecPtr _pNames; |
895 | }; |
896 | |
897 | |
898 | template<class T0, |
899 | class T1, |
900 | class T2, |
901 | class T3, |
902 | class T4, |
903 | class T5, |
904 | class T6, |
905 | class T7, |
906 | class T8, |
907 | class T9, |
908 | class T10, |
909 | class T11, |
910 | class T12, |
911 | class T13, |
912 | class T14, |
913 | class T15, |
914 | class T16> |
915 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,NullTypeList>: |
916 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> |
917 | { |
918 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> TupleType; |
919 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>::Type Type; |
920 | typedef std::vector<std::string> NameVec; |
921 | typedef SharedPtr<NameVec> NameVecPtr; |
922 | |
923 | NamedTuple(): _pNames(0) |
924 | { |
925 | init(); |
926 | } |
927 | |
928 | NamedTuple(const NameVecPtr& rNames) |
929 | { |
930 | if (rNames->size() != TupleType::length) |
931 | throw InvalidArgumentException("Wrong names vector length." ); |
932 | |
933 | _pNames = rNames; |
934 | } |
935 | |
936 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
937 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
938 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
939 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
940 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
941 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
942 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
943 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
944 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
945 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
946 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
947 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
948 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
949 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
950 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
951 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
952 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): |
953 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16), |
954 | _pNames(0) |
955 | { |
956 | init(); |
957 | } |
958 | |
959 | NamedTuple(const NameVecPtr& rNames, |
960 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
961 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
962 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
963 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
964 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
965 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
966 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
967 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
968 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
969 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
970 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
971 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
972 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
973 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
974 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
975 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
976 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): |
977 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16) |
978 | { |
979 | if (rNames->size() != TupleType::length) |
980 | throw InvalidArgumentException("Wrong names vector length." ); |
981 | |
982 | _pNames = rNames; |
983 | } |
984 | |
985 | NamedTuple(const std::string& n0, |
986 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
987 | const std::string& n1 = "B" , |
988 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
989 | const std::string& n2 = "C" , |
990 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
991 | const std::string& n3 = "D" , |
992 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
993 | const std::string& n4 = "E" , |
994 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
995 | const std::string& n5 = "F" , |
996 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
997 | const std::string& n6 = "G" , |
998 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
999 | const std::string& n7 = "H" , |
1000 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1001 | const std::string& n8 = "I" , |
1002 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1003 | const std::string& n9 = "J" , |
1004 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1005 | const std::string& n10 = "K" , |
1006 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1007 | const std::string& n11 = "L" , |
1008 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1009 | const std::string& n12 = "M" , |
1010 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1011 | const std::string& n13 = "N" , |
1012 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1013 | const std::string& n14 = "O" , |
1014 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
1015 | const std::string& n15 = "P" , |
1016 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15), |
1017 | const std::string& n16 = "Q" , |
1018 | typename TypeWrapper<T16>::CONSTTYPE& t16 = POCO_TYPEWRAPPER_DEFAULTVALUE(T16)): |
1019 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16), |
1020 | _pNames(0) |
1021 | { |
1022 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16); |
1023 | } |
1024 | |
1025 | const DynamicAny get(const std::string& name) const |
1026 | { |
1027 | NameVec::const_iterator it = _pNames->begin(); |
1028 | NameVec::const_iterator itEnd = _pNames->end(); |
1029 | |
1030 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
1031 | { |
1032 | if (name == *it) |
1033 | { |
1034 | switch (counter) |
1035 | { |
1036 | case 0: return TupleType::template get<0>(); |
1037 | case 1: return TupleType::template get<1>(); |
1038 | case 2: return TupleType::template get<2>(); |
1039 | case 3: return TupleType::template get<3>(); |
1040 | case 4: return TupleType::template get<4>(); |
1041 | case 5: return TupleType::template get<5>(); |
1042 | case 6: return TupleType::template get<6>(); |
1043 | case 7: return TupleType::template get<7>(); |
1044 | case 8: return TupleType::template get<8>(); |
1045 | case 9: return TupleType::template get<9>(); |
1046 | case 10: return TupleType::template get<10>(); |
1047 | case 11: return TupleType::template get<11>(); |
1048 | case 12: return TupleType::template get<12>(); |
1049 | case 13: return TupleType::template get<13>(); |
1050 | case 14: return TupleType::template get<14>(); |
1051 | case 15: return TupleType::template get<15>(); |
1052 | case 16: return TupleType::template get<16>(); |
1053 | default: throw RangeException(); |
1054 | } |
1055 | } |
1056 | } |
1057 | |
1058 | throw NotFoundException("Name not found: " + name); |
1059 | } |
1060 | |
1061 | const DynamicAny operator [] (const std::string& name) const |
1062 | { |
1063 | return get(name); |
1064 | } |
1065 | |
1066 | template<int N> |
1067 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
1068 | { |
1069 | return TupleType::template get<N>(); |
1070 | } |
1071 | |
1072 | template<int N> |
1073 | typename TypeGetter<N, Type>::HeadType& get() |
1074 | { |
1075 | return TupleType::template get<N>(); |
1076 | } |
1077 | |
1078 | template<int N> |
1079 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
1080 | { |
1081 | return TupleType::template set<N>(val); |
1082 | } |
1083 | |
1084 | const NameVecPtr& names() |
1085 | { |
1086 | return _pNames; |
1087 | } |
1088 | |
1089 | void setName(std::size_t index, const std::string& name) |
1090 | { |
1091 | if (index >= _pNames->size()) |
1092 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1093 | |
1094 | (*_pNames)[index] = name; |
1095 | } |
1096 | |
1097 | const std::string& getName(std::size_t index) |
1098 | { |
1099 | if (index >= _pNames->size()) |
1100 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1101 | |
1102 | return (*_pNames)[index]; |
1103 | } |
1104 | |
1105 | bool operator == (const NamedTuple& other) const |
1106 | { |
1107 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
1108 | } |
1109 | |
1110 | bool operator != (const NamedTuple& other) const |
1111 | { |
1112 | return !(*this == other); |
1113 | } |
1114 | |
1115 | bool operator < (const NamedTuple& other) const |
1116 | { |
1117 | TupleType th(*this); |
1118 | TupleType oth(other); |
1119 | |
1120 | return (th < oth && _pNames == other._pNames) || |
1121 | (th == oth && _pNames < other._pNames) || |
1122 | (th < oth && _pNames < other._pNames); |
1123 | } |
1124 | |
1125 | private: |
1126 | void init(const std::string& n0 = "A" , |
1127 | const std::string& n1 = "B" , |
1128 | const std::string& n2 = "C" , |
1129 | const std::string& n3 = "D" , |
1130 | const std::string& n4 = "E" , |
1131 | const std::string& n5 = "F" , |
1132 | const std::string& n6 = "G" , |
1133 | const std::string& n7 = "H" , |
1134 | const std::string& n8 = "I" , |
1135 | const std::string& n9 = "J" , |
1136 | const std::string& n10 = "K" , |
1137 | const std::string& n11 = "L" , |
1138 | const std::string& n12 = "M" , |
1139 | const std::string& n13 = "N" , |
1140 | const std::string& n14 = "O" , |
1141 | const std::string& n15 = "P" , |
1142 | const std::string& n16 = "Q" ) |
1143 | { |
1144 | if (!_pNames) |
1145 | { |
1146 | _pNames = new NameVec; |
1147 | _pNames->push_back(n0); |
1148 | _pNames->push_back(n1); |
1149 | _pNames->push_back(n2); |
1150 | _pNames->push_back(n3); |
1151 | _pNames->push_back(n4); |
1152 | _pNames->push_back(n5); |
1153 | _pNames->push_back(n6); |
1154 | _pNames->push_back(n7); |
1155 | _pNames->push_back(n8); |
1156 | _pNames->push_back(n9); |
1157 | _pNames->push_back(n10); |
1158 | _pNames->push_back(n11); |
1159 | _pNames->push_back(n12); |
1160 | _pNames->push_back(n13); |
1161 | _pNames->push_back(n14); |
1162 | _pNames->push_back(n15); |
1163 | _pNames->push_back(n16); |
1164 | } |
1165 | } |
1166 | |
1167 | NameVecPtr _pNames; |
1168 | }; |
1169 | |
1170 | |
1171 | template<class T0, |
1172 | class T1, |
1173 | class T2, |
1174 | class T3, |
1175 | class T4, |
1176 | class T5, |
1177 | class T6, |
1178 | class T7, |
1179 | class T8, |
1180 | class T9, |
1181 | class T10, |
1182 | class T11, |
1183 | class T12, |
1184 | class T13, |
1185 | class T14, |
1186 | class T15> |
1187 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,NullTypeList>: |
1188 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> |
1189 | { |
1190 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> TupleType; |
1191 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>::Type Type; |
1192 | |
1193 | typedef std::vector<std::string> NameVec; |
1194 | typedef SharedPtr<NameVec> NameVecPtr; |
1195 | |
1196 | NamedTuple(): _pNames(0) |
1197 | { |
1198 | init(); |
1199 | } |
1200 | |
1201 | NamedTuple(const NameVecPtr& rNames) |
1202 | { |
1203 | if (rNames->size() != TupleType::length) |
1204 | throw InvalidArgumentException("Wrong names vector length." ); |
1205 | |
1206 | _pNames = rNames; |
1207 | } |
1208 | |
1209 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
1210 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1211 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1212 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1213 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1214 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1215 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1216 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1217 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1218 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1219 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1220 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1221 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1222 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1223 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
1224 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): |
1225 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15), |
1226 | _pNames(0) |
1227 | { |
1228 | init(); |
1229 | } |
1230 | |
1231 | NamedTuple(const NameVecPtr& rNames, |
1232 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
1233 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1234 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1235 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1236 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1237 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1238 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1239 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1240 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1241 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1242 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1243 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1244 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1245 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1246 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
1247 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): |
1248 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15) |
1249 | { |
1250 | if (rNames->size() != TupleType::length) |
1251 | throw InvalidArgumentException("Wrong names vector length." ); |
1252 | |
1253 | _pNames = rNames; |
1254 | } |
1255 | |
1256 | NamedTuple(const std::string& n0, |
1257 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
1258 | const std::string& n1 = "B" , |
1259 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1260 | const std::string& n2 = "C" , |
1261 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1262 | const std::string& n3 = "D" , |
1263 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1264 | const std::string& n4 = "E" , |
1265 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1266 | const std::string& n5 = "F" , |
1267 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1268 | const std::string& n6 = "G" , |
1269 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1270 | const std::string& n7 = "H" , |
1271 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1272 | const std::string& n8 = "I" , |
1273 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1274 | const std::string& n9 = "J" , |
1275 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1276 | const std::string& n10 = "K" , |
1277 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1278 | const std::string& n11 = "L" , |
1279 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1280 | const std::string& n12 = "M" , |
1281 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1282 | const std::string& n13 = "N" , |
1283 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1284 | const std::string& n14 = "O" , |
1285 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14), |
1286 | const std::string& n15 = "P" , |
1287 | typename TypeWrapper<T15>::CONSTTYPE& t15 = POCO_TYPEWRAPPER_DEFAULTVALUE(T15)): |
1288 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15), |
1289 | _pNames(0) |
1290 | { |
1291 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15); |
1292 | } |
1293 | |
1294 | const DynamicAny get(const std::string& name) const |
1295 | { |
1296 | NameVec::const_iterator it = _pNames->begin(); |
1297 | NameVec::const_iterator itEnd = _pNames->end(); |
1298 | |
1299 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
1300 | { |
1301 | if (name == *it) |
1302 | { |
1303 | switch (counter) |
1304 | { |
1305 | case 0: return TupleType::template get<0>(); |
1306 | case 1: return TupleType::template get<1>(); |
1307 | case 2: return TupleType::template get<2>(); |
1308 | case 3: return TupleType::template get<3>(); |
1309 | case 4: return TupleType::template get<4>(); |
1310 | case 5: return TupleType::template get<5>(); |
1311 | case 6: return TupleType::template get<6>(); |
1312 | case 7: return TupleType::template get<7>(); |
1313 | case 8: return TupleType::template get<8>(); |
1314 | case 9: return TupleType::template get<9>(); |
1315 | case 10: return TupleType::template get<10>(); |
1316 | case 11: return TupleType::template get<11>(); |
1317 | case 12: return TupleType::template get<12>(); |
1318 | case 13: return TupleType::template get<13>(); |
1319 | case 14: return TupleType::template get<14>(); |
1320 | case 15: return TupleType::template get<15>(); |
1321 | default: throw RangeException(); |
1322 | } |
1323 | } |
1324 | } |
1325 | |
1326 | throw NotFoundException("Name not found: " + name); |
1327 | } |
1328 | |
1329 | const DynamicAny operator [] (const std::string& name) const |
1330 | { |
1331 | return get(name); |
1332 | } |
1333 | |
1334 | template<int N> |
1335 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
1336 | { |
1337 | return TupleType::template get<N>(); |
1338 | } |
1339 | |
1340 | template<int N> |
1341 | typename TypeGetter<N, Type>::HeadType& get() |
1342 | { |
1343 | return TupleType::template get<N>(); |
1344 | } |
1345 | |
1346 | template<int N> |
1347 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
1348 | { |
1349 | return TupleType::template set<N>(val); |
1350 | } |
1351 | |
1352 | const NameVecPtr& names() |
1353 | { |
1354 | return _pNames; |
1355 | } |
1356 | |
1357 | void setName(std::size_t index, const std::string& name) |
1358 | { |
1359 | if (index >= _pNames->size()) |
1360 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1361 | |
1362 | (*_pNames)[index] = name; |
1363 | } |
1364 | |
1365 | const std::string& getName(std::size_t index) |
1366 | { |
1367 | if (index >= _pNames->size()) |
1368 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1369 | |
1370 | return (*_pNames)[index]; |
1371 | } |
1372 | |
1373 | bool operator == (const NamedTuple& other) const |
1374 | { |
1375 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
1376 | } |
1377 | |
1378 | bool operator != (const NamedTuple& other) const |
1379 | { |
1380 | return !(*this == other); |
1381 | } |
1382 | |
1383 | bool operator < (const NamedTuple& other) const |
1384 | { |
1385 | TupleType th(*this); |
1386 | TupleType oth(other); |
1387 | |
1388 | return (th < oth && _pNames == other._pNames) || |
1389 | (th == oth && _pNames < other._pNames) || |
1390 | (th < oth && _pNames < other._pNames); |
1391 | } |
1392 | |
1393 | private: |
1394 | void init(const std::string& n0 = "A" , |
1395 | const std::string& n1 = "B" , |
1396 | const std::string& n2 = "C" , |
1397 | const std::string& n3 = "D" , |
1398 | const std::string& n4 = "E" , |
1399 | const std::string& n5 = "F" , |
1400 | const std::string& n6 = "G" , |
1401 | const std::string& n7 = "H" , |
1402 | const std::string& n8 = "I" , |
1403 | const std::string& n9 = "J" , |
1404 | const std::string& n10 = "K" , |
1405 | const std::string& n11 = "L" , |
1406 | const std::string& n12 = "M" , |
1407 | const std::string& n13 = "N" , |
1408 | const std::string& n14 = "O" , |
1409 | const std::string& n15 = "P" ) |
1410 | { |
1411 | if (!_pNames) |
1412 | { |
1413 | _pNames = new NameVec; |
1414 | _pNames->push_back(n0); |
1415 | _pNames->push_back(n1); |
1416 | _pNames->push_back(n2); |
1417 | _pNames->push_back(n3); |
1418 | _pNames->push_back(n4); |
1419 | _pNames->push_back(n5); |
1420 | _pNames->push_back(n6); |
1421 | _pNames->push_back(n7); |
1422 | _pNames->push_back(n8); |
1423 | _pNames->push_back(n9); |
1424 | _pNames->push_back(n10); |
1425 | _pNames->push_back(n11); |
1426 | _pNames->push_back(n12); |
1427 | _pNames->push_back(n13); |
1428 | _pNames->push_back(n14); |
1429 | _pNames->push_back(n15); |
1430 | } |
1431 | } |
1432 | |
1433 | NameVecPtr _pNames; |
1434 | }; |
1435 | |
1436 | |
1437 | template<class T0, |
1438 | class T1, |
1439 | class T2, |
1440 | class T3, |
1441 | class T4, |
1442 | class T5, |
1443 | class T6, |
1444 | class T7, |
1445 | class T8, |
1446 | class T9, |
1447 | class T10, |
1448 | class T11, |
1449 | class T12, |
1450 | class T13, |
1451 | class T14> |
1452 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,NullTypeList>: |
1453 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> |
1454 | { |
1455 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> TupleType; |
1456 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>::Type Type; |
1457 | |
1458 | typedef std::vector<std::string> NameVec; |
1459 | typedef SharedPtr<NameVec> NameVecPtr; |
1460 | |
1461 | NamedTuple(): _pNames(0) |
1462 | { |
1463 | init(); |
1464 | } |
1465 | |
1466 | NamedTuple(const NameVecPtr& rNames) |
1467 | { |
1468 | if (rNames->size() != TupleType::length) |
1469 | throw InvalidArgumentException("Wrong names vector length." ); |
1470 | |
1471 | _pNames = rNames; |
1472 | } |
1473 | |
1474 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
1475 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1476 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1477 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1478 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1479 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1480 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1481 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1482 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1483 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1484 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1485 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1486 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1487 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1488 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): |
1489 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14), |
1490 | _pNames(0) |
1491 | { |
1492 | init(); |
1493 | } |
1494 | |
1495 | NamedTuple(const NameVecPtr& rNames, |
1496 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
1497 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1498 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1499 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1500 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1501 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1502 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1503 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1504 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1505 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1506 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1507 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1508 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1509 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1510 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): |
1511 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14) |
1512 | { |
1513 | if (rNames->size() != TupleType::length) |
1514 | throw InvalidArgumentException("Wrong names vector length." ); |
1515 | |
1516 | _pNames = rNames; |
1517 | } |
1518 | |
1519 | NamedTuple(const std::string& n0, |
1520 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
1521 | const std::string& n1 = "B" , |
1522 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1523 | const std::string& n2 = "C" , |
1524 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1525 | const std::string& n3 = "D" , |
1526 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1527 | const std::string& n4 = "E" , |
1528 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1529 | const std::string& n5 = "F" , |
1530 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1531 | const std::string& n6 = "G" , |
1532 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1533 | const std::string& n7 = "H" , |
1534 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1535 | const std::string& n8 = "I" , |
1536 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1537 | const std::string& n9 = "J" , |
1538 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1539 | const std::string& n10 = "K" , |
1540 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1541 | const std::string& n11 = "L" , |
1542 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1543 | const std::string& n12 = "M" , |
1544 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1545 | const std::string& n13 = "N" , |
1546 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13), |
1547 | const std::string& n14 = "O" , |
1548 | typename TypeWrapper<T14>::CONSTTYPE& t14 = POCO_TYPEWRAPPER_DEFAULTVALUE(T14)): |
1549 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14), |
1550 | _pNames(0) |
1551 | { |
1552 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14); |
1553 | } |
1554 | |
1555 | const DynamicAny get(const std::string& name) const |
1556 | { |
1557 | NameVec::const_iterator it = _pNames->begin(); |
1558 | NameVec::const_iterator itEnd = _pNames->end(); |
1559 | |
1560 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
1561 | { |
1562 | if (name == *it) |
1563 | { |
1564 | switch (counter) |
1565 | { |
1566 | case 0: return TupleType::template get<0>(); |
1567 | case 1: return TupleType::template get<1>(); |
1568 | case 2: return TupleType::template get<2>(); |
1569 | case 3: return TupleType::template get<3>(); |
1570 | case 4: return TupleType::template get<4>(); |
1571 | case 5: return TupleType::template get<5>(); |
1572 | case 6: return TupleType::template get<6>(); |
1573 | case 7: return TupleType::template get<7>(); |
1574 | case 8: return TupleType::template get<8>(); |
1575 | case 9: return TupleType::template get<9>(); |
1576 | case 10: return TupleType::template get<10>(); |
1577 | case 11: return TupleType::template get<11>(); |
1578 | case 12: return TupleType::template get<12>(); |
1579 | case 13: return TupleType::template get<13>(); |
1580 | case 14: return TupleType::template get<14>(); |
1581 | default: throw RangeException(); |
1582 | } |
1583 | } |
1584 | } |
1585 | |
1586 | throw NotFoundException("Name not found: " + name); |
1587 | } |
1588 | |
1589 | const DynamicAny operator [] (const std::string& name) const |
1590 | { |
1591 | return get(name); |
1592 | } |
1593 | |
1594 | template<int N> |
1595 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
1596 | { |
1597 | return TupleType::template get<N>(); |
1598 | } |
1599 | |
1600 | template<int N> |
1601 | typename TypeGetter<N, Type>::HeadType& get() |
1602 | { |
1603 | return TupleType::template get<N>(); |
1604 | } |
1605 | |
1606 | template<int N> |
1607 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
1608 | { |
1609 | return TupleType::template set<N>(val); |
1610 | } |
1611 | |
1612 | const NameVecPtr& names() |
1613 | { |
1614 | return _pNames; |
1615 | } |
1616 | |
1617 | void setName(std::size_t index, const std::string& name) |
1618 | { |
1619 | if (index >= _pNames->size()) |
1620 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1621 | |
1622 | (*_pNames)[index] = name; |
1623 | } |
1624 | |
1625 | const std::string& getName(std::size_t index) |
1626 | { |
1627 | if (index >= _pNames->size()) |
1628 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1629 | |
1630 | return (*_pNames)[index]; |
1631 | } |
1632 | |
1633 | bool operator == (const NamedTuple& other) const |
1634 | { |
1635 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
1636 | } |
1637 | |
1638 | bool operator != (const NamedTuple& other) const |
1639 | { |
1640 | return !(*this == other); |
1641 | } |
1642 | |
1643 | bool operator < (const NamedTuple& other) const |
1644 | { |
1645 | TupleType th(*this); |
1646 | TupleType oth(other); |
1647 | |
1648 | return (th < oth && _pNames == other._pNames) || |
1649 | (th == oth && _pNames < other._pNames) || |
1650 | (th < oth && _pNames < other._pNames); |
1651 | } |
1652 | |
1653 | private: |
1654 | void init(const std::string& n0 = "A" , |
1655 | const std::string& n1 = "B" , |
1656 | const std::string& n2 = "C" , |
1657 | const std::string& n3 = "D" , |
1658 | const std::string& n4 = "E" , |
1659 | const std::string& n5 = "F" , |
1660 | const std::string& n6 = "G" , |
1661 | const std::string& n7 = "H" , |
1662 | const std::string& n8 = "I" , |
1663 | const std::string& n9 = "J" , |
1664 | const std::string& n10 = "K" , |
1665 | const std::string& n11 = "L" , |
1666 | const std::string& n12 = "M" , |
1667 | const std::string& n13 = "N" , |
1668 | const std::string& n14 = "O" ) |
1669 | { |
1670 | if (!_pNames) |
1671 | { |
1672 | _pNames = new NameVec; |
1673 | _pNames->push_back(n0); |
1674 | _pNames->push_back(n1); |
1675 | _pNames->push_back(n2); |
1676 | _pNames->push_back(n3); |
1677 | _pNames->push_back(n4); |
1678 | _pNames->push_back(n5); |
1679 | _pNames->push_back(n6); |
1680 | _pNames->push_back(n7); |
1681 | _pNames->push_back(n8); |
1682 | _pNames->push_back(n9); |
1683 | _pNames->push_back(n10); |
1684 | _pNames->push_back(n11); |
1685 | _pNames->push_back(n12); |
1686 | _pNames->push_back(n13); |
1687 | _pNames->push_back(n14); |
1688 | } |
1689 | } |
1690 | |
1691 | NameVecPtr _pNames; |
1692 | }; |
1693 | |
1694 | |
1695 | template<class T0, |
1696 | class T1, |
1697 | class T2, |
1698 | class T3, |
1699 | class T4, |
1700 | class T5, |
1701 | class T6, |
1702 | class T7, |
1703 | class T8, |
1704 | class T9, |
1705 | class T10, |
1706 | class T11, |
1707 | class T12, |
1708 | class T13> |
1709 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,NullTypeList>: |
1710 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> |
1711 | { |
1712 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> TupleType; |
1713 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>::Type Type; |
1714 | |
1715 | typedef std::vector<std::string> NameVec; |
1716 | typedef SharedPtr<NameVec> NameVecPtr; |
1717 | |
1718 | NamedTuple(): _pNames(0) |
1719 | { |
1720 | init(); |
1721 | } |
1722 | |
1723 | NamedTuple(const NameVecPtr& rNames) |
1724 | { |
1725 | if (rNames->size() != TupleType::length) |
1726 | throw InvalidArgumentException("Wrong names vector length." ); |
1727 | |
1728 | _pNames = rNames; |
1729 | } |
1730 | |
1731 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
1732 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1733 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1734 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1735 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1736 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1737 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1738 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1739 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1740 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1741 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1742 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1743 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1744 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): |
1745 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13), |
1746 | _pNames(0) |
1747 | { |
1748 | init(); |
1749 | } |
1750 | |
1751 | NamedTuple(const NameVecPtr& rNames, |
1752 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
1753 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1754 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1755 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1756 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1757 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1758 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1759 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1760 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1761 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1762 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1763 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1764 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1765 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): |
1766 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13) |
1767 | { |
1768 | if (rNames->size() != TupleType::length) |
1769 | throw InvalidArgumentException("Wrong names vector length." ); |
1770 | |
1771 | _pNames = rNames; |
1772 | } |
1773 | |
1774 | NamedTuple(const std::string& n0, |
1775 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
1776 | const std::string& n1 = "B" , |
1777 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1778 | const std::string& n2 = "C" , |
1779 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1780 | const std::string& n3 = "D" , |
1781 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1782 | const std::string& n4 = "E" , |
1783 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1784 | const std::string& n5 = "F" , |
1785 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1786 | const std::string& n6 = "G" , |
1787 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1788 | const std::string& n7 = "H" , |
1789 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1790 | const std::string& n8 = "I" , |
1791 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1792 | const std::string& n9 = "J" , |
1793 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1794 | const std::string& n10 = "K" , |
1795 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1796 | const std::string& n11 = "L" , |
1797 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1798 | const std::string& n12 = "M" , |
1799 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12), |
1800 | const std::string& n13 = "N" , |
1801 | typename TypeWrapper<T13>::CONSTTYPE& t13 = POCO_TYPEWRAPPER_DEFAULTVALUE(T13)): |
1802 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13), |
1803 | _pNames(0) |
1804 | { |
1805 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13); |
1806 | } |
1807 | |
1808 | const DynamicAny get(const std::string& name) const |
1809 | { |
1810 | NameVec::const_iterator it = _pNames->begin(); |
1811 | NameVec::const_iterator itEnd = _pNames->end(); |
1812 | |
1813 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
1814 | { |
1815 | if (name == *it) |
1816 | { |
1817 | switch (counter) |
1818 | { |
1819 | case 0: return TupleType::template get<0>(); |
1820 | case 1: return TupleType::template get<1>(); |
1821 | case 2: return TupleType::template get<2>(); |
1822 | case 3: return TupleType::template get<3>(); |
1823 | case 4: return TupleType::template get<4>(); |
1824 | case 5: return TupleType::template get<5>(); |
1825 | case 6: return TupleType::template get<6>(); |
1826 | case 7: return TupleType::template get<7>(); |
1827 | case 8: return TupleType::template get<8>(); |
1828 | case 9: return TupleType::template get<9>(); |
1829 | case 10: return TupleType::template get<10>(); |
1830 | case 11: return TupleType::template get<11>(); |
1831 | case 12: return TupleType::template get<12>(); |
1832 | case 13: return TupleType::template get<13>(); |
1833 | default: throw RangeException(); |
1834 | } |
1835 | } |
1836 | } |
1837 | |
1838 | throw NotFoundException("Name not found: " + name); |
1839 | } |
1840 | |
1841 | const DynamicAny operator [] (const std::string& name) const |
1842 | { |
1843 | return get(name); |
1844 | } |
1845 | |
1846 | template<int N> |
1847 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
1848 | { |
1849 | return TupleType::template get<N>(); |
1850 | } |
1851 | |
1852 | template<int N> |
1853 | typename TypeGetter<N, Type>::HeadType& get() |
1854 | { |
1855 | return TupleType::template get<N>(); |
1856 | } |
1857 | |
1858 | template<int N> |
1859 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
1860 | { |
1861 | return TupleType::template set<N>(val); |
1862 | } |
1863 | |
1864 | const NameVecPtr& names() |
1865 | { |
1866 | return _pNames; |
1867 | } |
1868 | |
1869 | void setName(std::size_t index, const std::string& name) |
1870 | { |
1871 | if (index >= _pNames->size()) |
1872 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1873 | |
1874 | (*_pNames)[index] = name; |
1875 | } |
1876 | |
1877 | const std::string& getName(std::size_t index) |
1878 | { |
1879 | if (index >= _pNames->size()) |
1880 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
1881 | |
1882 | return (*_pNames)[index]; |
1883 | } |
1884 | |
1885 | bool operator == (const NamedTuple& other) const |
1886 | { |
1887 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
1888 | } |
1889 | |
1890 | bool operator != (const NamedTuple& other) const |
1891 | { |
1892 | return !(*this == other); |
1893 | } |
1894 | |
1895 | bool operator < (const NamedTuple& other) const |
1896 | { |
1897 | TupleType th(*this); |
1898 | TupleType oth(other); |
1899 | |
1900 | return (th < oth && _pNames == other._pNames) || |
1901 | (th == oth && _pNames < other._pNames) || |
1902 | (th < oth && _pNames < other._pNames); |
1903 | } |
1904 | |
1905 | private: |
1906 | void init(const std::string& n0 = "A" , |
1907 | const std::string& n1 = "B" , |
1908 | const std::string& n2 = "C" , |
1909 | const std::string& n3 = "D" , |
1910 | const std::string& n4 = "E" , |
1911 | const std::string& n5 = "F" , |
1912 | const std::string& n6 = "G" , |
1913 | const std::string& n7 = "H" , |
1914 | const std::string& n8 = "I" , |
1915 | const std::string& n9 = "J" , |
1916 | const std::string& n10 = "K" , |
1917 | const std::string& n11 = "L" , |
1918 | const std::string& n12 = "M" , |
1919 | const std::string& n13 = "N" ) |
1920 | { |
1921 | if (!_pNames) |
1922 | { |
1923 | _pNames = new NameVec; |
1924 | _pNames->push_back(n0); |
1925 | _pNames->push_back(n1); |
1926 | _pNames->push_back(n2); |
1927 | _pNames->push_back(n3); |
1928 | _pNames->push_back(n4); |
1929 | _pNames->push_back(n5); |
1930 | _pNames->push_back(n6); |
1931 | _pNames->push_back(n7); |
1932 | _pNames->push_back(n8); |
1933 | _pNames->push_back(n9); |
1934 | _pNames->push_back(n10); |
1935 | _pNames->push_back(n11); |
1936 | _pNames->push_back(n12); |
1937 | _pNames->push_back(n13); |
1938 | } |
1939 | } |
1940 | |
1941 | NameVecPtr _pNames; |
1942 | }; |
1943 | |
1944 | |
1945 | template<class T0, |
1946 | class T1, |
1947 | class T2, |
1948 | class T3, |
1949 | class T4, |
1950 | class T5, |
1951 | class T6, |
1952 | class T7, |
1953 | class T8, |
1954 | class T9, |
1955 | class T10, |
1956 | class T11, |
1957 | class T12> |
1958 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,NullTypeList>: |
1959 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> |
1960 | { |
1961 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> TupleType; |
1962 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>::Type Type; |
1963 | |
1964 | typedef std::vector<std::string> NameVec; |
1965 | typedef SharedPtr<NameVec> NameVecPtr; |
1966 | |
1967 | NamedTuple(): _pNames(0) |
1968 | { |
1969 | init(); |
1970 | } |
1971 | |
1972 | NamedTuple(const NameVecPtr& rNames) |
1973 | { |
1974 | if (rNames->size() != TupleType::length) |
1975 | throw InvalidArgumentException("Wrong names vector length." ); |
1976 | |
1977 | _pNames = rNames; |
1978 | } |
1979 | |
1980 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
1981 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
1982 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
1983 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
1984 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
1985 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
1986 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
1987 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
1988 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
1989 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
1990 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
1991 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
1992 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): |
1993 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12), |
1994 | _pNames(0) |
1995 | { |
1996 | init(); |
1997 | } |
1998 | |
1999 | NamedTuple(const NameVecPtr& rNames, |
2000 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2001 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2002 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2003 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2004 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2005 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2006 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2007 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2008 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2009 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2010 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
2011 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
2012 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): |
2013 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12) |
2014 | { |
2015 | if (rNames->size() != TupleType::length) |
2016 | throw InvalidArgumentException("Wrong names vector length." ); |
2017 | |
2018 | _pNames = rNames; |
2019 | } |
2020 | |
2021 | NamedTuple(const std::string& n0, |
2022 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2023 | const std::string& n1 = "B" , |
2024 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2025 | const std::string& n2 = "C" , |
2026 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2027 | const std::string& n3 = "D" , |
2028 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2029 | const std::string& n4 = "E" , |
2030 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2031 | const std::string& n5 = "F" , |
2032 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2033 | const std::string& n6 = "G" , |
2034 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2035 | const std::string& n7 = "H" , |
2036 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2037 | const std::string& n8 = "I" , |
2038 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2039 | const std::string& n9 = "J" , |
2040 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2041 | const std::string& n10 = "K" , |
2042 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
2043 | const std::string& n11 = "L" , |
2044 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11), |
2045 | const std::string& n12 = "M" , |
2046 | typename TypeWrapper<T12>::CONSTTYPE& t12 = POCO_TYPEWRAPPER_DEFAULTVALUE(T12)): |
2047 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12), _pNames(0) |
2048 | { |
2049 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12); |
2050 | } |
2051 | |
2052 | const DynamicAny get(const std::string& name) const |
2053 | { |
2054 | NameVec::const_iterator it = _pNames->begin(); |
2055 | NameVec::const_iterator itEnd = _pNames->end(); |
2056 | |
2057 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
2058 | { |
2059 | if (name == *it) |
2060 | { |
2061 | switch (counter) |
2062 | { |
2063 | case 0: return TupleType::template get<0>(); |
2064 | case 1: return TupleType::template get<1>(); |
2065 | case 2: return TupleType::template get<2>(); |
2066 | case 3: return TupleType::template get<3>(); |
2067 | case 4: return TupleType::template get<4>(); |
2068 | case 5: return TupleType::template get<5>(); |
2069 | case 6: return TupleType::template get<6>(); |
2070 | case 7: return TupleType::template get<7>(); |
2071 | case 8: return TupleType::template get<8>(); |
2072 | case 9: return TupleType::template get<9>(); |
2073 | case 10: return TupleType::template get<10>(); |
2074 | case 11: return TupleType::template get<11>(); |
2075 | case 12: return TupleType::template get<12>(); |
2076 | default: throw RangeException(); |
2077 | } |
2078 | } |
2079 | } |
2080 | |
2081 | throw NotFoundException("Name not found: " + name); |
2082 | } |
2083 | |
2084 | const DynamicAny operator [] (const std::string& name) const |
2085 | { |
2086 | return get(name); |
2087 | } |
2088 | |
2089 | template<int N> |
2090 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
2091 | { |
2092 | return TupleType::template get<N>(); |
2093 | } |
2094 | |
2095 | template<int N> |
2096 | typename TypeGetter<N, Type>::HeadType& get() |
2097 | { |
2098 | return TupleType::template get<N>(); |
2099 | } |
2100 | |
2101 | template<int N> |
2102 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
2103 | { |
2104 | return TupleType::template set<N>(val); |
2105 | } |
2106 | |
2107 | const NameVecPtr& names() |
2108 | { |
2109 | return _pNames; |
2110 | } |
2111 | |
2112 | void setName(std::size_t index, const std::string& name) |
2113 | { |
2114 | if (index >= _pNames->size()) |
2115 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2116 | |
2117 | (*_pNames)[index] = name; |
2118 | } |
2119 | |
2120 | const std::string& getName(std::size_t index) |
2121 | { |
2122 | if (index >= _pNames->size()) |
2123 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2124 | |
2125 | return (*_pNames)[index]; |
2126 | } |
2127 | |
2128 | bool operator == (const NamedTuple& other) const |
2129 | { |
2130 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
2131 | } |
2132 | |
2133 | bool operator != (const NamedTuple& other) const |
2134 | { |
2135 | return !(*this == other); |
2136 | } |
2137 | |
2138 | bool operator < (const NamedTuple& other) const |
2139 | { |
2140 | TupleType th(*this); |
2141 | TupleType oth(other); |
2142 | |
2143 | return (th < oth && _pNames == other._pNames) || |
2144 | (th == oth && _pNames < other._pNames) || |
2145 | (th < oth && _pNames < other._pNames); |
2146 | } |
2147 | |
2148 | private: |
2149 | void init(const std::string& n0 = "A" , |
2150 | const std::string& n1 = "B" , |
2151 | const std::string& n2 = "C" , |
2152 | const std::string& n3 = "D" , |
2153 | const std::string& n4 = "E" , |
2154 | const std::string& n5 = "F" , |
2155 | const std::string& n6 = "G" , |
2156 | const std::string& n7 = "H" , |
2157 | const std::string& n8 = "I" , |
2158 | const std::string& n9 = "J" , |
2159 | const std::string& n10 = "K" , |
2160 | const std::string& n11 = "L" , |
2161 | const std::string& n12 = "M" ) |
2162 | { |
2163 | if (!_pNames) |
2164 | { |
2165 | _pNames = new NameVec; |
2166 | _pNames->push_back(n0); |
2167 | _pNames->push_back(n1); |
2168 | _pNames->push_back(n2); |
2169 | _pNames->push_back(n3); |
2170 | _pNames->push_back(n4); |
2171 | _pNames->push_back(n5); |
2172 | _pNames->push_back(n6); |
2173 | _pNames->push_back(n7); |
2174 | _pNames->push_back(n8); |
2175 | _pNames->push_back(n9); |
2176 | _pNames->push_back(n10); |
2177 | _pNames->push_back(n11); |
2178 | _pNames->push_back(n12); |
2179 | } |
2180 | } |
2181 | |
2182 | NameVecPtr _pNames; |
2183 | }; |
2184 | |
2185 | |
2186 | template<class T0, |
2187 | class T1, |
2188 | class T2, |
2189 | class T3, |
2190 | class T4, |
2191 | class T5, |
2192 | class T6, |
2193 | class T7, |
2194 | class T8, |
2195 | class T9, |
2196 | class T10, |
2197 | class T11> |
2198 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,NullTypeList>: |
2199 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> |
2200 | { |
2201 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> TupleType; |
2202 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::Type Type; |
2203 | |
2204 | typedef std::vector<std::string> NameVec; |
2205 | typedef SharedPtr<NameVec> NameVecPtr; |
2206 | |
2207 | NamedTuple(): _pNames(0) |
2208 | { |
2209 | init(); |
2210 | } |
2211 | |
2212 | NamedTuple(const NameVecPtr& rNames) |
2213 | { |
2214 | if (rNames->size() != TupleType::length) |
2215 | throw InvalidArgumentException("Wrong names vector length." ); |
2216 | |
2217 | _pNames = rNames; |
2218 | } |
2219 | |
2220 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
2221 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2222 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2223 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2224 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2225 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2226 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2227 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2228 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2229 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2230 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
2231 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): |
2232 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11), |
2233 | _pNames(0) |
2234 | { |
2235 | init(); |
2236 | } |
2237 | |
2238 | NamedTuple(const NameVecPtr& rNames, |
2239 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2240 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2241 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2242 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2243 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2244 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2245 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2246 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2247 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2248 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2249 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
2250 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): |
2251 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11) |
2252 | { |
2253 | if (rNames->size() != TupleType::length) |
2254 | throw InvalidArgumentException("Wrong names vector length." ); |
2255 | |
2256 | _pNames = rNames; |
2257 | } |
2258 | |
2259 | NamedTuple(const std::string& n0, |
2260 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2261 | const std::string& n1 = "B" , |
2262 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2263 | const std::string& n2 = "C" , |
2264 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2265 | const std::string& n3 = "D" , |
2266 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2267 | const std::string& n4 = "E" , |
2268 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2269 | const std::string& n5 = "F" , |
2270 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2271 | const std::string& n6 = "G" , |
2272 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2273 | const std::string& n7 = "H" , |
2274 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2275 | const std::string& n8 = "I" , |
2276 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2277 | const std::string& n9 = "J" , |
2278 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2279 | const std::string& n10 = "K" , |
2280 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10), |
2281 | const std::string& n11 = "L" , |
2282 | typename TypeWrapper<T11>::CONSTTYPE& t11 = POCO_TYPEWRAPPER_DEFAULTVALUE(T11)): |
2283 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11), |
2284 | _pNames(0) |
2285 | { |
2286 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11); |
2287 | } |
2288 | |
2289 | const DynamicAny get(const std::string& name) const |
2290 | { |
2291 | NameVec::const_iterator it = _pNames->begin(); |
2292 | NameVec::const_iterator itEnd = _pNames->end(); |
2293 | |
2294 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
2295 | { |
2296 | if (name == *it) |
2297 | { |
2298 | switch (counter) |
2299 | { |
2300 | case 0: return TupleType::template get<0>(); |
2301 | case 1: return TupleType::template get<1>(); |
2302 | case 2: return TupleType::template get<2>(); |
2303 | case 3: return TupleType::template get<3>(); |
2304 | case 4: return TupleType::template get<4>(); |
2305 | case 5: return TupleType::template get<5>(); |
2306 | case 6: return TupleType::template get<6>(); |
2307 | case 7: return TupleType::template get<7>(); |
2308 | case 8: return TupleType::template get<8>(); |
2309 | case 9: return TupleType::template get<9>(); |
2310 | case 10: return TupleType::template get<10>(); |
2311 | case 11: return TupleType::template get<11>(); |
2312 | default: throw RangeException(); |
2313 | } |
2314 | } |
2315 | } |
2316 | |
2317 | throw NotFoundException("Name not found: " + name); |
2318 | } |
2319 | |
2320 | const DynamicAny operator [] (const std::string& name) const |
2321 | { |
2322 | return get(name); |
2323 | } |
2324 | |
2325 | template<int N> |
2326 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
2327 | { |
2328 | return TupleType::template get<N>(); |
2329 | } |
2330 | |
2331 | template<int N> |
2332 | typename TypeGetter<N, Type>::HeadType& get() |
2333 | { |
2334 | return TupleType::template get<N>(); |
2335 | } |
2336 | |
2337 | template<int N> |
2338 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
2339 | { |
2340 | return TupleType::template set<N>(val); |
2341 | } |
2342 | |
2343 | const NameVecPtr& names() |
2344 | { |
2345 | return _pNames; |
2346 | } |
2347 | |
2348 | void setName(std::size_t index, const std::string& name) |
2349 | { |
2350 | if (index >= _pNames->size()) |
2351 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2352 | |
2353 | (*_pNames)[index] = name; |
2354 | } |
2355 | |
2356 | const std::string& getName(std::size_t index) |
2357 | { |
2358 | if (index >= _pNames->size()) |
2359 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2360 | |
2361 | return (*_pNames)[index]; |
2362 | } |
2363 | |
2364 | bool operator == (const NamedTuple& other) const |
2365 | { |
2366 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
2367 | } |
2368 | |
2369 | bool operator != (const NamedTuple& other) const |
2370 | { |
2371 | return !(*this == other); |
2372 | } |
2373 | |
2374 | bool operator < (const NamedTuple& other) const |
2375 | { |
2376 | TupleType th(*this); |
2377 | TupleType oth(other); |
2378 | |
2379 | return (th < oth && _pNames == other._pNames) || |
2380 | (th == oth && _pNames < other._pNames) || |
2381 | (th < oth && _pNames < other._pNames); |
2382 | } |
2383 | |
2384 | private: |
2385 | void init(const std::string& n0 = "A" , |
2386 | const std::string& n1 = "B" , |
2387 | const std::string& n2 = "C" , |
2388 | const std::string& n3 = "D" , |
2389 | const std::string& n4 = "E" , |
2390 | const std::string& n5 = "F" , |
2391 | const std::string& n6 = "G" , |
2392 | const std::string& n7 = "H" , |
2393 | const std::string& n8 = "I" , |
2394 | const std::string& n9 = "J" , |
2395 | const std::string& n10 = "K" , |
2396 | const std::string& n11 = "L" ) |
2397 | { |
2398 | if (!_pNames) |
2399 | { |
2400 | _pNames = new NameVec; |
2401 | _pNames->push_back(n0); |
2402 | _pNames->push_back(n1); |
2403 | _pNames->push_back(n2); |
2404 | _pNames->push_back(n3); |
2405 | _pNames->push_back(n4); |
2406 | _pNames->push_back(n5); |
2407 | _pNames->push_back(n6); |
2408 | _pNames->push_back(n7); |
2409 | _pNames->push_back(n8); |
2410 | _pNames->push_back(n9); |
2411 | _pNames->push_back(n10); |
2412 | _pNames->push_back(n11); |
2413 | } |
2414 | } |
2415 | |
2416 | NameVecPtr _pNames; |
2417 | }; |
2418 | |
2419 | |
2420 | template<class T0, |
2421 | class T1, |
2422 | class T2, |
2423 | class T3, |
2424 | class T4, |
2425 | class T5, |
2426 | class T6, |
2427 | class T7, |
2428 | class T8, |
2429 | class T9, |
2430 | class T10> |
2431 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,NullTypeList>: |
2432 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> |
2433 | { |
2434 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> TupleType; |
2435 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Type Type; |
2436 | |
2437 | typedef std::vector<std::string> NameVec; |
2438 | typedef SharedPtr<NameVec> NameVecPtr; |
2439 | |
2440 | NamedTuple(): _pNames(0) |
2441 | { |
2442 | init(); |
2443 | } |
2444 | |
2445 | NamedTuple(const NameVecPtr& rNames) |
2446 | { |
2447 | if (rNames->size() != TupleType::length) |
2448 | throw InvalidArgumentException("Wrong names vector length." ); |
2449 | |
2450 | _pNames = rNames; |
2451 | } |
2452 | |
2453 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
2454 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2455 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2456 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2457 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2458 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2459 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2460 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2461 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2462 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2463 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): |
2464 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10), |
2465 | _pNames(0) |
2466 | { |
2467 | init(); |
2468 | } |
2469 | |
2470 | NamedTuple(const NameVecPtr& rNames, |
2471 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2472 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2473 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2474 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2475 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2476 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2477 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2478 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2479 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2480 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2481 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): |
2482 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) |
2483 | { |
2484 | if (rNames->size() != TupleType::length) |
2485 | throw InvalidArgumentException("Wrong names vector length." ); |
2486 | |
2487 | _pNames = rNames; |
2488 | } |
2489 | |
2490 | NamedTuple(const std::string& n0, |
2491 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2492 | const std::string& n1 = "B" , |
2493 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2494 | const std::string& n2 = "C" , |
2495 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2496 | const std::string& n3 = "D" , |
2497 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2498 | const std::string& n4 = "E" , |
2499 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2500 | const std::string& n5 = "F" , |
2501 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2502 | const std::string& n6 = "G" , |
2503 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2504 | const std::string& n7 = "H" , |
2505 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2506 | const std::string& n8 = "I" , |
2507 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2508 | const std::string& n9 = "J" , |
2509 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9), |
2510 | const std::string& n10 = "K" , |
2511 | typename TypeWrapper<T10>::CONSTTYPE& t10 = POCO_TYPEWRAPPER_DEFAULTVALUE(T10)): |
2512 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10), _pNames(0) |
2513 | { |
2514 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10); |
2515 | } |
2516 | |
2517 | const DynamicAny get(const std::string& name) const |
2518 | { |
2519 | NameVec::const_iterator it = _pNames->begin(); |
2520 | NameVec::const_iterator itEnd = _pNames->end(); |
2521 | |
2522 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
2523 | { |
2524 | if (name == *it) |
2525 | { |
2526 | switch (counter) |
2527 | { |
2528 | case 0: return TupleType::template get<0>(); |
2529 | case 1: return TupleType::template get<1>(); |
2530 | case 2: return TupleType::template get<2>(); |
2531 | case 3: return TupleType::template get<3>(); |
2532 | case 4: return TupleType::template get<4>(); |
2533 | case 5: return TupleType::template get<5>(); |
2534 | case 6: return TupleType::template get<6>(); |
2535 | case 7: return TupleType::template get<7>(); |
2536 | case 8: return TupleType::template get<8>(); |
2537 | case 9: return TupleType::template get<9>(); |
2538 | case 10: return TupleType::template get<10>(); |
2539 | default: throw RangeException(); |
2540 | } |
2541 | } |
2542 | } |
2543 | |
2544 | throw NotFoundException("Name not found: " + name); |
2545 | } |
2546 | |
2547 | const DynamicAny operator [] (const std::string& name) const |
2548 | { |
2549 | return get(name); |
2550 | } |
2551 | |
2552 | template<int N> |
2553 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
2554 | { |
2555 | return TupleType::template get<N>(); |
2556 | } |
2557 | |
2558 | template<int N> |
2559 | typename TypeGetter<N, Type>::HeadType& get() |
2560 | { |
2561 | return TupleType::template get<N>(); |
2562 | } |
2563 | |
2564 | template<int N> |
2565 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
2566 | { |
2567 | return TupleType::template set<N>(val); |
2568 | } |
2569 | |
2570 | const NameVecPtr& names() |
2571 | { |
2572 | return _pNames; |
2573 | } |
2574 | |
2575 | void setName(std::size_t index, const std::string& name) |
2576 | { |
2577 | if (index >= _pNames->size()) |
2578 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2579 | |
2580 | (*_pNames)[index] = name; |
2581 | } |
2582 | |
2583 | const std::string& getName(std::size_t index) |
2584 | { |
2585 | if (index >= _pNames->size()) |
2586 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2587 | |
2588 | return (*_pNames)[index]; |
2589 | } |
2590 | |
2591 | bool operator == (const NamedTuple& other) const |
2592 | { |
2593 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
2594 | } |
2595 | |
2596 | bool operator != (const NamedTuple& other) const |
2597 | { |
2598 | return !(*this == other); |
2599 | } |
2600 | |
2601 | bool operator < (const NamedTuple& other) const |
2602 | { |
2603 | TupleType th(*this); |
2604 | TupleType oth(other); |
2605 | |
2606 | return (th < oth && _pNames == other._pNames) || |
2607 | (th == oth && _pNames < other._pNames) || |
2608 | (th < oth && _pNames < other._pNames); |
2609 | } |
2610 | |
2611 | private: |
2612 | void init(const std::string& n0 = "A" , |
2613 | const std::string& n1 = "B" , |
2614 | const std::string& n2 = "C" , |
2615 | const std::string& n3 = "D" , |
2616 | const std::string& n4 = "E" , |
2617 | const std::string& n5 = "F" , |
2618 | const std::string& n6 = "G" , |
2619 | const std::string& n7 = "H" , |
2620 | const std::string& n8 = "I" , |
2621 | const std::string& n9 = "J" , |
2622 | const std::string& n10 = "K" ) |
2623 | { |
2624 | if (!_pNames) |
2625 | { |
2626 | _pNames = new NameVec; |
2627 | _pNames->push_back(n0); |
2628 | _pNames->push_back(n1); |
2629 | _pNames->push_back(n2); |
2630 | _pNames->push_back(n3); |
2631 | _pNames->push_back(n4); |
2632 | _pNames->push_back(n5); |
2633 | _pNames->push_back(n6); |
2634 | _pNames->push_back(n7); |
2635 | _pNames->push_back(n8); |
2636 | _pNames->push_back(n9); |
2637 | _pNames->push_back(n10); |
2638 | } |
2639 | } |
2640 | |
2641 | NameVecPtr _pNames; |
2642 | }; |
2643 | |
2644 | |
2645 | template<class T0, |
2646 | class T1, |
2647 | class T2, |
2648 | class T3, |
2649 | class T4, |
2650 | class T5, |
2651 | class T6, |
2652 | class T7, |
2653 | class T8, |
2654 | class T9> |
2655 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,NullTypeList>: |
2656 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9> |
2657 | { |
2658 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9> TupleType; |
2659 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>::Type Type; |
2660 | |
2661 | typedef std::vector<std::string> NameVec; |
2662 | typedef SharedPtr<NameVec> NameVecPtr; |
2663 | |
2664 | NamedTuple(): _pNames(0) |
2665 | { |
2666 | init(); |
2667 | } |
2668 | |
2669 | NamedTuple(const NameVecPtr& rNames) |
2670 | { |
2671 | if (rNames->size() != TupleType::length) |
2672 | throw InvalidArgumentException("Wrong names vector length." ); |
2673 | |
2674 | _pNames = rNames; |
2675 | } |
2676 | |
2677 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
2678 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2679 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2680 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2681 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2682 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2683 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2684 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2685 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2686 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): |
2687 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9), |
2688 | _pNames(0) |
2689 | { |
2690 | init(); |
2691 | } |
2692 | |
2693 | NamedTuple(const NameVecPtr& rNames, |
2694 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2695 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2696 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2697 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2698 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2699 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2700 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2701 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2702 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2703 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): |
2704 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9) |
2705 | { |
2706 | if (rNames->size() != TupleType::length) |
2707 | throw InvalidArgumentException("Wrong names vector length." ); |
2708 | |
2709 | _pNames = rNames; |
2710 | } |
2711 | |
2712 | NamedTuple(const std::string& n0, |
2713 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2714 | const std::string& n1 = "B" , |
2715 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2716 | const std::string& n2 = "C" , |
2717 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2718 | const std::string& n3 = "D" , |
2719 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2720 | const std::string& n4 = "E" , |
2721 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2722 | const std::string& n5 = "F" , |
2723 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2724 | const std::string& n6 = "G" , |
2725 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2726 | const std::string& n7 = "H" , |
2727 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2728 | const std::string& n8 = "I" , |
2729 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8), |
2730 | const std::string& n9 = "J" , |
2731 | typename TypeWrapper<T9>::CONSTTYPE& t9 = POCO_TYPEWRAPPER_DEFAULTVALUE(T9)): |
2732 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8,t9), |
2733 | _pNames(0) |
2734 | { |
2735 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9); |
2736 | } |
2737 | |
2738 | const DynamicAny get(const std::string& name) const |
2739 | { |
2740 | NameVec::const_iterator it = _pNames->begin(); |
2741 | NameVec::const_iterator itEnd = _pNames->end(); |
2742 | |
2743 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
2744 | { |
2745 | if (name == *it) |
2746 | { |
2747 | switch (counter) |
2748 | { |
2749 | case 0: return TupleType::template get<0>(); |
2750 | case 1: return TupleType::template get<1>(); |
2751 | case 2: return TupleType::template get<2>(); |
2752 | case 3: return TupleType::template get<3>(); |
2753 | case 4: return TupleType::template get<4>(); |
2754 | case 5: return TupleType::template get<5>(); |
2755 | case 6: return TupleType::template get<6>(); |
2756 | case 7: return TupleType::template get<7>(); |
2757 | case 8: return TupleType::template get<8>(); |
2758 | case 9: return TupleType::template get<9>(); |
2759 | default: throw RangeException(); |
2760 | } |
2761 | } |
2762 | } |
2763 | |
2764 | throw NotFoundException("Name not found: " + name); |
2765 | } |
2766 | |
2767 | const DynamicAny operator [] (const std::string& name) const |
2768 | { |
2769 | return get(name); |
2770 | } |
2771 | |
2772 | template<int N> |
2773 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
2774 | { |
2775 | return TupleType::template get<N>(); |
2776 | } |
2777 | |
2778 | template<int N> |
2779 | typename TypeGetter<N, Type>::HeadType& get() |
2780 | { |
2781 | return TupleType::template get<N>(); |
2782 | } |
2783 | |
2784 | template<int N> |
2785 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
2786 | { |
2787 | return TupleType::template set<N>(val); |
2788 | } |
2789 | |
2790 | const NameVecPtr& names() |
2791 | { |
2792 | return _pNames; |
2793 | } |
2794 | |
2795 | void setName(std::size_t index, const std::string& name) |
2796 | { |
2797 | if (index >= _pNames->size()) |
2798 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2799 | |
2800 | (*_pNames)[index] = name; |
2801 | } |
2802 | |
2803 | const std::string& getName(std::size_t index) |
2804 | { |
2805 | if (index >= _pNames->size()) |
2806 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
2807 | |
2808 | return (*_pNames)[index]; |
2809 | } |
2810 | |
2811 | bool operator == (const NamedTuple& other) const |
2812 | { |
2813 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
2814 | } |
2815 | |
2816 | bool operator != (const NamedTuple& other) const |
2817 | { |
2818 | return !(*this == other); |
2819 | } |
2820 | |
2821 | bool operator < (const NamedTuple& other) const |
2822 | { |
2823 | TupleType th(*this); |
2824 | TupleType oth(other); |
2825 | |
2826 | return (th < oth && _pNames == other._pNames) || |
2827 | (th == oth && _pNames < other._pNames) || |
2828 | (th < oth && _pNames < other._pNames); |
2829 | } |
2830 | |
2831 | private: |
2832 | void init(const std::string& n0 = "A" , |
2833 | const std::string& n1 = "B" , |
2834 | const std::string& n2 = "C" , |
2835 | const std::string& n3 = "D" , |
2836 | const std::string& n4 = "E" , |
2837 | const std::string& n5 = "F" , |
2838 | const std::string& n6 = "G" , |
2839 | const std::string& n7 = "H" , |
2840 | const std::string& n8 = "I" , |
2841 | const std::string& n9 = "J" ) |
2842 | { |
2843 | if (!_pNames) |
2844 | { |
2845 | _pNames = new NameVec; |
2846 | _pNames->push_back(n0); |
2847 | _pNames->push_back(n1); |
2848 | _pNames->push_back(n2); |
2849 | _pNames->push_back(n3); |
2850 | _pNames->push_back(n4); |
2851 | _pNames->push_back(n5); |
2852 | _pNames->push_back(n6); |
2853 | _pNames->push_back(n7); |
2854 | _pNames->push_back(n8); |
2855 | _pNames->push_back(n9); |
2856 | } |
2857 | } |
2858 | |
2859 | NameVecPtr _pNames; |
2860 | }; |
2861 | |
2862 | |
2863 | template<class T0, |
2864 | class T1, |
2865 | class T2, |
2866 | class T3, |
2867 | class T4, |
2868 | class T5, |
2869 | class T6, |
2870 | class T7, |
2871 | class T8> |
2872 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,NullTypeList>: |
2873 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8> |
2874 | { |
2875 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8> TupleType; |
2876 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8>::Type Type; |
2877 | |
2878 | typedef std::vector<std::string> NameVec; |
2879 | typedef SharedPtr<NameVec> NameVecPtr; |
2880 | |
2881 | NamedTuple(): _pNames(0) |
2882 | { |
2883 | init(); |
2884 | } |
2885 | |
2886 | NamedTuple(const NameVecPtr& rNames) |
2887 | { |
2888 | if (rNames->size() != TupleType::length) |
2889 | throw InvalidArgumentException("Wrong names vector length." ); |
2890 | |
2891 | _pNames = rNames; |
2892 | } |
2893 | |
2894 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
2895 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2896 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2897 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2898 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2899 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2900 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2901 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2902 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): |
2903 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8), |
2904 | _pNames(0) |
2905 | { |
2906 | init(); |
2907 | } |
2908 | |
2909 | NamedTuple(const NameVecPtr& rNames, |
2910 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2911 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2912 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2913 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2914 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2915 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2916 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2917 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2918 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): |
2919 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8) |
2920 | { |
2921 | if (rNames->size() != TupleType::length) |
2922 | throw InvalidArgumentException("Wrong names vector length." ); |
2923 | |
2924 | _pNames = rNames; |
2925 | } |
2926 | |
2927 | NamedTuple(const std::string& n0, |
2928 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
2929 | const std::string& n1 = "B" , |
2930 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
2931 | const std::string& n2 = "C" , |
2932 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
2933 | const std::string& n3 = "D" , |
2934 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
2935 | const std::string& n4 = "E" , |
2936 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
2937 | const std::string& n5 = "F" , |
2938 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
2939 | const std::string& n6 = "G" , |
2940 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
2941 | const std::string& n7 = "H" , |
2942 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7), |
2943 | const std::string& n8 = "I" , |
2944 | typename TypeWrapper<T8>::CONSTTYPE& t8 = POCO_TYPEWRAPPER_DEFAULTVALUE(T8)): |
2945 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7,t8), |
2946 | _pNames(0) |
2947 | { |
2948 | init(n0,n1,n2,n3,n4,n5,n6,n7,n8); |
2949 | } |
2950 | |
2951 | const DynamicAny get(const std::string& name) const |
2952 | { |
2953 | NameVec::const_iterator it = _pNames->begin(); |
2954 | NameVec::const_iterator itEnd = _pNames->end(); |
2955 | |
2956 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
2957 | { |
2958 | if (name == *it) |
2959 | { |
2960 | switch (counter) |
2961 | { |
2962 | case 0: return TupleType::template get<0>(); |
2963 | case 1: return TupleType::template get<1>(); |
2964 | case 2: return TupleType::template get<2>(); |
2965 | case 3: return TupleType::template get<3>(); |
2966 | case 4: return TupleType::template get<4>(); |
2967 | case 5: return TupleType::template get<5>(); |
2968 | case 6: return TupleType::template get<6>(); |
2969 | case 7: return TupleType::template get<7>(); |
2970 | case 8: return TupleType::template get<8>(); |
2971 | default: throw RangeException(); |
2972 | } |
2973 | } |
2974 | } |
2975 | |
2976 | throw NotFoundException("Name not found: " + name); |
2977 | } |
2978 | |
2979 | const DynamicAny operator [] (const std::string& name) const |
2980 | { |
2981 | return get(name); |
2982 | } |
2983 | |
2984 | template<int N> |
2985 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
2986 | { |
2987 | return TupleType::template get<N>(); |
2988 | } |
2989 | |
2990 | template<int N> |
2991 | typename TypeGetter<N, Type>::HeadType& get() |
2992 | { |
2993 | return TupleType::template get<N>(); |
2994 | } |
2995 | |
2996 | template<int N> |
2997 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
2998 | { |
2999 | return TupleType::template set<N>(val); |
3000 | } |
3001 | |
3002 | const NameVecPtr& names() |
3003 | { |
3004 | return _pNames; |
3005 | } |
3006 | |
3007 | void setName(std::size_t index, const std::string& name) |
3008 | { |
3009 | if (index >= _pNames->size()) |
3010 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3011 | |
3012 | (*_pNames)[index] = name; |
3013 | } |
3014 | |
3015 | const std::string& getName(std::size_t index) |
3016 | { |
3017 | if (index >= _pNames->size()) |
3018 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3019 | |
3020 | return (*_pNames)[index]; |
3021 | } |
3022 | |
3023 | bool operator == (const NamedTuple& other) const |
3024 | { |
3025 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
3026 | } |
3027 | |
3028 | bool operator != (const NamedTuple& other) const |
3029 | { |
3030 | return !(*this == other); |
3031 | } |
3032 | |
3033 | bool operator < (const NamedTuple& other) const |
3034 | { |
3035 | TupleType th(*this); |
3036 | TupleType oth(other); |
3037 | |
3038 | return (th < oth && _pNames == other._pNames) || |
3039 | (th == oth && _pNames < other._pNames) || |
3040 | (th < oth && _pNames < other._pNames); |
3041 | } |
3042 | |
3043 | private: |
3044 | void init(const std::string& n0 = "A" , |
3045 | const std::string& n1 = "B" , |
3046 | const std::string& n2 = "C" , |
3047 | const std::string& n3 = "D" , |
3048 | const std::string& n4 = "E" , |
3049 | const std::string& n5 = "F" , |
3050 | const std::string& n6 = "G" , |
3051 | const std::string& n7 = "H" , |
3052 | const std::string& n8 = "I" ) |
3053 | { |
3054 | if (!_pNames) |
3055 | { |
3056 | _pNames = new NameVec; |
3057 | _pNames->push_back(n0); |
3058 | _pNames->push_back(n1); |
3059 | _pNames->push_back(n2); |
3060 | _pNames->push_back(n3); |
3061 | _pNames->push_back(n4); |
3062 | _pNames->push_back(n5); |
3063 | _pNames->push_back(n6); |
3064 | _pNames->push_back(n7); |
3065 | _pNames->push_back(n8); |
3066 | } |
3067 | } |
3068 | |
3069 | NameVecPtr _pNames; |
3070 | }; |
3071 | |
3072 | |
3073 | template<class T0, |
3074 | class T1, |
3075 | class T2, |
3076 | class T3, |
3077 | class T4, |
3078 | class T5, |
3079 | class T6, |
3080 | class T7> |
3081 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,T7,NullTypeList>: |
3082 | public Tuple<T0,T1,T2,T3,T4,T5,T6,T7> |
3083 | { |
3084 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6,T7> TupleType; |
3085 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6,T7>::Type Type; |
3086 | |
3087 | typedef std::vector<std::string> NameVec; |
3088 | typedef SharedPtr<NameVec> NameVecPtr; |
3089 | |
3090 | NamedTuple(): _pNames(0) |
3091 | { |
3092 | init(); |
3093 | } |
3094 | |
3095 | NamedTuple(const NameVecPtr& rNames) |
3096 | { |
3097 | if (rNames->size() != TupleType::length) |
3098 | throw InvalidArgumentException("Wrong names vector length." ); |
3099 | |
3100 | _pNames = rNames; |
3101 | } |
3102 | |
3103 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
3104 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3105 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3106 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3107 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3108 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
3109 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
3110 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): |
3111 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7), |
3112 | _pNames(0) |
3113 | { |
3114 | init(); |
3115 | } |
3116 | |
3117 | NamedTuple(const NameVecPtr& rNames, |
3118 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3119 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3120 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3121 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3122 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3123 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
3124 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
3125 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): |
3126 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7) |
3127 | { |
3128 | if (rNames->size() != TupleType::length) |
3129 | throw InvalidArgumentException("Wrong names vector length." ); |
3130 | |
3131 | _pNames = rNames; |
3132 | } |
3133 | |
3134 | NamedTuple(const std::string& n0, |
3135 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3136 | const std::string& n1 = "B" , |
3137 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3138 | const std::string& n2 = "C" , |
3139 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3140 | const std::string& n3 = "D" , |
3141 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3142 | const std::string& n4 = "E" , |
3143 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3144 | const std::string& n5 = "F" , |
3145 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
3146 | const std::string& n6 = "G" , |
3147 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6), |
3148 | const std::string& n7 = "H" , |
3149 | typename TypeWrapper<T7>::CONSTTYPE& t7 = POCO_TYPEWRAPPER_DEFAULTVALUE(T7)): |
3150 | TupleType(t0,t1,t2,t3,t4,t5,t6,t7), |
3151 | _pNames(0) |
3152 | { |
3153 | init(n0,n1,n2,n3,n4,n5,n6,n7); |
3154 | } |
3155 | |
3156 | const DynamicAny get(const std::string& name) const |
3157 | { |
3158 | NameVec::const_iterator it = _pNames->begin(); |
3159 | NameVec::const_iterator itEnd = _pNames->end(); |
3160 | |
3161 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
3162 | { |
3163 | if (name == *it) |
3164 | { |
3165 | switch (counter) |
3166 | { |
3167 | case 0: return TupleType::template get<0>(); |
3168 | case 1: return TupleType::template get<1>(); |
3169 | case 2: return TupleType::template get<2>(); |
3170 | case 3: return TupleType::template get<3>(); |
3171 | case 4: return TupleType::template get<4>(); |
3172 | case 5: return TupleType::template get<5>(); |
3173 | case 6: return TupleType::template get<6>(); |
3174 | case 7: return TupleType::template get<7>(); |
3175 | default: throw RangeException(); |
3176 | } |
3177 | } |
3178 | } |
3179 | |
3180 | throw NotFoundException("Name not found: " + name); |
3181 | } |
3182 | |
3183 | const DynamicAny operator [] (const std::string& name) const |
3184 | { |
3185 | return get(name); |
3186 | } |
3187 | |
3188 | template<int N> |
3189 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
3190 | { |
3191 | return TupleType::template get<N>(); |
3192 | } |
3193 | |
3194 | template<int N> |
3195 | typename TypeGetter<N, Type>::HeadType& get() |
3196 | { |
3197 | return TupleType::template get<N>(); |
3198 | } |
3199 | |
3200 | template<int N> |
3201 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
3202 | { |
3203 | return TupleType::template set<N>(val); |
3204 | } |
3205 | |
3206 | const NameVecPtr& names() |
3207 | { |
3208 | return _pNames; |
3209 | } |
3210 | |
3211 | void setName(std::size_t index, const std::string& name) |
3212 | { |
3213 | if (index >= _pNames->size()) |
3214 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3215 | |
3216 | (*_pNames)[index] = name; |
3217 | } |
3218 | |
3219 | const std::string& getName(std::size_t index) |
3220 | { |
3221 | if (index >= _pNames->size()) |
3222 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3223 | |
3224 | return (*_pNames)[index]; |
3225 | } |
3226 | |
3227 | bool operator == (const NamedTuple& other) const |
3228 | { |
3229 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
3230 | } |
3231 | |
3232 | bool operator != (const NamedTuple& other) const |
3233 | { |
3234 | return !(*this == other); |
3235 | } |
3236 | |
3237 | bool operator < (const NamedTuple& other) const |
3238 | { |
3239 | TupleType th(*this); |
3240 | TupleType oth(other); |
3241 | |
3242 | return (th < oth && _pNames == other._pNames) || |
3243 | (th == oth && _pNames < other._pNames) || |
3244 | (th < oth && _pNames < other._pNames); |
3245 | } |
3246 | |
3247 | private: |
3248 | void init(const std::string& n0 = "A" , |
3249 | const std::string& n1 = "B" , |
3250 | const std::string& n2 = "C" , |
3251 | const std::string& n3 = "D" , |
3252 | const std::string& n4 = "E" , |
3253 | const std::string& n5 = "F" , |
3254 | const std::string& n6 = "G" , |
3255 | const std::string& n7 = "H" ) |
3256 | { |
3257 | if (!_pNames) |
3258 | { |
3259 | _pNames = new NameVec; |
3260 | _pNames->push_back(n0); |
3261 | _pNames->push_back(n1); |
3262 | _pNames->push_back(n2); |
3263 | _pNames->push_back(n3); |
3264 | _pNames->push_back(n4); |
3265 | _pNames->push_back(n5); |
3266 | _pNames->push_back(n6); |
3267 | _pNames->push_back(n7); |
3268 | } |
3269 | } |
3270 | |
3271 | NameVecPtr _pNames; |
3272 | }; |
3273 | |
3274 | |
3275 | template<class T0, |
3276 | class T1, |
3277 | class T2, |
3278 | class T3, |
3279 | class T4, |
3280 | class T5, |
3281 | class T6> |
3282 | struct NamedTuple<T0,T1,T2,T3,T4,T5,T6,NullTypeList>: |
3283 | public Tuple<T0,T1,T2,T3,T4,T5,T6> |
3284 | { |
3285 | typedef Tuple<T0,T1,T2,T3,T4,T5,T6> TupleType; |
3286 | typedef typename Tuple<T0,T1,T2,T3,T4,T5,T6>::Type Type; |
3287 | |
3288 | typedef std::vector<std::string> NameVec; |
3289 | typedef SharedPtr<NameVec> NameVecPtr; |
3290 | |
3291 | NamedTuple(): _pNames(0) |
3292 | { |
3293 | init(); |
3294 | } |
3295 | |
3296 | NamedTuple(const NameVecPtr& rNames) |
3297 | { |
3298 | if (rNames->size() != TupleType::length) |
3299 | throw InvalidArgumentException("Wrong names vector length." ); |
3300 | |
3301 | _pNames = rNames; |
3302 | } |
3303 | |
3304 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
3305 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3306 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3307 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3308 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3309 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
3310 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): |
3311 | TupleType(t0,t1,t2,t3,t4,t5,t6), _pNames(0) |
3312 | { |
3313 | init(); |
3314 | } |
3315 | |
3316 | NamedTuple(const NameVecPtr& rNames, |
3317 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3318 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3319 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3320 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3321 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3322 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
3323 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): |
3324 | TupleType(t0,t1,t2,t3,t4,t5,t6) |
3325 | { |
3326 | if (rNames->size() != TupleType::length) |
3327 | throw InvalidArgumentException("Wrong names vector length." ); |
3328 | |
3329 | _pNames = rNames; |
3330 | } |
3331 | |
3332 | NamedTuple(const std::string& n0, |
3333 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3334 | const std::string& n1 = "B" , |
3335 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3336 | const std::string& n2 = "C" , |
3337 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3338 | const std::string& n3 = "D" , |
3339 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3340 | const std::string& n4 = "E" , |
3341 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3342 | const std::string& n5 = "F" , |
3343 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5), |
3344 | const std::string& n6 = "G" , |
3345 | typename TypeWrapper<T6>::CONSTTYPE& t6 = POCO_TYPEWRAPPER_DEFAULTVALUE(T6)): |
3346 | TupleType(t0,t1,t2,t3,t4,t5,t6), _pNames(0) |
3347 | { |
3348 | init(n0,n1,n2,n3,n4,n5,n6); |
3349 | } |
3350 | |
3351 | const DynamicAny get(const std::string& name) const |
3352 | { |
3353 | NameVec::const_iterator it = _pNames->begin(); |
3354 | NameVec::const_iterator itEnd = _pNames->end(); |
3355 | |
3356 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
3357 | { |
3358 | if (name == *it) |
3359 | { |
3360 | switch (counter) |
3361 | { |
3362 | case 0: return TupleType::template get<0>(); |
3363 | case 1: return TupleType::template get<1>(); |
3364 | case 2: return TupleType::template get<2>(); |
3365 | case 3: return TupleType::template get<3>(); |
3366 | case 4: return TupleType::template get<4>(); |
3367 | case 5: return TupleType::template get<5>(); |
3368 | case 6: return TupleType::template get<6>(); |
3369 | default: throw RangeException(); |
3370 | } |
3371 | } |
3372 | } |
3373 | |
3374 | throw NotFoundException("Name not found: " + name); |
3375 | } |
3376 | |
3377 | const DynamicAny operator [] (const std::string& name) const |
3378 | { |
3379 | return get(name); |
3380 | } |
3381 | |
3382 | template<int N> |
3383 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
3384 | { |
3385 | return TupleType::template get<N>(); |
3386 | } |
3387 | |
3388 | template<int N> |
3389 | typename TypeGetter<N, Type>::HeadType& get() |
3390 | { |
3391 | return TupleType::template get<N>(); |
3392 | } |
3393 | |
3394 | template<int N> |
3395 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
3396 | { |
3397 | return TupleType::template set<N>(val); |
3398 | } |
3399 | |
3400 | const NameVecPtr& names() |
3401 | { |
3402 | return _pNames; |
3403 | } |
3404 | |
3405 | void setName(std::size_t index, const std::string& name) |
3406 | { |
3407 | if (index >= _pNames->size()) |
3408 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3409 | |
3410 | (*_pNames)[index] = name; |
3411 | } |
3412 | |
3413 | const std::string& getName(std::size_t index) |
3414 | { |
3415 | if (index >= _pNames->size()) |
3416 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3417 | |
3418 | return (*_pNames)[index]; |
3419 | } |
3420 | |
3421 | bool operator == (const NamedTuple& other) const |
3422 | { |
3423 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
3424 | } |
3425 | |
3426 | bool operator != (const NamedTuple& other) const |
3427 | { |
3428 | return !(*this == other); |
3429 | } |
3430 | |
3431 | bool operator < (const NamedTuple& other) const |
3432 | { |
3433 | TupleType th(*this); |
3434 | TupleType oth(other); |
3435 | |
3436 | return (th < oth && _pNames == other._pNames) || |
3437 | (th == oth && _pNames < other._pNames) || |
3438 | (th < oth && _pNames < other._pNames); |
3439 | } |
3440 | |
3441 | private: |
3442 | void init(const std::string& n0 = "A" , |
3443 | const std::string& n1 = "B" , |
3444 | const std::string& n2 = "C" , |
3445 | const std::string& n3 = "D" , |
3446 | const std::string& n4 = "E" , |
3447 | const std::string& n5 = "F" , |
3448 | const std::string& n6 = "G" ) |
3449 | { |
3450 | if (!_pNames) |
3451 | { |
3452 | _pNames = new NameVec; |
3453 | _pNames->push_back(n0); |
3454 | _pNames->push_back(n1); |
3455 | _pNames->push_back(n2); |
3456 | _pNames->push_back(n3); |
3457 | _pNames->push_back(n4); |
3458 | _pNames->push_back(n5); |
3459 | _pNames->push_back(n6); |
3460 | } |
3461 | } |
3462 | |
3463 | NameVecPtr _pNames; |
3464 | }; |
3465 | |
3466 | |
3467 | template<class T0, |
3468 | class T1, |
3469 | class T2, |
3470 | class T3, |
3471 | class T4, |
3472 | class T5> |
3473 | struct NamedTuple<T0,T1,T2,T3,T4,T5,NullTypeList>: |
3474 | public Tuple<T0,T1,T2,T3,T4,T5> |
3475 | { |
3476 | typedef Tuple<T0,T1,T2,T3,T4,T5> TupleType; |
3477 | typedef typename Tuple<T0,T1,T2,T3,T4,T5>::Type Type; |
3478 | |
3479 | typedef std::vector<std::string> NameVec; |
3480 | typedef SharedPtr<NameVec> NameVecPtr; |
3481 | |
3482 | NamedTuple(): _pNames(0) |
3483 | { |
3484 | init(); |
3485 | } |
3486 | |
3487 | NamedTuple(const NameVecPtr& rNames) |
3488 | { |
3489 | if (rNames->size() != TupleType::length) |
3490 | throw InvalidArgumentException("Wrong names vector length." ); |
3491 | |
3492 | _pNames = rNames; |
3493 | } |
3494 | |
3495 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
3496 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3497 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3498 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3499 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3500 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): |
3501 | TupleType(t0,t1,t2,t3,t4,t5), _pNames(0) |
3502 | { |
3503 | init(); |
3504 | } |
3505 | |
3506 | NamedTuple(const NameVecPtr& rNames, |
3507 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3508 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3509 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3510 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3511 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3512 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): |
3513 | TupleType(t0,t1,t2,t3,t4,t5) |
3514 | { |
3515 | if (rNames->size() != TupleType::length) |
3516 | throw InvalidArgumentException("Wrong names vector length." ); |
3517 | |
3518 | _pNames = rNames; |
3519 | } |
3520 | |
3521 | NamedTuple(const std::string& n0, |
3522 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3523 | const std::string& n1 = "B" , |
3524 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3525 | const std::string& n2 = "C" , |
3526 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3527 | const std::string& n3 = "D" , |
3528 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3529 | const std::string& n4 = "E" , |
3530 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4), |
3531 | const std::string& n5 = "F" , |
3532 | typename TypeWrapper<T5>::CONSTTYPE& t5 = POCO_TYPEWRAPPER_DEFAULTVALUE(T5)): |
3533 | TupleType(t0,t1,t2,t3,t4,t5), _pNames(0) |
3534 | { |
3535 | init(n0,n1,n2,n3,n4,n5); |
3536 | } |
3537 | |
3538 | const DynamicAny get(const std::string& name) const |
3539 | { |
3540 | NameVec::const_iterator it = _pNames->begin(); |
3541 | NameVec::const_iterator itEnd = _pNames->end(); |
3542 | |
3543 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
3544 | { |
3545 | if (name == *it) |
3546 | { |
3547 | switch (counter) |
3548 | { |
3549 | case 0: return TupleType::template get<0>(); |
3550 | case 1: return TupleType::template get<1>(); |
3551 | case 2: return TupleType::template get<2>(); |
3552 | case 3: return TupleType::template get<3>(); |
3553 | case 4: return TupleType::template get<4>(); |
3554 | case 5: return TupleType::template get<5>(); |
3555 | default: throw RangeException(); |
3556 | } |
3557 | } |
3558 | } |
3559 | |
3560 | throw NotFoundException("Name not found: " + name); |
3561 | } |
3562 | |
3563 | const DynamicAny operator [] (const std::string& name) const |
3564 | { |
3565 | return get(name); |
3566 | } |
3567 | |
3568 | template<int N> |
3569 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
3570 | { |
3571 | return TupleType::template get<N>(); |
3572 | } |
3573 | |
3574 | template<int N> |
3575 | typename TypeGetter<N, Type>::HeadType& get() |
3576 | { |
3577 | return TupleType::template get<N>(); |
3578 | } |
3579 | |
3580 | template<int N> |
3581 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
3582 | { |
3583 | return TupleType::template set<N>(val); |
3584 | } |
3585 | |
3586 | const NameVecPtr& names() |
3587 | { |
3588 | return _pNames; |
3589 | } |
3590 | |
3591 | void setName(std::size_t index, const std::string& name) |
3592 | { |
3593 | if (index >= _pNames->size()) |
3594 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3595 | |
3596 | (*_pNames)[index] = name; |
3597 | } |
3598 | |
3599 | const std::string& getName(std::size_t index) |
3600 | { |
3601 | if (index >= _pNames->size()) |
3602 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3603 | |
3604 | return (*_pNames)[index]; |
3605 | } |
3606 | |
3607 | bool operator == (const NamedTuple& other) const |
3608 | { |
3609 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
3610 | } |
3611 | |
3612 | bool operator != (const NamedTuple& other) const |
3613 | { |
3614 | return !(*this == other); |
3615 | } |
3616 | |
3617 | bool operator < (const NamedTuple& other) const |
3618 | { |
3619 | TupleType th(*this); |
3620 | TupleType oth(other); |
3621 | |
3622 | return (th < oth && _pNames == other._pNames) || |
3623 | (th == oth && _pNames < other._pNames) || |
3624 | (th < oth && _pNames < other._pNames); |
3625 | } |
3626 | |
3627 | private: |
3628 | void init(const std::string& n0 = "A" , |
3629 | const std::string& n1 = "B" , |
3630 | const std::string& n2 = "C" , |
3631 | const std::string& n3 = "D" , |
3632 | const std::string& n4 = "E" , |
3633 | const std::string& n5 = "F" ) |
3634 | { |
3635 | if (!_pNames) |
3636 | { |
3637 | _pNames = new NameVec; |
3638 | _pNames->push_back(n0); |
3639 | _pNames->push_back(n1); |
3640 | _pNames->push_back(n2); |
3641 | _pNames->push_back(n3); |
3642 | _pNames->push_back(n4); |
3643 | _pNames->push_back(n5); |
3644 | } |
3645 | } |
3646 | |
3647 | NameVecPtr _pNames; |
3648 | }; |
3649 | |
3650 | |
3651 | template<class T0, |
3652 | class T1, |
3653 | class T2, |
3654 | class T3, |
3655 | class T4> |
3656 | struct NamedTuple<T0,T1,T2,T3,T4,NullTypeList>: |
3657 | public Tuple<T0,T1,T2,T3,T4> |
3658 | { |
3659 | typedef Tuple<T0,T1,T2,T3,T4> TupleType; |
3660 | typedef typename Tuple<T0,T1,T2,T3,T4>::Type Type; |
3661 | |
3662 | typedef std::vector<std::string> NameVec; |
3663 | typedef SharedPtr<NameVec> NameVecPtr; |
3664 | |
3665 | NamedTuple(): _pNames(0) |
3666 | { |
3667 | init(); |
3668 | } |
3669 | |
3670 | NamedTuple(const NameVecPtr& rNames) |
3671 | { |
3672 | if (rNames->size() != TupleType::length) |
3673 | throw InvalidArgumentException("Wrong names vector length." ); |
3674 | |
3675 | _pNames = rNames; |
3676 | } |
3677 | |
3678 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
3679 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3680 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3681 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3682 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): |
3683 | TupleType(t0,t1,t2,t3,t4), |
3684 | _pNames(0) |
3685 | { |
3686 | init(); |
3687 | } |
3688 | |
3689 | NamedTuple(const NameVecPtr& rNames, |
3690 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3691 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3692 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3693 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3694 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): |
3695 | TupleType(t0,t1,t2,t3,t4) |
3696 | { |
3697 | if (rNames->size() != TupleType::length) |
3698 | throw InvalidArgumentException("Wrong names vector length." ); |
3699 | |
3700 | _pNames = rNames; |
3701 | } |
3702 | |
3703 | NamedTuple(const std::string& n0, |
3704 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3705 | const std::string& n1 = "B" , |
3706 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3707 | const std::string& n2 = "C" , |
3708 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3709 | const std::string& n3 = "D" , |
3710 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3), |
3711 | const std::string& n4 = "E" , |
3712 | typename TypeWrapper<T4>::CONSTTYPE& t4 = POCO_TYPEWRAPPER_DEFAULTVALUE(T4)): |
3713 | TupleType(t0,t1,t2,t3,t4), |
3714 | _pNames(0) |
3715 | { |
3716 | init(n0,n1,n2,n3,n4); |
3717 | } |
3718 | |
3719 | const DynamicAny get(const std::string& name) const |
3720 | { |
3721 | NameVec::const_iterator it = _pNames->begin(); |
3722 | NameVec::const_iterator itEnd = _pNames->end(); |
3723 | |
3724 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
3725 | { |
3726 | if (name == *it) |
3727 | { |
3728 | switch (counter) |
3729 | { |
3730 | case 0: return TupleType::template get<0>(); |
3731 | case 1: return TupleType::template get<1>(); |
3732 | case 2: return TupleType::template get<2>(); |
3733 | case 3: return TupleType::template get<3>(); |
3734 | case 4: return TupleType::template get<4>(); |
3735 | default: throw RangeException(); |
3736 | } |
3737 | } |
3738 | } |
3739 | |
3740 | throw NotFoundException("Name not found: " + name); |
3741 | } |
3742 | |
3743 | const DynamicAny operator [] (const std::string& name) const |
3744 | { |
3745 | return get(name); |
3746 | } |
3747 | |
3748 | template<int N> |
3749 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
3750 | { |
3751 | return TupleType::template get<N>(); |
3752 | } |
3753 | |
3754 | template<int N> |
3755 | typename TypeGetter<N, Type>::HeadType& get() |
3756 | { |
3757 | return TupleType::template get<N>(); |
3758 | } |
3759 | |
3760 | template<int N> |
3761 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
3762 | { |
3763 | return TupleType::template set<N>(val); |
3764 | } |
3765 | |
3766 | const NameVecPtr& names() |
3767 | { |
3768 | return _pNames; |
3769 | } |
3770 | |
3771 | void setName(std::size_t index, const std::string& name) |
3772 | { |
3773 | if (index >= _pNames->size()) |
3774 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3775 | |
3776 | (*_pNames)[index] = name; |
3777 | } |
3778 | |
3779 | const std::string& getName(std::size_t index) |
3780 | { |
3781 | if (index >= _pNames->size()) |
3782 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3783 | |
3784 | return (*_pNames)[index]; |
3785 | } |
3786 | |
3787 | bool operator == (const NamedTuple& other) const |
3788 | { |
3789 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
3790 | } |
3791 | |
3792 | bool operator != (const NamedTuple& other) const |
3793 | { |
3794 | return !(*this == other); |
3795 | } |
3796 | |
3797 | bool operator < (const NamedTuple& other) const |
3798 | { |
3799 | TupleType th(*this); |
3800 | TupleType oth(other); |
3801 | |
3802 | return (th < oth && _pNames == other._pNames) || |
3803 | (th == oth && _pNames < other._pNames) || |
3804 | (th < oth && _pNames < other._pNames); |
3805 | } |
3806 | |
3807 | private: |
3808 | void init(const std::string& n0 = "A" , |
3809 | const std::string& n1 = "B" , |
3810 | const std::string& n2 = "C" , |
3811 | const std::string& n3 = "D" , |
3812 | const std::string& n4 = "E" ) |
3813 | { |
3814 | if (!_pNames) |
3815 | { |
3816 | _pNames = new NameVec; |
3817 | _pNames->push_back(n0); |
3818 | _pNames->push_back(n1); |
3819 | _pNames->push_back(n2); |
3820 | _pNames->push_back(n3); |
3821 | _pNames->push_back(n4); |
3822 | } |
3823 | } |
3824 | |
3825 | NameVecPtr _pNames; |
3826 | }; |
3827 | |
3828 | |
3829 | template<class T0, |
3830 | class T1, |
3831 | class T2, |
3832 | class T3> |
3833 | struct NamedTuple<T0,T1,T2,T3,NullTypeList>: |
3834 | public Tuple<T0,T1,T2,T3> |
3835 | { |
3836 | typedef Tuple<T0,T1,T2,T3> TupleType; |
3837 | typedef typename Tuple<T0,T1,T2,T3>::Type Type; |
3838 | |
3839 | typedef std::vector<std::string> NameVec; |
3840 | typedef SharedPtr<NameVec> NameVecPtr; |
3841 | |
3842 | NamedTuple(): _pNames(0) |
3843 | { |
3844 | init(); |
3845 | } |
3846 | |
3847 | NamedTuple(const NameVecPtr& rNames) |
3848 | { |
3849 | if (rNames->size() != TupleType::length) |
3850 | throw InvalidArgumentException("Wrong names vector length." ); |
3851 | |
3852 | _pNames = rNames; |
3853 | } |
3854 | |
3855 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
3856 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3857 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3858 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): |
3859 | TupleType(t0,t1,t2,t3), |
3860 | _pNames(0) |
3861 | { |
3862 | init(); |
3863 | } |
3864 | |
3865 | NamedTuple(const NameVecPtr& rNames, |
3866 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3867 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3868 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3869 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): |
3870 | TupleType(t0,t1,t2,t3) |
3871 | { |
3872 | if (rNames->size() != TupleType::length) |
3873 | throw InvalidArgumentException("Wrong names vector length." ); |
3874 | |
3875 | _pNames = rNames; |
3876 | } |
3877 | |
3878 | NamedTuple(const std::string& n0, |
3879 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
3880 | const std::string& n1 = "B" , |
3881 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
3882 | const std::string& n2 = "C" , |
3883 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2), |
3884 | const std::string& n3 = "D" , |
3885 | typename TypeWrapper<T3>::CONSTTYPE& t3 = POCO_TYPEWRAPPER_DEFAULTVALUE(T3)): |
3886 | TupleType(t0,t1,t2,t3), _pNames(0) |
3887 | { |
3888 | init(n0,n1,n2,n3); |
3889 | } |
3890 | |
3891 | const DynamicAny get(const std::string& name) const |
3892 | { |
3893 | NameVec::const_iterator it = _pNames->begin(); |
3894 | NameVec::const_iterator itEnd = _pNames->end(); |
3895 | |
3896 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
3897 | { |
3898 | if (name == *it) |
3899 | { |
3900 | switch (counter) |
3901 | { |
3902 | case 0: return TupleType::template get<0>(); |
3903 | case 1: return TupleType::template get<1>(); |
3904 | case 2: return TupleType::template get<2>(); |
3905 | case 3: return TupleType::template get<3>(); |
3906 | default: throw RangeException(); |
3907 | } |
3908 | } |
3909 | } |
3910 | |
3911 | throw NotFoundException("Name not found: " + name); |
3912 | } |
3913 | |
3914 | const DynamicAny operator [] (const std::string& name) const |
3915 | { |
3916 | return get(name); |
3917 | } |
3918 | |
3919 | template<int N> |
3920 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
3921 | { |
3922 | return TupleType::template get<N>(); |
3923 | } |
3924 | |
3925 | template<int N> |
3926 | typename TypeGetter<N, Type>::HeadType& get() |
3927 | { |
3928 | return TupleType::template get<N>(); |
3929 | } |
3930 | |
3931 | template<int N> |
3932 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
3933 | { |
3934 | return TupleType::template set<N>(val); |
3935 | } |
3936 | |
3937 | const NameVecPtr& names() |
3938 | { |
3939 | return _pNames; |
3940 | } |
3941 | |
3942 | void setName(std::size_t index, const std::string& name) |
3943 | { |
3944 | if (index >= _pNames->size()) |
3945 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3946 | |
3947 | (*_pNames)[index] = name; |
3948 | } |
3949 | |
3950 | const std::string& getName(std::size_t index) |
3951 | { |
3952 | if (index >= _pNames->size()) |
3953 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
3954 | |
3955 | return (*_pNames)[index]; |
3956 | } |
3957 | |
3958 | bool operator == (const NamedTuple& other) const |
3959 | { |
3960 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
3961 | } |
3962 | |
3963 | bool operator != (const NamedTuple& other) const |
3964 | { |
3965 | return !(*this == other); |
3966 | } |
3967 | |
3968 | bool operator < (const NamedTuple& other) const |
3969 | { |
3970 | TupleType th(*this); |
3971 | TupleType oth(other); |
3972 | |
3973 | return (th < oth && _pNames == other._pNames) || |
3974 | (th == oth && _pNames < other._pNames) || |
3975 | (th < oth && _pNames < other._pNames); |
3976 | } |
3977 | |
3978 | private: |
3979 | void init(const std::string& n0 = "A" , |
3980 | const std::string& n1 = "B" , |
3981 | const std::string& n2 = "C" , |
3982 | const std::string& n3 = "D" ) |
3983 | { |
3984 | if (!_pNames) |
3985 | { |
3986 | _pNames = new NameVec; |
3987 | _pNames->push_back(n0); |
3988 | _pNames->push_back(n1); |
3989 | _pNames->push_back(n2); |
3990 | _pNames->push_back(n3); |
3991 | } |
3992 | } |
3993 | |
3994 | NameVecPtr _pNames; |
3995 | }; |
3996 | |
3997 | |
3998 | template<class T0, |
3999 | class T1, |
4000 | class T2> |
4001 | struct NamedTuple<T0,T1,T2,NullTypeList>: |
4002 | public Tuple<T0,T1,T2> |
4003 | { |
4004 | typedef Tuple<T0,T1,T2> TupleType; |
4005 | typedef typename Tuple<T0,T1,T2>::Type Type; |
4006 | |
4007 | typedef std::vector<std::string> NameVec; |
4008 | typedef SharedPtr<NameVec> NameVecPtr; |
4009 | |
4010 | NamedTuple(): _pNames(0) |
4011 | { |
4012 | init(); |
4013 | } |
4014 | |
4015 | NamedTuple(const NameVecPtr& rNames) |
4016 | { |
4017 | if (rNames->size() != TupleType::length) |
4018 | throw InvalidArgumentException("Wrong names vector length." ); |
4019 | |
4020 | _pNames = rNames; |
4021 | } |
4022 | |
4023 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
4024 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
4025 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): |
4026 | TupleType(t0,t1,t2), |
4027 | _pNames(0) |
4028 | { |
4029 | init(); |
4030 | } |
4031 | |
4032 | NamedTuple(const NameVecPtr& rNames, |
4033 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
4034 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
4035 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): |
4036 | TupleType(t0,t1,t2) |
4037 | { |
4038 | if (rNames->size() != TupleType::length) |
4039 | throw InvalidArgumentException("Wrong names vector length." ); |
4040 | |
4041 | _pNames = rNames; |
4042 | } |
4043 | |
4044 | NamedTuple(const std::string& n0, |
4045 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
4046 | const std::string& n1 = "B" , |
4047 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1), |
4048 | const std::string& n2 = "C" , |
4049 | typename TypeWrapper<T2>::CONSTTYPE& t2 = POCO_TYPEWRAPPER_DEFAULTVALUE(T2)): |
4050 | TupleType(t0,t1,t2), |
4051 | _pNames(0) |
4052 | { |
4053 | init(n0,n1,n2); |
4054 | } |
4055 | |
4056 | const DynamicAny get(const std::string& name) const |
4057 | { |
4058 | NameVec::const_iterator it = _pNames->begin(); |
4059 | NameVec::const_iterator itEnd = _pNames->end(); |
4060 | |
4061 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
4062 | { |
4063 | if (name == *it) |
4064 | { |
4065 | switch (counter) |
4066 | { |
4067 | case 0: return TupleType::template get<0>(); |
4068 | case 1: return TupleType::template get<1>(); |
4069 | case 2: return TupleType::template get<2>(); |
4070 | default: throw RangeException(); |
4071 | } |
4072 | } |
4073 | } |
4074 | |
4075 | throw NotFoundException("Name not found: " + name); |
4076 | } |
4077 | |
4078 | const DynamicAny operator [] (const std::string& name) const |
4079 | { |
4080 | return get(name); |
4081 | } |
4082 | |
4083 | template<int N> |
4084 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
4085 | { |
4086 | return TupleType::template get<N>(); |
4087 | } |
4088 | |
4089 | template<int N> |
4090 | typename TypeGetter<N, Type>::HeadType& get() |
4091 | { |
4092 | return TupleType::template get<N>(); |
4093 | } |
4094 | |
4095 | template<int N> |
4096 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
4097 | { |
4098 | return TupleType::template set<N>(val); |
4099 | } |
4100 | |
4101 | const NameVecPtr& names() |
4102 | { |
4103 | return _pNames; |
4104 | } |
4105 | |
4106 | void setName(std::size_t index, const std::string& name) |
4107 | { |
4108 | if (index >= _pNames->size()) |
4109 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
4110 | |
4111 | (*_pNames)[index] = name; |
4112 | } |
4113 | |
4114 | const std::string& getName(std::size_t index) |
4115 | { |
4116 | if (index >= _pNames->size()) |
4117 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
4118 | |
4119 | return (*_pNames)[index]; |
4120 | } |
4121 | |
4122 | bool operator == (const NamedTuple& other) const |
4123 | { |
4124 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
4125 | } |
4126 | |
4127 | bool operator != (const NamedTuple& other) const |
4128 | { |
4129 | return !(*this == other); |
4130 | } |
4131 | |
4132 | bool operator < (const NamedTuple& other) const |
4133 | { |
4134 | TupleType th(*this); |
4135 | TupleType oth(other); |
4136 | |
4137 | return (th < oth && _pNames == other._pNames) || |
4138 | (th == oth && _pNames < other._pNames) || |
4139 | (th < oth && _pNames < other._pNames); |
4140 | } |
4141 | |
4142 | private: |
4143 | void init(const std::string& n0 = "A" , |
4144 | const std::string& n1 = "B" , |
4145 | const std::string& n2 = "C" ) |
4146 | { |
4147 | if (!_pNames) |
4148 | { |
4149 | _pNames = new NameVec; |
4150 | _pNames->push_back(n0); |
4151 | _pNames->push_back(n1); |
4152 | _pNames->push_back(n2); |
4153 | } |
4154 | } |
4155 | |
4156 | NameVecPtr _pNames; |
4157 | }; |
4158 | |
4159 | |
4160 | template<class T0, |
4161 | class T1> |
4162 | struct NamedTuple<T0,T1,NullTypeList>: |
4163 | public Tuple<T0,T1> |
4164 | { |
4165 | typedef Tuple<T0,T1> TupleType; |
4166 | typedef typename Tuple<T0,T1>::Type Type; |
4167 | |
4168 | typedef std::vector<std::string> NameVec; |
4169 | typedef SharedPtr<NameVec> NameVecPtr; |
4170 | |
4171 | NamedTuple(): _pNames(0) |
4172 | { |
4173 | init(); |
4174 | } |
4175 | |
4176 | NamedTuple(const NameVecPtr& rNames) |
4177 | { |
4178 | if (rNames->size() != TupleType::length) |
4179 | throw InvalidArgumentException("Wrong names vector length." ); |
4180 | |
4181 | _pNames = rNames; |
4182 | } |
4183 | |
4184 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0, |
4185 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): |
4186 | TupleType(t0,t1), |
4187 | _pNames(0) |
4188 | { |
4189 | init(); |
4190 | } |
4191 | |
4192 | NamedTuple(const NameVecPtr& rNames, |
4193 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
4194 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): |
4195 | TupleType(t0,t1) |
4196 | { |
4197 | if (rNames->size() != TupleType::length) |
4198 | throw InvalidArgumentException("Wrong names vector length." ); |
4199 | |
4200 | _pNames = rNames; |
4201 | } |
4202 | |
4203 | NamedTuple(const std::string& n0, |
4204 | typename TypeWrapper<T0>::CONSTTYPE& t0, |
4205 | const std::string& n1 = "B" , |
4206 | typename TypeWrapper<T1>::CONSTTYPE& t1 = POCO_TYPEWRAPPER_DEFAULTVALUE(T1)): |
4207 | TupleType(t0,t1), |
4208 | _pNames(0) |
4209 | { |
4210 | init(n0,n1); |
4211 | } |
4212 | |
4213 | const DynamicAny get(const std::string& name) const |
4214 | { |
4215 | NameVec::const_iterator it = _pNames->begin(); |
4216 | NameVec::const_iterator itEnd = _pNames->end(); |
4217 | |
4218 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
4219 | { |
4220 | if (name == *it) |
4221 | { |
4222 | switch (counter) |
4223 | { |
4224 | case 0: return TupleType::template get<0>(); |
4225 | case 1: return TupleType::template get<1>(); |
4226 | default: throw RangeException(); |
4227 | } |
4228 | } |
4229 | } |
4230 | |
4231 | throw NotFoundException("Name not found: " + name); |
4232 | } |
4233 | |
4234 | const DynamicAny operator [] (const std::string& name) const |
4235 | { |
4236 | return get(name); |
4237 | } |
4238 | |
4239 | template<int N> |
4240 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
4241 | { |
4242 | return TupleType::template get<N>(); |
4243 | } |
4244 | |
4245 | template<int N> |
4246 | typename TypeGetter<N, Type>::HeadType& get() |
4247 | { |
4248 | return TupleType::template get<N>(); |
4249 | } |
4250 | |
4251 | template<int N> |
4252 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
4253 | { |
4254 | return TupleType::template set<N>(val); |
4255 | } |
4256 | |
4257 | const NameVecPtr& names() |
4258 | { |
4259 | return _pNames; |
4260 | } |
4261 | |
4262 | void setName(std::size_t index, const std::string& name) |
4263 | { |
4264 | if (index >= _pNames->size()) |
4265 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
4266 | |
4267 | (*_pNames)[index] = name; |
4268 | } |
4269 | |
4270 | const std::string& getName(std::size_t index) |
4271 | { |
4272 | if (index >= _pNames->size()) |
4273 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
4274 | |
4275 | return (*_pNames)[index]; |
4276 | } |
4277 | |
4278 | bool operator == (const NamedTuple& other) const |
4279 | { |
4280 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
4281 | } |
4282 | |
4283 | bool operator != (const NamedTuple& other) const |
4284 | { |
4285 | return !(*this == other); |
4286 | } |
4287 | |
4288 | bool operator < (const NamedTuple& other) const |
4289 | { |
4290 | TupleType th(*this); |
4291 | TupleType oth(other); |
4292 | |
4293 | return (th < oth && _pNames == other._pNames) || |
4294 | (th == oth && _pNames < other._pNames) || |
4295 | (th < oth && _pNames < other._pNames); |
4296 | } |
4297 | |
4298 | private: |
4299 | void init(const std::string& n0 = "A" , |
4300 | const std::string& n1 = "B" ) |
4301 | { |
4302 | if (!_pNames) |
4303 | { |
4304 | _pNames = new NameVec; |
4305 | _pNames->push_back(n0); |
4306 | _pNames->push_back(n1); |
4307 | } |
4308 | } |
4309 | |
4310 | NameVecPtr _pNames; |
4311 | }; |
4312 | |
4313 | |
4314 | template<class T0> |
4315 | struct NamedTuple<T0,NullTypeList>: |
4316 | public Tuple<T0> |
4317 | { |
4318 | typedef Tuple<T0> TupleType; |
4319 | typedef typename Tuple<T0>::Type Type; |
4320 | |
4321 | typedef std::vector<std::string> NameVec; |
4322 | typedef SharedPtr<NameVec> NameVecPtr; |
4323 | |
4324 | NamedTuple(): _pNames(0) |
4325 | { |
4326 | init(); |
4327 | } |
4328 | |
4329 | NamedTuple(const NameVecPtr& rNames) |
4330 | { |
4331 | if (rNames->size() != TupleType::length) |
4332 | throw InvalidArgumentException("Wrong names vector length." ); |
4333 | |
4334 | _pNames = rNames; |
4335 | } |
4336 | |
4337 | NamedTuple(typename TypeWrapper<T0>::CONSTTYPE& t0): |
4338 | TupleType(t0), |
4339 | _pNames(0) |
4340 | { |
4341 | init(); |
4342 | } |
4343 | |
4344 | NamedTuple(const NameVecPtr& rNames, |
4345 | typename TypeWrapper<T0>::CONSTTYPE& t0): |
4346 | TupleType(t0) |
4347 | { |
4348 | if (rNames->size() != TupleType::length) |
4349 | throw InvalidArgumentException("Wrong names vector length." ); |
4350 | |
4351 | _pNames = rNames; |
4352 | } |
4353 | |
4354 | NamedTuple(const std::string& n0, typename TypeWrapper<T0>::CONSTTYPE& t0): |
4355 | TupleType(t0), |
4356 | _pNames(0) |
4357 | { |
4358 | init(n0); |
4359 | } |
4360 | |
4361 | const DynamicAny get(const std::string& name) const |
4362 | { |
4363 | NameVec::const_iterator it = _pNames->begin(); |
4364 | NameVec::const_iterator itEnd = _pNames->end(); |
4365 | |
4366 | for(std::size_t counter = 0; it != itEnd; ++it, ++counter) |
4367 | { |
4368 | if (name == *it) |
4369 | { |
4370 | switch (counter) |
4371 | { |
4372 | case 0: return TupleType::template get<0>(); |
4373 | default: throw RangeException(); |
4374 | } |
4375 | } |
4376 | } |
4377 | |
4378 | throw NotFoundException("Name not found: " + name); |
4379 | } |
4380 | |
4381 | const DynamicAny operator [] (const std::string& name) const |
4382 | { |
4383 | return get(name); |
4384 | } |
4385 | |
4386 | template<int N> |
4387 | typename TypeGetter<N, Type>::ConstHeadType& get() const |
4388 | { |
4389 | return TupleType::template get<N>(); |
4390 | } |
4391 | |
4392 | template<int N> |
4393 | typename TypeGetter<N, Type>::HeadType& get() |
4394 | { |
4395 | return TupleType::template get<N>(); |
4396 | } |
4397 | |
4398 | template<int N> |
4399 | void set(typename TypeGetter<N, Type>::ConstHeadType& val) |
4400 | { |
4401 | return TupleType::template set<N>(val); |
4402 | } |
4403 | |
4404 | const NameVecPtr& names() |
4405 | { |
4406 | return _pNames; |
4407 | } |
4408 | |
4409 | void setName(std::size_t index, const std::string& name) |
4410 | { |
4411 | if (index >= _pNames->size()) |
4412 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
4413 | |
4414 | (*_pNames)[index] = name; |
4415 | } |
4416 | |
4417 | const std::string& getName(std::size_t index) |
4418 | { |
4419 | if (index >= _pNames->size()) |
4420 | throw InvalidArgumentException(format("Invalid index: %z" , index)); |
4421 | |
4422 | return (*_pNames)[index]; |
4423 | } |
4424 | |
4425 | bool operator == (const NamedTuple& other) const |
4426 | { |
4427 | return TupleType(*this) == TupleType(other) && _pNames == other._pNames; |
4428 | } |
4429 | |
4430 | bool operator != (const NamedTuple& other) const |
4431 | { |
4432 | return !(*this == other); |
4433 | } |
4434 | |
4435 | bool operator < (const NamedTuple& other) const |
4436 | { |
4437 | TupleType th(*this); |
4438 | TupleType oth(other); |
4439 | |
4440 | return (th < oth && _pNames == other._pNames) || |
4441 | (th == oth && _pNames < other._pNames) || |
4442 | (th < oth && _pNames < other._pNames); |
4443 | } |
4444 | |
4445 | private: |
4446 | void init(const std::string& n0 = "A" ) |
4447 | { |
4448 | if (!_pNames) |
4449 | { |
4450 | _pNames = new NameVec; |
4451 | _pNames->push_back(n0); |
4452 | } |
4453 | } |
4454 | |
4455 | NameVecPtr _pNames; |
4456 | }; |
4457 | |
4458 | |
4459 | } // namespace Poco |
4460 | |
4461 | |
4462 | #endif // Foundation_Tuple_INCLUDED |
4463 | |