Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:24:03

0001 #ifndef PODIO_DETAIL_LINKCOLLECTIONITERATOR_H
0002 #define PODIO_DETAIL_LINKCOLLECTIONITERATOR_H
0003 
0004 #include "podio/detail/LinkFwd.h"
0005 #include "podio/utilities/MaybeSharedPtr.h"
0006 #include <iterator>
0007 
0008 namespace podio {
0009 template <typename FromT, typename ToT, bool Mutable>
0010 class LinkCollectionIteratorT {
0011   using LinkType = LinkT<FromT, ToT, Mutable>;
0012   using LinkObjT = LinkObj<FromT, ToT>;
0013 
0014 public:
0015   using value_type = LinkType;
0016   using difference_type = ptrdiff_t;
0017   using reference = LinkType;
0018   using pointer = LinkType*;
0019   using iterator_category = std::input_iterator_tag;
0020   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0021   // remain valid as long as the iterator is valid, not as long as the range is valid.
0022   using iterator_concept = std::random_access_iterator_tag;
0023 
0024   LinkCollectionIteratorT(size_t index, const LinkObjPointerContainer<FromT, ToT>* coll) :
0025       m_index(index), m_object(podio::utils::MaybeSharedPtr<LinkObjT>{nullptr}), m_collection(coll) {
0026   }
0027   LinkCollectionIteratorT() = default;
0028   LinkCollectionIteratorT(const LinkCollectionIteratorT&) = default;
0029   LinkCollectionIteratorT& operator=(const LinkCollectionIteratorT&) = default;
0030   LinkCollectionIteratorT(LinkCollectionIteratorT&&) = default;
0031   LinkCollectionIteratorT& operator=(LinkCollectionIteratorT&&) = default;
0032   ~LinkCollectionIteratorT() = default;
0033 
0034   auto operator<=>(const LinkCollectionIteratorT& other) const {
0035     return m_index <=> other.m_index;
0036   }
0037 
0038   bool operator==(const LinkCollectionIteratorT& other) const {
0039     return m_index == other.m_index;
0040   }
0041 
0042   LinkType operator*() const {
0043     return LinkType{podio::utils::MaybeSharedPtr<LinkObjT>((*m_collection)[m_index])};
0044   }
0045 
0046   LinkType* operator->() {
0047     m_object.m_obj = podio::utils::MaybeSharedPtr<LinkObjT>((*m_collection)[m_index]);
0048     return &m_object;
0049   }
0050 
0051   LinkCollectionIteratorT& operator++() {
0052     ++m_index;
0053     return *this;
0054   }
0055 
0056   LinkCollectionIteratorT operator++(int) {
0057     auto copy = *this;
0058     ++m_index;
0059     return copy;
0060   }
0061 
0062   LinkCollectionIteratorT& operator--() {
0063     --m_index;
0064     return *this;
0065   }
0066 
0067   LinkCollectionIteratorT operator--(int) {
0068     auto copy = *this;
0069     --m_index;
0070     return copy;
0071   }
0072 
0073   LinkCollectionIteratorT& operator+=(difference_type n) {
0074     m_index += n;
0075     return *this;
0076   }
0077 
0078   LinkCollectionIteratorT operator+(difference_type n) const {
0079     auto copy = *this;
0080     copy += n;
0081     return copy;
0082   }
0083 
0084   friend LinkCollectionIteratorT operator+(difference_type n, const LinkCollectionIteratorT& it) {
0085     return it + n;
0086   }
0087 
0088   LinkCollectionIteratorT& operator-=(difference_type n) {
0089     m_index -= n;
0090     return *this;
0091   }
0092 
0093   LinkCollectionIteratorT operator-(difference_type n) const {
0094     auto copy = *this;
0095     copy -= n;
0096     return copy;
0097   }
0098 
0099   LinkType operator[](difference_type n) const {
0100     return LinkType{podio::utils::MaybeSharedPtr<LinkObjT>((*m_collection)[m_index + n])};
0101   }
0102 
0103   difference_type operator-(const LinkCollectionIteratorT& other) const {
0104     return m_index - other.m_index;
0105   }
0106 
0107 private:
0108   size_t m_index{0};
0109   LinkType m_object{podio::utils::MaybeSharedPtr<LinkObjT>{nullptr}};
0110   const LinkObjPointerContainer<FromT, ToT>* m_collection{nullptr};
0111 };
0112 } // namespace podio
0113 
0114 #endif // PODIO_DETAIL_LINKCOLLECTIONITERATOR_H