Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Acts/EventData/detail/DynamicKeyIterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/detail/DynamicColumn.hpp"
0012 #include "Acts/Utilities/Concepts.hpp"
0013 #include "Acts/Utilities/HashedString.hpp"
0014 
0015 #include <unordered_map>
0016 
0017 namespace Acts::detail {
0018 
0019 template <typename C>
0020 class DynamicKeyIterator {
0021   using map_t = std::unordered_map<HashedString, std::unique_ptr<C>>;
0022 
0023  public:
0024   using iterator_category = std::forward_iterator_tag;
0025   using value_type = HashedString;
0026   using difference_type = std::ptrdiff_t;
0027   using pointer = void;
0028   using reference = void;
0029 
0030   DynamicKeyIterator(typename map_t::const_iterator it) : m_it{it} {}
0031   DynamicKeyIterator() = default;
0032 
0033   DynamicKeyIterator& operator++() {
0034     m_it++;
0035     return *this;
0036   }
0037 
0038   DynamicKeyIterator operator++(int /*value*/) {
0039     auto copy = *this;
0040     ++(copy.m_it);
0041     return copy;
0042   }
0043 
0044   bool operator==(const DynamicKeyIterator& other) const {
0045     return m_it == other.m_it;
0046   }
0047 
0048   bool operator!=(const DynamicKeyIterator& other) const {
0049     return m_it != other.m_it;
0050   }
0051 
0052   value_type operator*() const { return m_it->first; }
0053 
0054  private:
0055   typename map_t::const_iterator m_it;
0056 };
0057 
0058 ACTS_STATIC_CHECK_CONCEPT(std::forward_iterator, DynamicKeyIterator<int>);
0059 
0060 template <typename C>
0061 class DynamicKeyRange {
0062  public:
0063   DynamicKeyRange(DynamicKeyIterator<C> begin, DynamicKeyIterator<C> end)
0064       : m_begin{begin}, m_end{end} {}
0065 
0066   DynamicKeyIterator<C> begin() const { return m_begin; }
0067   DynamicKeyIterator<C> end() const { return m_end; }
0068 
0069  private:
0070   DynamicKeyIterator<C> m_begin;
0071   DynamicKeyIterator<C> m_end;
0072 };
0073 
0074 }  // namespace Acts::detail