28 #ifndef TOMOGRAPHER_VALUECALCULATOR_H 29 #define TOMOGRAPHER_VALUECALCULATOR_H 49 namespace tomo_internal {
54 template<
typename ValueType,
typename... ValueCalculators>
55 struct MplxVC_getval_helper_helper
57 template<
int I,
typename Po
intType>
58 static inline ValueType callGetValue(
const void * valcalc, PointType && x)
61 -> getValue(std::forward<PointType>(x));
68 template<
int NumValueCalculators,
typename ValueType,
typename... ValueCalculators>
69 struct MplxVC_getval_helper
71 template<
typename PointType,
int IterI = 0,
72 TOMOGRAPHER_ENABLED_IF_TMPL(IterI < NumValueCalculators)>
73 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
76 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<IterI>(_valcalc, x) ;
78 return getValue<PointType, IterI+1>(_i, _valcalc, std::forward<PointType>(x));
81 template<
typename PointType,
int IterI = 0,
82 TOMOGRAPHER_ENABLED_IF_TMPL(IterI == NumValueCalculators)>
83 static inline ValueType getValue(
const int,
const void * , PointType&& )
91 template<
typename ValueType,
typename... ValueCalculators>
92 struct MplxVC_getval_helper<1, ValueType, ValueCalculators...>
95 template<
typename Po
intType>
96 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
99 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
103 template<
typename ValueType,
typename... ValueCalculators>
104 struct MplxVC_getval_helper<2, ValueType, ValueCalculators...>
107 template<
typename Po
intType>
108 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
110 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
113 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
115 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
120 template<
typename ValueType,
typename... ValueCalculators>
121 struct MplxVC_getval_helper<3, ValueType, ValueCalculators...>
124 template<
typename Po
intType>
125 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
127 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
130 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
132 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
134 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
139 template<
typename ValueType,
typename... ValueCalculators>
140 struct MplxVC_getval_helper<4, ValueType, ValueCalculators...>
143 template<
typename Po
intType>
144 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
146 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
149 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
151 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
153 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
155 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalc, x) ;
160 template<
typename ValueType,
typename... ValueCalculators>
161 struct MplxVC_getval_helper<5, ValueType, ValueCalculators...>
164 template<
typename Po
intType>
165 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
167 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
170 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
172 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
174 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
176 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalc, x) ;
178 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<4>(_valcalc, x) ;
183 template<
typename ValueType,
typename... ValueCalculators>
184 struct MplxVC_getval_helper<6, ValueType, ValueCalculators...>
187 template<
typename Po
intType>
188 static inline ValueType getValue(
const int _i,
const void * _valcalc, PointType&& x)
190 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
193 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
195 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
197 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
199 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalc, x) ;
201 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<4>(_valcalc, x) ;
203 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<5>(_valcalc, x) ;
221 template<
typename ValueType_,
typename... ValueCalculators>
226 typedef ValueType_ ValueType;
228 static constexpr
int NumValueCalculators =
sizeof...(ValueCalculators);
229 static constexpr
int NumStaticallyOptimizedIfs = 6;
236 const void * _valcalc;
239 template<
typename TupleCreators>
240 static inline const void * _create_Ith_valcalc(
int i, TupleCreators && creators)
244 return _create_Ith_valcalc_a(i, std::forward<TupleCreators>(creators));
247 template<
int I = 0,
typename TupleCreators = void,
249 static inline const void * _create_Ith_valcalc_a(
int i, TupleCreators && creators)
252 return (
const void *) std::get<I>(creators)();
254 return _create_Ith_valcalc_a<I+1>(i, std::forward<TupleCreators>(creators));
256 template<
int I = 0,
typename TupleCreators = void,
258 static inline const void * _create_Ith_valcalc_a(
int , TupleCreators && ) {
return NULL; }
261 template<int I = 0, typename std::enable_if<(I<NumValueCalculators),bool>::type =
true>
262 inline void _delete_all()
264 if (_i == I && _valcalc != NULL) {
265 delete (
const typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalc;
269 template<int I = 0, typename std::enable_if<(I==NumValueCalculators),bool>::type =
true>
270 inline void _delete_all() { }
273 static inline const void * _create_Ith_copy(
int i,
const void * src)
277 tomographer_assert( src != NULL &&
"Copy constructor invoked with invalid other object." ) ;
279 return _create_Ith_copy_a<0>(i, src);
282 template<
int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I<NumValueCalculators)>
283 inline static const
void * _create_Ith_copy_a(
int i, const
void * src) {
285 typedef
typename std::tuple_element<I, ValueCalculatorsTupleType>::type ValueCalculator;
286 return new ValueCalculator( *(const ValueCalculator*)src ) ;
288 return _create_Ith_copy_a<I+1>(i, src);
290 template<
int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I==NumValueCalculators)>
291 inline static const void * _create_Ith_copy_a(
int ,
const void * ) {
return NULL; }
306 template<
typename... CreatorFns>
308 : _valcalc(_create_Ith_valcalc(i,
std::forward_as_tuple(creators...))), _i(i)
327 : _valcalc(_create_Ith_copy(other._i, other._valcalc)), _i(other._i)
333 inline const typename std::tuple_element<I, ValueCalculatorsTupleType>::type *
getValueCalculator()
const 338 return (
const typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalc;
346 template<
typename Po
intType>
349 return tomo_internal::MplxVC_getval_helper<
350 NumValueCalculators,ValueType,ValueCalculators...
351 >::getValue(_i, _valcalc, std::forward<PointType>(x));
A ValueCalculator-instance which the choice of which ValueCalculator to use at run-time.
MultiplexorValueCalculator(const int i, CreatorFns &&... creators)
Constructor.
Base namespace for the Tomographer project.
ValueType getValue(PointType &&x) const
The main method which computes the value according to the pre-chosen ValueCalculator.
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
MultiplexorValueCalculator(const MultiplexorValueCalculator &other)
Copy constructor.
const std::tuple_element< I, ValueCalculatorsTupleType >::type * getValueCalculator() const
Get a particular value calculator [static index].
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()
Destructor. Frees resources.
#define tomographer_assert(...)
Assertion test macro.