2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 ////////////////////////////////////
6 // Navigationtoken Implementation //
7 ////////////////////////////////////
12 // query depth control
13 template<typename CHILD, typename CHILDPAR, typename HASH>
15 NavigationToken<CHILD,CHILDPAR,HASH>::pushQuery(const INavigable& /*parent*/,
16 const INavigable& /*child*/ )
19 // return ( m_navCondition != 0 )
20 // ? ( m_navCondition->accept(&parent) )
24 // relational parameter access
25 template<typename CHILD, typename CHILDPAR, typename HASH>
27 NavigationToken<CHILD,CHILDPAR,HASH>::getParameter(const_child_ptr data ) const
29 typename NavigationToken::tokenConstIterator found = m_data.find(data);
30 return ( found != m_data.end()
35 template<typename CHILD, typename CHILDPAR, typename HASH>
37 NavigationToken<CHILD,CHILDPAR,HASH>::getParameter( const_iterator& anIter )
40 return anIter.getParameter();
44 template <typename CHILD, typename CHILDPAR, typename HASH>
45 void NavigationToken<CHILD,CHILDPAR,HASH>::clear()
47 typedef typename tokenStore::allocator_type alloc_t;
49 alloc_t::get_allocator(m_data).reset();
50 if ( m_navSelector != 0 ) m_navSelector->reset();
51 if ( m_navCondition != 0 ) m_navCondition->reset();
55 namespace Navigation_detail {
58 // Add a pointer/weight pair to the map.
59 template <typename MAP, typename const_child_ptr, typename CHILDPAR>
61 void addToMap (MAP& map,
65 // Insert into container iff nothing already exists with this key.
66 // But return an iterator pointing at the element in any case.
67 std::pair<typename MAP::iterator, bool> ret =
68 map.insert (std::make_pair (data, weight));
71 // Didn't insert (because an element was already there).
73 ret.first->second += weight;
78 // Add a pointer/weight pair to the map.
79 // Specialization for the DefaultWeight case.
80 template <typename MAP, typename const_child_ptr>
82 void addToMap (MAP& map,
84 NavigationDefaults::DefaultWeight /*weight*/)
86 // In this case, we don't need to worry about propagating or summing
87 // weights. We just need to keep track of unique child pointers.
88 // Make sure the pointer is in the map.
93 } // namespace Navigation_detail
96 // set object in token
97 template <typename CHILD, typename CHILDPAR, typename HASH>
98 void NavigationToken<CHILD,CHILDPAR,HASH>::setObject(const_child_ptr data,
101 // check pointer validity
104 if ( m_navSelector == 0 || (m_navSelector !=0 && m_navSelector->accept(data,weight)) )
106 Navigation_detail::addToMap (m_data, data, weight);
111 // check if queried object is of requested type itself
112 template <typename CHILD, typename CHILDPAR, typename HASH>
113 bool NavigationToken<CHILD,CHILDPAR,HASH>::trySetObject(const
114 INavigable* theObject)
116 // See if this is the correct type.
117 // Cache the last complete type we rejected, to cut down on the
118 // number of dynamic_cast calls.
119 const std::type_info* ti = &typeid (*theObject);
120 if (ti == m_lastReject)
122 const_child_ptr thePtr = dynamic_cast<const_child_ptr>(theObject);
125 this->setObject(thePtr);
132 // check if queried object is of requested type itself, including parameters
133 template <typename CHILD, typename CHILDPAR, typename HASH>
135 NavigationToken<CHILD,CHILDPAR,HASH>::trySetObject(const
136 INavigable* theObject,
137 const std::any& theWeight)
139 // See if this is the correct type.
140 // Cache the last complete type we rejected, to cut down on the
141 // number of dynamic_cast calls.
142 const std::type_info* ti = &typeid (*theObject);
143 if (ti == m_lastReject)
145 const_child_ptr thePtr = dynamic_cast<const_child_ptr>(theObject);
147 CHILDPAR myWeight(std::any_cast<CHILDPAR>(theWeight));
150 setObject(thePtr,myWeight);
159 template <typename CHILD, typename CHILDPAR, typename HASH>
160 void NavigationToken<CHILD,CHILDPAR,HASH>::dumpStore()
162 std::cout << "[NavigationToken::dumpStore] - # elements in store: "
163 << this->size() << std::endl;
164 tokenConstIterator first = m_data.begin();
165 unsigned int iCtr = 0;
166 for ( ; first != m_data.end(); first++ )
169 std::cout << "Element " << std::setw(6) << iCtr << ": pointer to object "