|
|
|||
File indexing completed on 2025-10-27 07:55:13
0001 // This file is part of the ACTS project. 0002 // 0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. 0008 0009 #pragma once 0010 0011 #include "Acts/Navigation/NavigationDelegate.hpp" 0012 #include "Acts/Navigation/NavigationStream.hpp" 0013 0014 #include <type_traits> 0015 0016 namespace Acts { 0017 0018 class TrackingVolume; 0019 class INavigationPolicy; 0020 class Surface; 0021 0022 /// Concept for a navigation policy 0023 /// This exists so `updateState` can be a non-virtual method and we still have a 0024 /// way to enforce it exists. 0025 template <typename T> 0026 concept NavigationPolicyConcept = requires { 0027 requires std::is_base_of_v<INavigationPolicy, T>; 0028 // Has a conforming update method 0029 requires requires(T policy, const NavigationArguments& args) { 0030 policy.initializeCandidates(args, 0031 std::declval<AppendOnlyNavigationStream&>(), 0032 std::declval<const Logger&>()); 0033 }; 0034 }; 0035 0036 /// Base class for all navigation policies. The policy needs to be *connected* 0037 /// to a delegate via a virtual method for it to become active. The update 0038 /// method is not part of the class interface. The conventional `updateState` 0039 /// method is only required for use with the navigation policy factory, 0040 /// otherwise `connect` is free to connect any function. 0041 class INavigationPolicy { 0042 public: 0043 /// Noop update function that is suitable as a default for default navigation 0044 /// delegates. 0045 static void noopInitializeCandidates( 0046 const NavigationArguments& /*unused*/, 0047 const AppendOnlyNavigationStream& /*unused*/, const Logger& /*unused*/) { 0048 // This is a noop 0049 } 0050 0051 /// Virtual destructor so policies can be held through this base class. 0052 virtual ~INavigationPolicy() = default; 0053 0054 /// Connect a policy with a delegate (usually a member of a volume). 0055 /// This method exists to allow a policy to ensure a non-virtual function is 0056 /// registered with the delegate. 0057 /// @param delegate The delegate to connect to 0058 virtual void connect(NavigationDelegate& delegate) const = 0; 0059 0060 /// Convenience function to walk over all navigation policies. The default 0061 /// implementation just calls this on itself, while the @ref 0062 /// MultiNavigationPolicy will call it on all it's children. 0063 /// @param visitor The visitor function to call for each policy 0064 virtual void visit( 0065 const std::function<void(const INavigationPolicy&)>& visitor) const { 0066 visitor(*this); 0067 } 0068 0069 protected: 0070 /// Internal helper function for derived classes that conform to the concept 0071 /// and have a conventional `updateState` method. Mainly used to save some 0072 /// boilerplate. 0073 /// @tparam T The type of the navigation policy 0074 /// @param delegate The delegate to connect to 0075 template <NavigationPolicyConcept T> 0076 void connectDefault(NavigationDelegate& delegate) const { 0077 // This cannot be a concept because we use it in CRTP below 0078 const auto* self = static_cast<const T*>(this); 0079 delegate.template connect<&T::initializeCandidates>(self); 0080 } 0081 }; 0082 0083 } // namespace Acts
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|