27 #ifndef TOMOGRAPHER_VALUECALCULATOR_H 28 #define TOMOGRAPHER_VALUECALCULATOR_H 47 namespace tomo_internal {
52 template<
int NumValueCalculators,
typename ValueType,
typename... ValueCalculators>
53 struct MplxVC_getval_helper
55 template<
typename PointType,
int IterI = 0,
56 TOMOGRAPHER_ENABLED_IF_TMPL(IterI < NumValueCalculators)>
60 return std::get<IterI>(_valcalcs).getValue(std::forward<PointType>(x));
62 return getValue<PointType, IterI+1>(_i, _valcalcs, std::forward<PointType>(x));
65 template<
typename PointType,
int IterI = 0,
66 TOMOGRAPHER_ENABLED_IF_TMPL(IterI == NumValueCalculators)>
69 tomographer_assert(
false &&
"Invalid i: i>=NumValueCalculators or i<0");
74 template<
typename ValueType,
typename... ValueCalculators>
75 struct MplxVC_getval_helper<1, ValueType, ValueCalculators...>
78 template<
typename Po
intType>
81 tomographer_assert(_i == 0 &&
"i != 0 but NumValueCalculators == 1");(void)_i;
82 return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
86 template<
typename ValueType,
typename... ValueCalculators>
87 struct MplxVC_getval_helper<2, ValueType, ValueCalculators...>
90 template<
typename Po
intType>
93 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
95 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
96 default:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
101 template<
typename ValueType,
typename... ValueCalculators>
102 struct MplxVC_getval_helper<3, ValueType, ValueCalculators...>
105 template<
typename Po
intType>
108 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
110 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
111 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
112 default:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
117 template<
typename ValueType,
typename... ValueCalculators>
118 struct MplxVC_getval_helper<4, ValueType, ValueCalculators...>
121 template<
typename Po
intType>
124 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
126 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
127 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
128 case 2:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
129 default:
return std::get<3>(_valcalcs).getValue(std::forward<PointType>(x));
134 template<
typename ValueType,
typename... ValueCalculators>
135 struct MplxVC_getval_helper<5, ValueType, ValueCalculators...>
138 template<
typename Po
intType>
141 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
143 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
144 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
145 case 2:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
146 case 3:
return std::get<3>(_valcalcs).getValue(std::forward<PointType>(x));
147 default:
return std::get<4>(_valcalcs).getValue(std::forward<PointType>(x));
152 template<
typename ValueType,
typename... ValueCalculators>
153 struct MplxVC_getval_helper<6, ValueType, ValueCalculators...>
156 template<
typename Po
intType>
159 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
161 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
162 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
163 case 2:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
164 case 3:
return std::get<3>(_valcalcs).getValue(std::forward<PointType>(x));
165 case 4:
return std::get<4>(_valcalcs).getValue(std::forward<PointType>(x));
166 default:
return std::get<5>(_valcalcs).getValue(std::forward<PointType>(x));
183 template<
typename ValueType_,
typename... ValueCalculators>
188 typedef ValueType_ ValueType;
190 static constexpr
int NumValueCalculators =
sizeof...(ValueCalculators);
191 static constexpr
int NumStaticallyOptimizedIfs = 6;
211 template<
typename... Args>
213 : _valcalcs(
std::forward<Args>(valcalcs)...), _i(i)
219 inline const typename std::tuple_element<I, ValueCalculatorsTupleType>::type &
getValueCalculator()
const 221 return std::get<I>(_valcalcs);
225 template<
int I,
typename Po
intType>
228 return getValueCalculator<I>().getValue(std::forward<PointType>(x));
236 template<
typename Po
intType>
239 return tomo_internal::MplxVC_getval_helper<
240 NumValueCalculators,ValueType,ValueCalculators...
241 >::getValue(_i, _valcalcs, std::forward<PointType>(x));
A ValueCalculator-instance which the choice of which ValueCalculator to use at run-time.
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
Base namespace for the Tomographer project.
const std::tuple_element< I, ValueCalculatorsTupleType >::type & getValueCalculator() const
Get a particular value calculator [static index].
ValueType getValueI(PointType &&x) const
Calculate the value at the given point, using the I-th value calculator.
ValueType getValue(PointType &&x) const
The main method which computes the value according to the pre-chosen ValueCalculator.
Some C++ utilities, with a tad of C++11 tricks.
Managing the need for specific overrides to operator new() for some types (especially Eigen types) ...
MultiplexorValueCalculator(const int i, Args &&...valcalcs)
Constructor.