ATLAS Offline Software
Loading...
Searching...
No Matches
NavigationDefaults.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef NAVIGATION_NAVIGATIONDEFAULTS_H
6#define NAVIGATION_NAVIGATIONDEFAULTS_H
8//
10
11#include "AthLinks/ElementLink.h"
13
14#include <utility>
15#include <vector>
16#include <algorithm>
17
18namespace NavigationDefaults
19{
21 // Namespace Type Definitions //
23
24 // typedef unsigned int external_index_type;
25
27 // Default Type //
29
30 struct DefaultType{}; // completely dummy
31
33 // Default Container //
35
36 struct DefaultContainer // needs to provide a "type"
37 {
38 public:
40 };
41
43
45 // Default Insertion Handling //
47
49 // Default Relation Parameter //
51
53 public:
55 const DefaultWeight& operator+(const DefaultWeight&) const {return *this;}
56 const DefaultWeight& operator*(const DefaultWeight&) const {return *this;}
57 bool operator==(DefaultWeight&) const {return true;}
58 operator double() {return 1.0;}
59 };
60
62
64 // Default Constituent Collections: Including Relational Parameters //
66
67 template <typename CONT, typename RPAR>
69 {
70 // default container is a vector of (ElementLink,RPAR) pairs
71 //typedef typename std::pair< const ElementLink<CONT>*, RPAR > value_type;
72 typedef typename std::pair< ElementLink<CONT>, RPAR > value_type;
73 typedef typename std::vector< value_type > type;
74 typedef typename type::iterator type_iterator;
75 typedef typename type::const_iterator type_const_iterator;
76 typedef typename CONT::base_value_type* child_ptr;
77 typedef const typename CONT::base_value_type* const_child_ptr;
80
81 // object pointer (key) access (note: outer *() operates on ElementLink!)
83 {
84 const_child_ptr thePointer = 0;
85 if ((*thisIter).first.isValid() )
86 thePointer = *((*thisIter).first);
87 return thePointer;
88 }
89
90 // relational parameter (data) access
91 static RPAR getChildPar(type_const_iterator thisIter)
92 { return (*thisIter).second; }
93
94 // ElementLink pointer access
96 thisIter)
97 {
98 return &((*thisIter).first);
99 }
100
101 // container access through iterator
102 static const CONT& getContRef(type_const_iterator thisIter)
103 {
104 return ((*thisIter).first).getStorableObjectRef();
105 }
106
107 // container access through pointer
108 static const CONT& getContRef(const type& cont, const_child_ptr aChild)
109 {
110 return getContRef(find(cont,aChild));
111 }
112
113 // pointer to container access by iterator
114 static const CONT* getContPtr(type_const_iterator thisIter)
115 {
116 return ((*thisIter).first).getStorableObjectPointer();
117 }
118
119 // pointer to container access by pointer
120 static const CONT* getContPtr(const type& cont, const_child_ptr aChild)
121 {
122 type_const_iterator found = find(cont,aChild);
123 return found != cont.end()
124 ? getContPtr(found)
125 : 0;
126 }
127
128 // index in container access by iterator
129 static bool
131 external_index_type& theIndex)
132 {
133 theIndex = ((*thisIter).first).index();
134 const CONT* cont = getContPtr(thisIter);
135 return cont ? theIndex < cont->size() : false;
136 }
137
138 // index in container access by pointer
139 static bool
140 getContIndex(const type& cont, const_child_ptr aChild,
141 external_index_type& theIndex)
142 {
143 type_const_iterator found = find(cont,aChild);
144 if ( found != cont.end() )
145 {
146 return getContIndex(found,theIndex);
147 }
148 return false;
149 }
150
152
153 // insertion of ElementLink by object pointer
154 static void insert(type& cont,
155 const CONT* aChildContainer,
156 const_child_ptr aChild,
157 const RPAR& aPar=RPAR(),
158 size_t sizeHint = 0)
159 {
160 if (sizeHint && cont.capacity() < sizeHint)
161 cont.reserve(sizeHint);
162 cont.push_back(value_type(ElementLink<CONT>(const_cast<child_ptr>(aChild),
163 *aChildContainer),
164 aPar));
165 }
166
167 // insertion of ElementLink by object index
168 static void insert(type& cont, const CONT* aChildContainer,
169 const external_index_type& anIndex,
170 const RPAR& aPar=RPAR(),
171 size_t sizeHint = 0)
172 {
173 if (sizeHint && cont.capacity() < sizeHint)
174 cont.reserve(sizeHint);
175 cont.emplace_back (std::piecewise_construct,
176 std::forward_as_tuple(*aChildContainer,anIndex),
177 std::forward_as_tuple(aPar));
178 }
179
180 // insertion of ElementLink by object index
181 static void insert(type& cont, const CONT* aChildContainer,
182 const external_index_type& anIndex,
183 IProxyDict* sg,
184 const RPAR& aPar=RPAR(),
185 size_t sizeHint = 0)
186 {
187 if (sizeHint && cont.capacity() < sizeHint)
188 cont.reserve(sizeHint);
189 cont.emplace_back (std::piecewise_construct,
190 std::forward_as_tuple(*aChildContainer,anIndex,sg),
191 std::forward_as_tuple(aPar));
192 }
193
194 // insertion of ElementLink by ElementLink
195 static void insert(type& cont,
196 const ElementLink<CONT>* aLink,
197 const RPAR& aPar=RPAR(),
198 size_t sizeHint = 0)
199 {
200 if (sizeHint && cont.capacity() < sizeHint)
201 cont.reserve(sizeHint);
202 cont.push_back(value_type(*aLink, aPar));
203 }
204
205 // change parameter
206 static void changeParm(type& cont,
207 const_child_ptr pChild,
208 const RPAR& aPar=RPAR())
209 {
210 type_iterator iObj = find(cont,pChild);
211 if ( iObj != cont.end() ) (*iObj).second = aPar;
212 }
213
214 // change parameter
215 static void changeParm(type& cont,
216 const CONT* pContainer,
217 const external_index_type& refIndex,
218 const RPAR& aPar=RPAR())
219 {
220 changeParm(cont,(pContainer->operator[])(refIndex),aPar);
221 }
222
223 // change parameter
224 // static void changeParm(type_iterator& iter,
225 // const RPAR& aPar=RPAR())
226 // {
227 // (*iter).second = aPar;
228 // }
229
231
232 // find method implementation for const_iterator on objects
233 static type_const_iterator
234 find(const type& cont, const_child_ptr aChild)
235 {
236 type_const_iterator iEntry = cont.begin();
237 type_const_iterator lastEntry = cont.end();
238 while (iEntry != lastEntry && aChild != *((*iEntry).first)) ++iEntry;
239 return iEntry;
240 }
241
242 // find method for iterator on objects
243 static type_iterator
244 find(type& cont, const_child_ptr aChild)
245 {
246 type_iterator iEntry = cont.begin();
247 type_iterator lastEntry = cont.end();
248 while (iEntry != lastEntry && aChild != *((*iEntry).first)) ++iEntry;
249 return iEntry;
250 }
251
252 // find method for ElementLinks
253 // static type_const_iterator
254 // find(const type& cont, const ElementLink<CONT>* anElement)
255 // {
256 // const_child_ptr theChild = *(*anElement);
257 // return find(cont,theChild);
258 // }
259
260 // find method for ElementLinks
261 // static type_iterator
262 // find(type& cont, const ElementLink<CONT>* anElement)
263 // {
264 // child_ptr theChild = *(*anElement);
265 // return find(cont,theChild);
266 // }
267
269
270 // removal by object pointer
271 static bool
273 {
274 type_iterator found = find(cont,aChild);
275 if ( found != cont.end() )
276 {
277 // we assume the container owns the ElementLink/parameter pair,
278 // but not the object linked by ElementLink --- FIXME ??
279 // delete (*found).first;
280 cont.erase(found);
281 return true;
282 }
283 else
284 {
285 return false;
286 }
287 }
288
289 // removal by ElementLink
290 static bool
291 remove(type& cont, const ElementLink<CONT>* theElement)
292 {
293 type_iterator found = find(cont,theElement);
294 if ( found != cont.end() )
295 {
296 // delete (*found).first;
297 cont.erase(found);
298 return true;
299 }
300 else
301 {
302 return false;
303 }
304 }
305
306 // replace container in ElementLink
307 static bool
308 replace(type& cont, const CONT& theNewContainer) {
309 type_iterator firstEntry = cont.begin();
310 type_iterator lastEntry = cont.end();
311 for ( ; firstEntry != lastEntry ; ++firstEntry ) {
312 // Must force replacement with second arg true
313 ((*firstEntry).first).setStorableObject(theNewContainer, true);
314 }
315 return true;
316 }
317
318 // test on containment
319 static bool
320 contains(const type& cont, const_child_ptr aChild)
321 {
322 return find(cont,aChild) != cont.end();
323 }
324
325 };
326
328 // Default Constituent Collections: No Relational Parameters //
330
331 template <typename CONT>
333 {
334 // default container is a vector of ElementLinks
335 // typedef const ElementLink<CONT>* value_type;
337 typedef typename std::vector< value_type > type;
338 typedef typename type::iterator type_iterator;
339 typedef typename type::const_iterator type_const_iterator;
340 typedef typename CONT::base_value_type* child_ptr;
341 typedef const typename CONT::base_value_type* const_child_ptr;
342 // typedef typename CONT::const_reference const_child_ptr;
343 // typedef typename CONT::reference child_ptr;
346
347 // object pointer access
349 {
350 const_child_ptr ret = 0;
351 if ((*iter).isValid())
352 ret = *(*iter);
353 return ret;
354 }
355
356 // default weight is dummy
358 { return DefaultWeight(); }
359
360 // ElementLink pointer access
362 thisIter)
363 {
364 return &(*thisIter);
365 }
366
367 // container access by iterator
368 static const CONT& getContRef(type_const_iterator thisIter)
369 {
370 return (*thisIter).getStorableObjectRef();
371 }
372
373 // container access by pointer
374 static const CONT& getContRef(const type& cont, const_child_ptr aChild)
375 {
376 return getContRef(find(cont,aChild));
377 }
378
379 // pointer to container access by iterator
380 static const CONT* getContPtr(type_const_iterator thisIter)
381 {
382 return (*thisIter).getStorableObjectPointer();
383 }
384
385 // pointer to container access by pointer
386 static const CONT* getContPtr(const type& cont, const_child_ptr aChild)
387 {
388 type_const_iterator found = find(cont,aChild);
389 return found != cont.end()
390 ? getContPtr(found)
391 : 0;
392 }
393
394 // index in container access by iterator
395 static bool
397 external_index_type& theIndex)
398 {
399 theIndex = (*thisIter).index();
400 const CONT* cont = getContPtr(thisIter);
401 return cont ? theIndex < cont->size() : false;
402 }
403
404 // index in container access by pointer
405 static bool
406 getContIndex(const type& cont, const_child_ptr aChild,
407 external_index_type& theIndex)
408 {
409 type_const_iterator found = find(cont,aChild);
410 if ( found != cont.end() )
411 {
412 return getContIndex(found,theIndex);
413 }
414 return false;
415 }
416
417 // insertion of ElementLink by object pointer
418 static void insert(type& cont, const CONT* aChildContainer,
419 const_child_ptr aChild,
420 const DefaultWeight&,
421 size_t sizeHint = 0)
422 {
423 if (sizeHint && cont.capacity() < sizeHint)
424 cont.reserve(sizeHint);
425 // cast is an ugly fix!
426 cont.push_back(ElementLink<CONT>(const_cast<child_ptr>(aChild),
427 *aChildContainer));
428 }
429
430 // insertion of ElementLink by object index
431 static void insert(type& cont, const CONT* aChildContainer,
432 const external_index_type& anIndex,
433 const DefaultWeight&,
434 size_t sizeHint = 0)
435 {
436 if (sizeHint && cont.capacity() < sizeHint)
437 cont.reserve(sizeHint);
438 cont.push_back(ElementLink<CONT>(*aChildContainer,anIndex));
439 }
440
441 // direct insertion of ElementLink
442 static void insert(type& cont, const ElementLink<CONT>* aLink,
443 const DefaultWeight&,
444 size_t sizeHint = 0)
445 {
446 if (sizeHint && cont.capacity() < sizeHint)
447 cont.reserve(sizeHint);
448 cont.push_back(*aLink);
449 }
450
451 // change parameter
452 static void changeParm(type& /* cont */,
453 const_child_ptr /* pChild */,
454 const DefaultWeight& /*refParm*/)
455 { }
456
457 // change parameter
458 static void changeParm(type& /* cont */,
459 const CONT* /* pContainer */,
460 const external_index_type& /* refIndex */,
461 const DefaultWeight& /* refParm */)
462 { }
463
464 // change parameter
465 static void changeParm(type_iterator& /* iter */,
466 const DefaultWeight& /* refParm */)
467 { }
468
469 // allocation of object pointer in list
470 static type_const_iterator find(const type& cont,
471 const_child_ptr aChild)
472 {
473 type_const_iterator firstEntry = cont.begin();
474 type_const_iterator lastEntry = cont.end();
475 for ( ; firstEntry != lastEntry; ++firstEntry )
476 {
477 if ( *(*firstEntry) == aChild ) break;
478 }
479 return firstEntry;
480 }
481
482 // same but return iterator
483 static type_iterator find(type& cont, const_child_ptr aChild)
484 {
485 type_iterator firstEntry = cont.begin();
486 type_iterator lastEntry = cont.end();
487 for ( ; firstEntry != lastEntry; ++firstEntry )
488 {
489 if ( *(*firstEntry) == aChild ) break;
490 }
491 return firstEntry;
492 }
493
494 // find ElementLink directly
495 // static type_const_iterator find(const type& cont,
496 // const ElementLink<CONT>* anElement)
497 // {
498 // return std::find(anElement,cont.begin(),cont.end());
499 // }
500
501 // find ElementLink directly
502 // static type_iterator find(type& cont,
503 // const ElementLink<CONT>* anElement)
504 // {
505 // return std::find(anElement,cont.begin(),cont.end());
506 // }
507
508 // removal
509 static bool remove(type& cont, const_child_ptr aChild)
510 {
511 type_iterator found = find(cont,aChild);
512 if ( found != cont.end() )
513 {
514 // ownership of ElementLink!! FIXME
515 // delete *found;
516 cont.erase(found);
517 return true;
518 }
519 else
520 {
521 return false;
522 }
523 }
524
525 // removal of ElementLink
526 static bool remove(type& cont, const ElementLink<CONT>* anElement)
527 {
528 type_iterator found = find(cont,*anElement);
529 if ( found != cont.end() )
530 {
531 // delete *found;
532 cont.erase(anElement);
533 return true;
534 }
535 else
536 {
537 return false;
538 }
539 }
540
541 // replace container in ElementLink
542 static bool
543 replace(type& cont, const CONT& theNewContainer) {
544 type_iterator firstEntry = cont.begin();
545 type_iterator lastEntry = cont.end();
546 for ( ; firstEntry != lastEntry ; ++firstEntry ) {
547 // Must force replacement with second arg true
548 (*firstEntry).setStorableObject(theNewContainer, true);
549 }
550 return true;
551 }
552
553 // test on containment
554 static bool
555 contains(const type& cont, const_child_ptr aChild)
556 {
557 return find(cont,aChild) != cont.end();
558 }
559 };
560
562 // Default Constituent Collections: Terminal Node (Dummy) //
564
565 template<>
567 {
568 public:
570 };
571
572} // end of namespace
573#endif
574
575
576
DefaultWeight DefaultParameter
DefaultContainer TerminalNode
Definition index.py:1
static bool remove(type &cont, const_child_ptr aChild)
SG::GenerateIndexingPolicy< CONT >::type::index_type external_index_type
static void changeParm(type &, const CONT *, const external_index_type &, const DefaultWeight &)
static bool getContIndex(type_const_iterator thisIter, external_index_type &theIndex)
static void insert(type &cont, const CONT *aChildContainer, const_child_ptr aChild, const DefaultWeight &, size_t sizeHint=0)
static bool getContIndex(const type &cont, const_child_ptr aChild, external_index_type &theIndex)
static bool remove(type &cont, const ElementLink< CONT > *anElement)
static type_iterator find(type &cont, const_child_ptr aChild)
static const_child_ptr getChildPtr(type_const_iterator iter)
static const CONT * getContPtr(const type &cont, const_child_ptr aChild)
static const CONT & getContRef(const type &cont, const_child_ptr aChild)
static void changeParm(type_iterator &, const DefaultWeight &)
static const CONT * getContPtr(type_const_iterator thisIter)
static const ElementLink< CONT > * getElementPtr(type_const_iterator thisIter)
static void insert(type &cont, const CONT *aChildContainer, const external_index_type &anIndex, const DefaultWeight &, size_t sizeHint=0)
static bool contains(const type &cont, const_child_ptr aChild)
static void changeParm(type &, const_child_ptr, const DefaultWeight &)
static const CONT & getContRef(type_const_iterator thisIter)
static type_const_iterator find(const type &cont, const_child_ptr aChild)
static bool replace(type &cont, const CONT &theNewContainer)
static DefaultWeight getChildPar(type_const_iterator)
static void insert(type &cont, const ElementLink< CONT > *aLink, const DefaultWeight &, size_t sizeHint=0)
static bool remove(type &cont, const ElementLink< CONT > *theElement)
static bool getContIndex(type_const_iterator thisIter, external_index_type &theIndex)
static RPAR getChildPar(type_const_iterator thisIter)
static const CONT & getContRef(type_const_iterator thisIter)
static const CONT * getContPtr(type_const_iterator thisIter)
SG::GenerateIndexingPolicy< container_type >::type::index_type external_index_type
static bool getContIndex(const type &cont, const_child_ptr aChild, external_index_type &theIndex)
static void insert(type &cont, const CONT *aChildContainer, const external_index_type &anIndex, IProxyDict *sg, const RPAR &aPar=RPAR(), size_t sizeHint=0)
static const ElementLink< CONT > * getElementPtr(type_const_iterator thisIter)
static void changeParm(type &cont, const CONT *pContainer, const external_index_type &refIndex, const RPAR &aPar=RPAR())
static const CONT * getContPtr(const type &cont, const_child_ptr aChild)
static const_child_ptr getChildPtr(type_const_iterator thisIter)
static bool remove(type &cont, const_child_ptr aChild)
static const CONT & getContRef(const type &cont, const_child_ptr aChild)
static void insert(type &cont, const CONT *aChildContainer, const external_index_type &anIndex, const RPAR &aPar=RPAR(), size_t sizeHint=0)
static void insert(type &cont, const ElementLink< CONT > *aLink, const RPAR &aPar=RPAR(), size_t sizeHint=0)
static type_const_iterator find(const type &cont, const_child_ptr aChild)
std::pair< ElementLink< container_type >, parameter_type > value_type
static bool contains(const type &cont, const_child_ptr aChild)
static void changeParm(type &cont, const_child_ptr pChild, const RPAR &aPar=RPAR())
static type_iterator find(type &cont, const_child_ptr aChild)
static bool replace(type &cont, const CONT &theNewContainer)
static void insert(type &cont, const CONT *aChildContainer, const_child_ptr aChild, const RPAR &aPar=RPAR(), size_t sizeHint=0)
const DefaultWeight & operator*(const DefaultWeight &) const
bool operator==(DefaultWeight &) const
const DefaultWeight & operator+(const DefaultWeight &) const