ATLAS Offline Software
Loading...
Searching...
No Matches
NavigationDefaults.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 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 (*aChildContainer,anIndex, aPar);
176 }
177
178 // insertion of ElementLink by object index
179 static void insert(type& cont, const CONT* aChildContainer,
180 const external_index_type& anIndex,
181 IProxyDict* sg,
182 const RPAR& aPar=RPAR(),
183 size_t sizeHint = 0)
184 {
185 if (sizeHint && cont.capacity() < sizeHint)
186 cont.reserve(sizeHint);
187 cont.emplace_back (*aChildContainer,anIndex, sg, aPar);
188 }
189
190 // insertion of ElementLink by ElementLink
191 static void insert(type& cont,
192 const ElementLink<CONT>* aLink,
193 const RPAR& aPar=RPAR(),
194 size_t sizeHint = 0)
195 {
196 if (sizeHint && cont.capacity() < sizeHint)
197 cont.reserve(sizeHint);
198 cont.push_back(value_type(*aLink, aPar));
199 }
200
201 // change parameter
202 static void changeParm(type& cont,
203 const_child_ptr pChild,
204 const RPAR& aPar=RPAR())
205 {
206 type_iterator iObj = find(cont,pChild);
207 if ( iObj != cont.end() ) (*iObj).second = aPar;
208 }
209
210 // change parameter
211 static void changeParm(type& cont,
212 const CONT* pContainer,
213 const external_index_type& refIndex,
214 const RPAR& aPar=RPAR())
215 {
216 changeParm(cont,(pContainer->operator[])(refIndex),aPar);
217 }
218
219 // change parameter
220 // static void changeParm(type_iterator& iter,
221 // const RPAR& aPar=RPAR())
222 // {
223 // (*iter).second = aPar;
224 // }
225
227
228 // find method implementation for const_iterator on objects
229 static type_const_iterator
230 find(const type& cont, const_child_ptr aChild)
231 {
232 type_const_iterator iEntry = cont.begin();
233 type_const_iterator lastEntry = cont.end();
234 while (iEntry != lastEntry && aChild != *((*iEntry).first)) ++iEntry;
235 return iEntry;
236 }
237
238 // find method for iterator on objects
239 static type_iterator
240 find(type& cont, const_child_ptr aChild)
241 {
242 type_iterator iEntry = cont.begin();
243 type_iterator lastEntry = cont.end();
244 while (iEntry != lastEntry && aChild != *((*iEntry).first)) ++iEntry;
245 return iEntry;
246 }
247
248 // find method for ElementLinks
249 // static type_const_iterator
250 // find(const type& cont, const ElementLink<CONT>* anElement)
251 // {
252 // const_child_ptr theChild = *(*anElement);
253 // return find(cont,theChild);
254 // }
255
256 // find method for ElementLinks
257 // static type_iterator
258 // find(type& cont, const ElementLink<CONT>* anElement)
259 // {
260 // child_ptr theChild = *(*anElement);
261 // return find(cont,theChild);
262 // }
263
265
266 // removal by object pointer
267 static bool
269 {
270 type_iterator found = find(cont,aChild);
271 if ( found != cont.end() )
272 {
273 // we assume the container owns the ElementLink/parameter pair,
274 // but not the object linked by ElementLink --- FIXME ??
275 // delete (*found).first;
276 cont.erase(found);
277 return true;
278 }
279 else
280 {
281 return false;
282 }
283 }
284
285 // removal by ElementLink
286 static bool
287 remove(type& cont, const ElementLink<CONT>* theElement)
288 {
289 type_iterator found = find(cont,theElement);
290 if ( found != cont.end() )
291 {
292 // delete (*found).first;
293 cont.erase(found);
294 return true;
295 }
296 else
297 {
298 return false;
299 }
300 }
301
302 // replace container in ElementLink
303 static bool
304 replace(type& cont, const CONT& theNewContainer) {
305 type_iterator firstEntry = cont.begin();
306 type_iterator lastEntry = cont.end();
307 for ( ; firstEntry != lastEntry ; ++firstEntry ) {
308 // Must force replacement with second arg true
309 ((*firstEntry).first).setStorableObject(theNewContainer, true);
310 }
311 return true;
312 }
313
314 // test on containment
315 static bool
316 contains(const type& cont, const_child_ptr aChild)
317 {
318 return find(cont,aChild) != cont.end();
319 }
320
321 };
322
324 // Default Constituent Collections: No Relational Parameters //
326
327 template <typename CONT>
329 {
330 // default container is a vector of ElementLinks
331 // typedef const ElementLink<CONT>* value_type;
333 typedef typename std::vector< value_type > type;
334 typedef typename type::iterator type_iterator;
335 typedef typename type::const_iterator type_const_iterator;
336 typedef typename CONT::base_value_type* child_ptr;
337 typedef const typename CONT::base_value_type* const_child_ptr;
338 // typedef typename CONT::const_reference const_child_ptr;
339 // typedef typename CONT::reference child_ptr;
342
343 // object pointer access
345 {
346 const_child_ptr ret = 0;
347 if ((*iter).isValid())
348 ret = *(*iter);
349 return ret;
350 }
351
352 // default weight is dummy
354 { return DefaultWeight(); }
355
356 // ElementLink pointer access
358 thisIter)
359 {
360 return &(*thisIter);
361 }
362
363 // container access by iterator
364 static const CONT& getContRef(type_const_iterator thisIter)
365 {
366 return (*thisIter).getStorableObjectRef();
367 }
368
369 // container access by pointer
370 static const CONT& getContRef(const type& cont, const_child_ptr aChild)
371 {
372 return getContRef(find(cont,aChild));
373 }
374
375 // pointer to container access by iterator
376 static const CONT* getContPtr(type_const_iterator thisIter)
377 {
378 return (*thisIter).getStorableObjectPointer();
379 }
380
381 // pointer to container access by pointer
382 static const CONT* getContPtr(const type& cont, const_child_ptr aChild)
383 {
384 type_const_iterator found = find(cont,aChild);
385 return found != cont.end()
386 ? getContPtr(found)
387 : 0;
388 }
389
390 // index in container access by iterator
391 static bool
393 external_index_type& theIndex)
394 {
395 theIndex = (*thisIter).index();
396 const CONT* cont = getContPtr(thisIter);
397 return cont ? theIndex < cont->size() : false;
398 }
399
400 // index in container access by pointer
401 static bool
402 getContIndex(const type& cont, const_child_ptr aChild,
403 external_index_type& theIndex)
404 {
405 type_const_iterator found = find(cont,aChild);
406 if ( found != cont.end() )
407 {
408 return getContIndex(found,theIndex);
409 }
410 return false;
411 }
412
413 // insertion of ElementLink by object pointer
414 static void insert(type& cont, const CONT* aChildContainer,
415 const_child_ptr aChild,
416 const DefaultWeight&,
417 size_t sizeHint = 0)
418 {
419 if (sizeHint && cont.capacity() < sizeHint)
420 cont.reserve(sizeHint);
421 // cast is an ugly fix!
422 cont.push_back(ElementLink<CONT>(const_cast<child_ptr>(aChild),
423 *aChildContainer));
424 }
425
426 // insertion of ElementLink by object index
427 static void insert(type& cont, const CONT* aChildContainer,
428 const external_index_type& anIndex,
429 const DefaultWeight&,
430 size_t sizeHint = 0)
431 {
432 if (sizeHint && cont.capacity() < sizeHint)
433 cont.reserve(sizeHint);
434 cont.push_back(ElementLink<CONT>(*aChildContainer,anIndex));
435 }
436
437 // direct insertion of ElementLink
438 static void insert(type& cont, const ElementLink<CONT>* aLink,
439 const DefaultWeight&,
440 size_t sizeHint = 0)
441 {
442 if (sizeHint && cont.capacity() < sizeHint)
443 cont.reserve(sizeHint);
444 cont.push_back(*aLink);
445 }
446
447 // change parameter
448 static void changeParm(type& /* cont */,
449 const_child_ptr /* pChild */,
450 const DefaultWeight& /*refParm*/)
451 { }
452
453 // change parameter
454 static void changeParm(type& /* cont */,
455 const CONT* /* pContainer */,
456 const external_index_type& /* refIndex */,
457 const DefaultWeight& /* refParm */)
458 { }
459
460 // change parameter
461 static void changeParm(type_iterator& /* iter */,
462 const DefaultWeight& /* refParm */)
463 { }
464
465 // allocation of object pointer in list
466 static type_const_iterator find(const type& cont,
467 const_child_ptr aChild)
468 {
469 type_const_iterator firstEntry = cont.begin();
470 type_const_iterator lastEntry = cont.end();
471 for ( ; firstEntry != lastEntry; ++firstEntry )
472 {
473 if ( *(*firstEntry) == aChild ) break;
474 }
475 return firstEntry;
476 }
477
478 // same but return iterator
479 static type_iterator find(type& cont, const_child_ptr aChild)
480 {
481 type_iterator firstEntry = cont.begin();
482 type_iterator lastEntry = cont.end();
483 for ( ; firstEntry != lastEntry; ++firstEntry )
484 {
485 if ( *(*firstEntry) == aChild ) break;
486 }
487 return firstEntry;
488 }
489
490 // find ElementLink directly
491 // static type_const_iterator find(const type& cont,
492 // const ElementLink<CONT>* anElement)
493 // {
494 // return std::find(anElement,cont.begin(),cont.end());
495 // }
496
497 // find ElementLink directly
498 // static type_iterator find(type& cont,
499 // const ElementLink<CONT>* anElement)
500 // {
501 // return std::find(anElement,cont.begin(),cont.end());
502 // }
503
504 // removal
505 static bool remove(type& cont, const_child_ptr aChild)
506 {
507 type_iterator found = find(cont,aChild);
508 if ( found != cont.end() )
509 {
510 // ownership of ElementLink!! FIXME
511 // delete *found;
512 cont.erase(found);
513 return true;
514 }
515 else
516 {
517 return false;
518 }
519 }
520
521 // removal of ElementLink
522 static bool remove(type& cont, const ElementLink<CONT>* anElement)
523 {
524 type_iterator found = find(cont,*anElement);
525 if ( found != cont.end() )
526 {
527 // delete *found;
528 cont.erase(anElement);
529 return true;
530 }
531 else
532 {
533 return false;
534 }
535 }
536
537 // replace container in ElementLink
538 static bool
539 replace(type& cont, const CONT& theNewContainer) {
540 type_iterator firstEntry = cont.begin();
541 type_iterator lastEntry = cont.end();
542 for ( ; firstEntry != lastEntry ; ++firstEntry ) {
543 // Must force replacement with second arg true
544 (*firstEntry).setStorableObject(theNewContainer, true);
545 }
546 return true;
547 }
548
549 // test on containment
550 static bool
551 contains(const type& cont, const_child_ptr aChild)
552 {
553 return find(cont,aChild) != cont.end();
554 }
555 };
556
558 // Default Constituent Collections: Terminal Node (Dummy) //
560
561 template<>
563 {
564 public:
566 };
567
568} // end of namespace
569#endif
570
571
572
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