Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:07:51

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/UniverseTypeTraits.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<UniverseType U>
0024 struct UniverseTypeTraits;
0025 
0026 #define ORANGE_UNIV_TRAITS(ENUM_VALUE, CLS)             \
0027     template<>                                          \
0028     struct UniverseTypeTraits<UniverseType::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 UniverseTypeTraits instance.
0045  */
0046 template<class F>
0047 CELER_CONSTEXPR_FUNCTION decltype(auto)
0048 visit_universe_type(F&& func, UniverseType ut)
0049 {
0050 #define ORANGE_UT_VISIT_CASE(TYPE)          \
0051     case UniverseType::TYPE:                \
0052         return celeritas::forward<F>(func)( \
0053             UniverseTypeTraits<UniverseType::TYPE>{})
0054 
0055     switch (ut)
0056     {
0057         ORANGE_UT_VISIT_CASE(simple);
0058         ORANGE_UT_VISIT_CASE(rect_array);
0059         default:
0060             CELER_ASSERT_UNREACHABLE();
0061     }
0062 #undef ORANGE_UT_VISIT_CASE
0063 }
0064 
0065 //---------------------------------------------------------------------------//
0066 }  // namespace celeritas