File indexing completed on 2025-08-06 08:10:00
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Utilities/Any.hpp"
0013 #include "Acts/Utilities/Delegate.hpp"
0014 #include "Acts/Utilities/TypeTraits.hpp"
0015
0016 #include <cassert>
0017 #include <iostream>
0018 #include <type_traits>
0019 #include <utility>
0020
0021 #if !defined(ACTS_SOURCELINK_SBO_SIZE)
0022
0023 #define ACTS_SOURCELINK_SBO_SIZE 16
0024 #endif
0025
0026 namespace Acts {
0027
0028 class SourceLink final {
0029 using any_type = AnyBase<ACTS_SOURCELINK_SBO_SIZE>;
0030
0031 public:
0032 SourceLink(const SourceLink& other) = default;
0033 SourceLink(SourceLink&& other) = default;
0034 SourceLink& operator=(const SourceLink& other) = default;
0035 SourceLink& operator=(SourceLink&& other) = default;
0036
0037
0038
0039
0040 template <typename T, typename = std::enable_if_t<
0041 !std::is_same_v<std::decay_t<T>, SourceLink>>>
0042 explicit SourceLink(T&& upstream) {
0043 static_assert(!std::is_same_v<std::decay_t<T>, SourceLink>,
0044 "Cannot wrap SourceLink in SourceLink");
0045
0046 if constexpr (std::is_same_v<T, std::decay_t<T>>) {
0047 m_upstream = any_type{std::move(upstream)};
0048 } else {
0049 m_upstream = any_type{static_cast<std::decay_t<T>>(upstream)};
0050 }
0051 }
0052
0053
0054
0055
0056 template <typename T>
0057 T& get() {
0058 return m_upstream.as<T>();
0059 }
0060
0061
0062
0063
0064 template <typename T>
0065 const T& get() const {
0066 return m_upstream.as<T>();
0067 }
0068
0069 private:
0070 any_type m_upstream{};
0071 };
0072
0073 template <typename T>
0074 struct SourceLinkAdapterIterator {
0075 using BaseIterator = T;
0076
0077 using iterator_category = typename BaseIterator::iterator_category;
0078 using value_type = typename BaseIterator::value_type;
0079 using difference_type = typename BaseIterator::difference_type;
0080 using pointer = typename BaseIterator::pointer;
0081 using reference = typename BaseIterator::reference;
0082
0083 explicit SourceLinkAdapterIterator(T iterator) : m_iterator{iterator} {}
0084
0085 SourceLinkAdapterIterator& operator++() {
0086 ++m_iterator;
0087 return *this;
0088 }
0089
0090 bool operator==(const SourceLinkAdapterIterator& other) const {
0091 return m_iterator == other.m_iterator;
0092 }
0093
0094 bool operator!=(const SourceLinkAdapterIterator& other) const {
0095 return !(*this == other);
0096 }
0097
0098 Acts::SourceLink operator*() const { return Acts::SourceLink{*m_iterator}; }
0099
0100 auto operator-(const SourceLinkAdapterIterator& other) const {
0101 return m_iterator - other.m_iterator;
0102 }
0103
0104 BaseIterator m_iterator;
0105 };
0106
0107
0108 using SourceLinkSurfaceAccessor = Delegate<const Surface*(const SourceLink&)>;
0109
0110 }