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));
63 template<
int I,
typename Po
intType>
64 static inline ValueType callGetValue(
void * valcalc, PointType && x)
67 -> getValue(std::forward<PointType>(x));
74 template<
int NumValueCalculators,
typename ValueType,
typename... ValueCalculators>
75 struct MplxVC_getval_helper
77 template<
typename PointType,
typename VoidPtr,
78 int IterI = 0, TOMOGRAPHER_ENABLED_IF_TMPL(IterI < NumValueCalculators)>
79 static inline ValueType getValue(
const int _i, VoidPtr _valcalc, PointType&& x)
82 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<IterI>(_valcalc, x) ;
84 return getValue<PointType, VoidPtr, IterI+1>(_i, _valcalc, std::forward<PointType>(x));
87 template<
typename PointType,
typename VoidPtr,
88 int IterI = 0, TOMOGRAPHER_ENABLED_IF_TMPL(IterI == NumValueCalculators)>
89 static inline ValueType getValue(
const int, VoidPtr, PointType&& )
97 template<
typename ValueType,
typename... ValueCalculators>
98 struct MplxVC_getval_helper<1, ValueType, ValueCalculators...>
101 template<
typename Po
intType,
typename Vo
idPtr>
102 static inline ValueType getValue(
const int _i, VoidPtr _valcalc, PointType&& x)
105 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
109 template<
typename ValueType,
typename... ValueCalculators>
110 struct MplxVC_getval_helper<2, ValueType, ValueCalculators...>
113 template<
typename Po
intType,
typename Vo
idPtr>
114 static inline ValueType getValue(
const int _i, VoidPtr _valcalc, PointType&& x)
116 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
119 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
121 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
126 template<
typename ValueType,
typename... ValueCalculators>
127 struct MplxVC_getval_helper<3, ValueType, ValueCalculators...>
130 template<
typename Po
intType,
typename Vo
idPtr>
131 static inline ValueType getValue(
const int _i, VoidPtr _valcalc, PointType&& x)
133 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
136 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
138 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
140 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
145 template<
typename ValueType,
typename... ValueCalculators>
146 struct MplxVC_getval_helper<4, ValueType, ValueCalculators...>
149 template<
typename Po
intType,
typename Vo
idPtr>
150 static inline ValueType getValue(
const int _i, VoidPtr _valcalc, PointType&& x)
152 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
155 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
157 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
159 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
161 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalc, x) ;
166 template<
typename ValueType,
typename... ValueCalculators>
167 struct MplxVC_getval_helper<5, ValueType, ValueCalculators...>
170 template<
typename Po
intType,
typename Vo
idPtr>
171 static inline ValueType getValue(
const int _i, VoidPtr _valcalc, PointType&& x)
173 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
176 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
178 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
180 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
182 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalc, x) ;
184 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<4>(_valcalc, x) ;
189 template<
typename ValueType,
typename... ValueCalculators>
190 struct MplxVC_getval_helper<6, ValueType, ValueCalculators...>
193 template<
typename Po
intType,
typename Vo
idPtr>
194 static inline ValueType getValue(
const int _i, VoidPtr * _valcalc, PointType&& x)
196 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
199 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalc, x) ;
201 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalc, x) ;
203 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalc, x) ;
205 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalc, x) ;
207 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<4>(_valcalc, x) ;
209 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<5>(_valcalc, x) ;
275 template<
typename ValueType_,
typename... ValueCalculators>
284 static constexpr
int NumValueCalculators =
sizeof...(ValueCalculators);
293 static constexpr
int NumStaticallyOptimizedIfs = 6;
301 void *
const _valcalc;
308 template<
typename TupleCreators>
309 static inline void * _create_Ith_valcalc(
int i, TupleCreators && creators)
313 return _create_Ith_valcalc_a(i, std::forward<TupleCreators>(creators));
316 template<
int I = 0,
typename TupleCreators = void,
318 static inline void * _create_Ith_valcalc_a(
int i, TupleCreators && creators)
321 typename std::tuple_element<I, ValueCalculatorsTupleType>::type * valcalc =
322 std::get<I>(creators)();
323 return (
void *) valcalc;
325 return _create_Ith_valcalc_a<I+1>(i, std::forward<TupleCreators>(creators));
327 template<
int I = 0,
typename TupleCreators = void,
329 static inline void * _create_Ith_valcalc_a(
int , TupleCreators && ) {
return NULL; }
332 template<int I = 0, typename std::enable_if<(I<NumValueCalculators),bool>::type =
true>
333 inline void _delete_all()
335 if (_i == I && _valcalc != NULL) {
336 delete (
typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalc;
340 template<int I = 0, typename std::enable_if<(I==NumValueCalculators),bool>::type =
true>
341 inline void _delete_all() { }
344 static inline void * _create_Ith_copy(
int i,
void * src)
348 tomographer_assert( src != NULL &&
"Copy constructor invoked with invalid other object." ) ;
350 return _create_Ith_copy_a<0>(i, src);
353 template<
int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I<NumValueCalculators)>
354 inline static
void * _create_Ith_copy_a(
int i,
void * src) {
356 typedef
typename std::tuple_element<I, ValueCalculatorsTupleType>::type ValueCalculator;
357 return new ValueCalculator( *(const ValueCalculator*)src ) ;
359 return _create_Ith_copy_a<I+1>(i, src);
361 template<
int I = 0, TOMOGRAPHER_ENABLED_IF_TMPL(I==NumValueCalculators)>
362 inline static void * _create_Ith_copy_a(
int ,
void * ) {
return NULL; }
378 template<
typename... CreatorFns>
380 : _valcalc(_create_Ith_valcalc(i,
std::forward_as_tuple(creators...))), _i(i)
399 : _valcalc(_create_Ith_copy(other._i, other._valcalc)), _i(other._i)
409 inline const typename std::tuple_element<I, ValueCalculatorsTupleType>::type *
getValueCalculator()
const 414 return (
const typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalc;
428 return (
typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalc;
437 template<
typename Po
intType>
440 return tomo_internal::MplxVC_getval_helper<
441 NumValueCalculators,ValueType,ValueCalculators...
442 >::getValue(_i, (
const void*)_valcalc, std::forward<PointType>(x));
451 template<
typename Po
intType>
454 return tomo_internal::MplxVC_getval_helper<
455 NumValueCalculators,ValueType,ValueCalculators...
456 >::getValue(_i, _valcalc, std::forward<PointType>(x));
A ValueCalculator implementation which the choice of which ValueCalculator to use at run-time...
ValueType_ ValueType
Value type returned by getValue() (see ValueCalculator Interface)
MultiplexorValueCalculator(const int i, CreatorFns &&... creators)
Constructor.
Base namespace for the Tomographer project.
std::tuple_element< I, ValueCalculatorsTupleType >::type * getValueCalculator()
Get a particular value calculator [static index] (non-const)
ValueType getValue(PointType &&x)
The main method which computes the value according to the pre-chosen ValueCalculator (non-const versi...
ValueType getValue(PointType &&x) const
The main method which computes the value according to the pre-chosen ValueCalculator (const version) ...
#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] (const)
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.