Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <typeinfo> 7 : #include <unordered_map> 8 : 9 : #include "Time/RequestsStepperErrorTolerances.hpp" 10 : #include "Utilities/Gsl.hpp" 11 : 12 : /// \cond 13 : struct StepperErrorTolerances; 14 : /// \endcond 15 : 16 : namespace collect_stepper_error_tolerances_detail { 17 : void process_request( 18 : gsl::not_null<std::unordered_map<std::type_index, StepperErrorTolerances>*> 19 : tolerances, 20 : const RequestsStepperErrorTolerances& tolerance_request); 21 : } // namespace collect_stepper_error_tolerances_detail 22 : 23 : /// If \p potential_request inherits from 24 : /// `RequestsStepperErrorTolerances`, merge its tolerance requests 25 : /// into \p tolerances. 26 : template <typename PotentialRequest> 27 1 : void collect_stepper_error_tolerances( 28 : const gsl::not_null< 29 : std::unordered_map<std::type_index, StepperErrorTolerances>*> 30 : tolerances, 31 : const PotentialRequest& potential_request) { 32 : // This will fail to compile for non-polymorphic types. We could 33 : // check for that, but all normal uses of this should be on 34 : // polymorphic types and it serves as a check that you don't pass a 35 : // (smart) pointer to the object instead of the object itself. 36 : if (const auto* const tolerance_request = 37 : dynamic_cast<const RequestsStepperErrorTolerances*>( 38 : &potential_request); 39 : tolerance_request != nullptr) { 40 : collect_stepper_error_tolerances_detail::process_request( 41 : tolerances, *tolerance_request); 42 : } 43 : }