Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-27 09:40:47

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/univ/UnivTypeTraits.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/math/Algorithms.hh"
0010 #include "orange/OrangeTypes.hh"
0011 
0012 namespace celeritas
0013 {
0014 //---------------------------------------------------------------------------//
0015 struct SimpleUnitRecord;
0016 class SimpleUnitTracker;
0017 class RectArrayTracker;
0018 
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Map universe enumeration to surface data and tracker classes.
0022  */
0023 template<UnivType U>
0024 struct UnivTypeTraits;
0025 
0026 #define ORANGE_UNIV_TRAITS(ENUM_VALUE, CLS) \
0027     template<> \
0028     struct UnivTypeTraits<UnivType::ENUM_VALUE> \
0029     { \
0030         using record_type = CLS##Record; \
0031         using tracker_type = CLS##Tracker; \
0032     }
0033 
0034 ORANGE_UNIV_TRAITS(simple, SimpleUnit);
0035 ORANGE_UNIV_TRAITS(rect_array, RectArray);
0036 
0037 #undef ORANGE_UNIV_TRAITS
0038 
0039 //---------------------------------------------------------------------------//
0040 /*!
0041  * Expand a macro to a switch statement over all possible universe types.
0042  *
0043  * The \c func argument should be a functor that takes a single argument which
0044  * is a UnivTypeTraits instance.
0045  */
0046 template<class F>
0047 CELER_CONSTEXPR_FUNCTION decltype(auto) visit_univ_type(F&& func, UnivType ut)
0048 {
0049 #define ORANGE_UT_VISIT_CASE(TYPE) \
0050     case UnivType::TYPE: \
0051         return celeritas::forward<F>(func)(UnivTypeTraits<UnivType::TYPE>{})
0052 
0053     switch (ut)
0054     {
0055         ORANGE_UT_VISIT_CASE(simple);
0056         ORANGE_UT_VISIT_CASE(rect_array);
0057         default:
0058             CELER_ASSERT_UNREACHABLE();
0059     }
0060 #undef ORANGE_UT_VISIT_CASE
0061 }
0062 
0063 //---------------------------------------------------------------------------//
0064 }  // namespace celeritas