forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniverseTypeTraits.hh
67 lines (58 loc) · 2.22 KB
/
UniverseTypeTraits.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//----------------------------------*-C++-*----------------------------------//
// Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file orange/univ/UniverseTypeTraits.hh
//---------------------------------------------------------------------------//
#pragma once
#include "corecel/math/Algorithms.hh"
#include "orange/OrangeTypes.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
struct SimpleUnitRecord;
class SimpleUnitTracker;
class RectArrayTracker;
//---------------------------------------------------------------------------//
/*!
* Map universe enumeration to surface data and tracker classes.
*/
template<UniverseType U>
struct UniverseTypeTraits;
#define ORANGE_UNIV_TRAITS(ENUM_VALUE, CLS) \
template<> \
struct UniverseTypeTraits<UniverseType::ENUM_VALUE> \
{ \
using record_type = CLS##Record; \
using tracker_type = CLS##Tracker; \
}
ORANGE_UNIV_TRAITS(simple, SimpleUnit);
ORANGE_UNIV_TRAITS(rect_array, RectArray);
#undef ORANGE_UNIV_TRAITS
//---------------------------------------------------------------------------//
/*!
* Expand a macro to a switch statement over all possible universe types.
*
* The \c func argument should be a functor that takes a single argument which
* is a UniverseTypeTraits instance.
*/
template<class F>
CELER_CONSTEXPR_FUNCTION decltype(auto)
visit_universe_type(F&& func, UniverseType ut)
{
#define ORANGE_UT_VISIT_CASE(TYPE) \
case UniverseType::TYPE: \
return celeritas::forward<F>(func)( \
UniverseTypeTraits<UniverseType::TYPE>{})
switch (ut)
{
ORANGE_UT_VISIT_CASE(simple);
ORANGE_UT_VISIT_CASE(rect_array);
default:
CELER_ASSERT_UNREACHABLE();
}
#undef ORANGE_UT_VISIT_CASE
}
//---------------------------------------------------------------------------//
} // namespace celeritas