2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
6 * @file AthLinks/tools/ForwardIndexingPolicy.icc
7 * @author scott snyder <snyder@bnl.gov>
9 * @brief Indexing policy for a vector-like container.
17 * @brief Test to see if an index is valid.
18 * @param index The index to test.
20 template <class CONT, class VALUE_TYPE>
22 bool ForwardIndexingPolicy<CONT, VALUE_TYPE>::isValid (stored_index_type index)
24 return index != static_cast<stored_index_type>(INVALID);
29 * @brief Convert from stored to external index types.
30 * @param index The stored index.
32 template <class CONT, class VALUE_TYPE>
34 typename ForwardIndexingPolicy<CONT, VALUE_TYPE>::index_type
35 ForwardIndexingPolicy<CONT, VALUE_TYPE>::storedToExternal (stored_index_type index)
37 if (index == static_cast<stored_index_type>(INVALID))
44 * @brief Make an index invalid.
45 * @param index[out] The index to reset.
47 template <class CONT, class VALUE_TYPE>
49 void ForwardIndexingPolicy<CONT, VALUE_TYPE>::reset (stored_index_type& index)
51 index = static_cast<stored_index_type>(INVALID);
56 * @brief Retrieve from a container the element corresponding to an index.
57 * @param index The index to fetch.
58 * @param data The container.
60 * Will throw SG::ExcBadForwardLink if the index is invalid.
62 template <class CONT, class VALUE_TYPE>
64 typename ForwardIndexingPolicy<CONT, VALUE_TYPE>::ElementType
65 ForwardIndexingPolicy<CONT, VALUE_TYPE>::lookup (index_type index, const CONT& data)
67 if (!isValid(index) || (data.size() <= index)) {
68 SG::throwExcBadForwardLink (index, data.size(), ClassName<CONT>::name());
71 typedef typename CONT::const_iterator const_iterator;
72 const_iterator iter = data.begin();
73 std::advance(iter, index);
79 * @brief Find the index of the (first) instance of ELEMENT in DATA.
80 * @param data The container to search.
81 * @param element The element to find.
82 * @param index[out] The index in the container of @c element.
84 * Throws SG::ExcElementNotFound if the element is not in the container.
86 template <class CONT, class VALUE_TYPE>
87 void ForwardIndexingPolicy<CONT, VALUE_TYPE>::reverseLookup(const CONT& data,
88 ElementConstReference element,
91 //compiler checks we can compare elements
92 ::boost::function_requires<typename ::boost::EqualityComparableConcept<ElementType> >();
94 // Note that reverse lookup redoes the lookup even if m_isValid is true.
95 // Must ensure that we get correct index before persistency
97 typename CONT::size_type cindex;
98 if (!SG::findInContainer (data, element, cindex))
99 throwExcElementNotFound ("reverseLookup");