File indexing completed on 2025-01-30 10:17:13
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Assert.hh"
0011 #include "corecel/cont/Span.hh"
0012 #include "corecel/data/LdgIterator.hh"
0013 #include "orange/OrangeTypes.hh"
0014
0015 #include "LogicStack.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021
0022
0023
0024
0025 class LogicEvaluator
0026 {
0027 public:
0028
0029
0030 using SpanConstLogic = LdgSpan<logic_int const>;
0031 using SpanConstSense = Span<Sense const>;
0032
0033
0034 public:
0035
0036 explicit CELER_FORCEINLINE_FUNCTION LogicEvaluator(SpanConstLogic logic);
0037
0038
0039 inline CELER_FUNCTION bool operator()(SpanConstSense values) const;
0040
0041 private:
0042
0043
0044 SpanConstLogic logic_;
0045 };
0046
0047
0048
0049
0050
0051 CELER_FUNCTION LogicEvaluator::LogicEvaluator(SpanConstLogic logic)
0052 : logic_(logic)
0053 {
0054 CELER_EXPECT(!logic_.empty());
0055 }
0056
0057
0058
0059
0060
0061 CELER_FUNCTION bool LogicEvaluator::operator()(SpanConstSense values) const
0062 {
0063 LogicStack stack;
0064
0065 for (logic_int lgc : logic_)
0066 {
0067 if (!logic::is_operator_token(lgc))
0068 {
0069
0070 CELER_EXPECT(lgc < values.size());
0071 stack.push(static_cast<bool>(values[lgc]));
0072 continue;
0073 }
0074
0075
0076 switch (lgc)
0077 {
0078
0079 case logic::ltrue: stack.push(true); break;
0080 case logic::lor: stack.apply_or(); break;
0081 case logic::land: stack.apply_and(); break;
0082 case logic::lnot: stack.apply_not(); break;
0083 default: CELER_ASSERT_UNREACHABLE();
0084 }
0085
0086 }
0087 CELER_ENSURE(stack.size() == 1);
0088 return stack.top();
0089 }
0090
0091
0092 }
0093 }