28 #ifndef TOMOGRAPHER_VALUECALCULATOR_H 29 #define TOMOGRAPHER_VALUECALCULATOR_H 48 namespace tomo_internal {
53 template<
int NumValueCalculators,
typename ValueType,
typename... ValueCalculators>
54 struct MplxVC_getval_helper
56 template<
typename PointType,
int IterI = 0,
57 TOMOGRAPHER_ENABLED_IF_TMPL(IterI < NumValueCalculators)>
61 return std::get<IterI>(_valcalcs).getValue(std::forward<PointType>(x));
63 return getValue<PointType, IterI+1>(_i, _valcalcs, std::forward<PointType>(x));
66 template<
typename PointType,
int IterI = 0,
67 TOMOGRAPHER_ENABLED_IF_TMPL(IterI == NumValueCalculators)>
75 template<
typename ValueType,
typename... ValueCalculators>
76 struct MplxVC_getval_helper<1, ValueType, ValueCalculators...>
79 template<
typename Po
intType>
83 return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
87 template<
typename ValueType,
typename... ValueCalculators>
88 struct MplxVC_getval_helper<2, ValueType, ValueCalculators...>
91 template<
typename Po
intType>
94 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
96 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
97 default:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
102 template<
typename ValueType,
typename... ValueCalculators>
103 struct MplxVC_getval_helper<3, ValueType, ValueCalculators...>
106 template<
typename Po
intType>
109 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
111 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
112 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
113 default:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
118 template<
typename ValueType,
typename... ValueCalculators>
119 struct MplxVC_getval_helper<4, ValueType, ValueCalculators...>
122 template<
typename Po
intType>
125 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
127 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
128 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
129 case 2:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
130 default:
return std::get<3>(_valcalcs).getValue(std::forward<PointType>(x));
135 template<
typename ValueType,
typename... ValueCalculators>
136 struct MplxVC_getval_helper<5, ValueType, ValueCalculators...>
139 template<
typename Po
intType>
142 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
144 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
145 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
146 case 2:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
147 case 3:
return std::get<3>(_valcalcs).getValue(std::forward<PointType>(x));
148 default:
return std::get<4>(_valcalcs).getValue(std::forward<PointType>(x));
153 template<
typename ValueType,
typename... ValueCalculators>
154 struct MplxVC_getval_helper<6, ValueType, ValueCalculators...>
157 template<
typename Po
intType>
160 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
162 case 0:
return std::get<0>(_valcalcs).getValue(std::forward<PointType>(x));
163 case 1:
return std::get<1>(_valcalcs).getValue(std::forward<PointType>(x));
164 case 2:
return std::get<2>(_valcalcs).getValue(std::forward<PointType>(x));
165 case 3:
return std::get<3>(_valcalcs).getValue(std::forward<PointType>(x));
166 case 4:
return std::get<4>(_valcalcs).getValue(std::forward<PointType>(x));
167 default:
return std::get<5>(_valcalcs).getValue(std::forward<PointType>(x));
184 template<
typename ValueType_,
typename... ValueCalculators>
189 typedef ValueType_ ValueType;
191 static constexpr
int NumValueCalculators =
sizeof...(ValueCalculators);
192 static constexpr
int NumStaticallyOptimizedIfs = 6;
212 template<
typename... Args>
214 : _valcalcs(
std::forward<Args>(valcalcs)...), _i(i)
220 inline const typename std::tuple_element<I, ValueCalculatorsTupleType>::type &
getValueCalculator()
const 222 return std::get<I>(_valcalcs);
226 template<
int I,
typename Po
intType>
229 return getValueCalculator<I>().getValue(std::forward<PointType>(x));
237 template<
typename Po
intType>
240 return tomo_internal::MplxVC_getval_helper<
241 NumValueCalculators,ValueType,ValueCalculators...
242 >::getValue(_i, _valcalcs, std::forward<PointType>(x));
A ValueCalculator-instance which the choice of which ValueCalculator to use at run-time.
Base namespace for the Tomographer project.
MultiplexorValueCalculator(const int i, Args &&... valcalcs)
Constructor.
ValueType getValue(PointType &&x) const
The main method which computes the value according to the pre-chosen ValueCalculator.
const std::tuple_element< I, ValueCalculatorsTupleType >::type & getValueCalculator() const
Get a particular value calculator [static index].
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
ValueType getValueI(PointType &&x) const
Calculate the value at the given point, using the I-th value calculator.
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) ...
#define tomographer_assert(...)
Assertion test macro.