Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:17:13

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