2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
7 * @file AthLinks/tools/SetIndexingPolicy.icc
8 * @author scott snyder <snyder@bnl.gov>
10 * @brief Indexing policy for a set-like container.
18 * @brief Test to see if an index is valid.
19 * @param index The index to test.
22 requires CxxUtils::detail::SimpleAssociativeContainer<SET>
24 bool SetIndexingPolicy<SET>::isValid (const stored_index_type& index)
26 return index.isValid();
31 * @brief Convert from stored to external index types.
32 * @param index The stored index.
35 requires CxxUtils::detail::SimpleAssociativeContainer<SET>
37 typename SetIndexingPolicy<SET>::index_type
38 SetIndexingPolicy<SET>::storedToExternal (stored_index_type index)
45 * @brief Make an index invalid.
46 * @param index[out] The index to reset.
49 requires CxxUtils::detail::SimpleAssociativeContainer<SET>
51 void SetIndexingPolicy<SET>::reset (stored_index_type& index)
58 * @brief Retrieve from a container the element corresponding to an index.
59 * @param index The index to fetch.
60 * @param data The container.
62 * Will throw SG::ExcInvalidIndex if the index is invalid and
63 * SG::ExcIndexNotFound if the index is not in the container.
66 requires CxxUtils::detail::SimpleAssociativeContainer<SET>
67 typename SetIndexingPolicy<SET>::ElementType
68 SetIndexingPolicy<SET>::lookup(const stored_index_type& index,
72 SG::throwExcInvalidIndex ("SetIndexingPolicy");
73 iterator iter = data.find(index);
74 if (iter == data.end())
75 SG::throwExcIndexNotFound ("SetIndexingPolicy");
81 * @brief Find the index of the (first) instance of ELEMENT in DATA.
82 * @param data The container to search.
83 * @param element The element to find.
84 * @param index[out] The index in the container of @c element.
86 * Throws SG::ExcElementNotFound if the element is not in the container.
89 requires CxxUtils::detail::SimpleAssociativeContainer<SET>
91 SetIndexingPolicy<SET>::reverseLookup(const SET& data,
92 ElementConstReference element,
95 //compiler checks we can compare elements
96 static_assert(std::equality_comparable<ElementType>, "ElementType must support equality comparison");
97 // Note that reverseLookup will recalculate index even if m_valid is true.
98 // Must ensure that index is write before persistency
99 if (data.end() != data.find(element))
104 SG::throwExcElementNotFound ("reverseLookup");