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 std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, 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 std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
76 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<IterI>(_valcalcs, x) ;
78 return getValue<PointType, IterI+1>(_i, _valcalcs, 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 std::array<
void*,
sizeof...(ValueCalculators)> & , 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 std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
99 return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalcs, 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 std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
110 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
112 case 0:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalcs, x) ;
113 default:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalcs, x) ;
118 template<
typename ValueType,
typename... ValueCalculators>
119 struct MplxVC_getval_helper<3, ValueType, ValueCalculators...>
122 template<
typename Po
intType>
123 static inline ValueType getValue(
const int _i,
const std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
125 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
127 case 0:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalcs, x) ;
128 case 1:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalcs, x) ;
129 default:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalcs, x) ;
134 template<
typename ValueType,
typename... ValueCalculators>
135 struct MplxVC_getval_helper<4, ValueType, ValueCalculators...>
138 template<
typename Po
intType>
139 static inline ValueType getValue(
const int _i,
const std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
141 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
143 case 0:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalcs, x) ;
144 case 1:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalcs, x) ;
145 case 2:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalcs, x) ;
146 default:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalcs, x) ;
151 template<
typename ValueType,
typename... ValueCalculators>
152 struct MplxVC_getval_helper<5, ValueType, ValueCalculators...>
155 template<
typename Po
intType>
156 static inline ValueType getValue(
const int _i,
const std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
158 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
160 case 0:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalcs, x) ;
161 case 1:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalcs, x) ;
162 case 2:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalcs, x) ;
163 case 3:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalcs, x) ;
164 default:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<4>(_valcalcs, x) ;
169 template<
typename ValueType,
typename... ValueCalculators>
170 struct MplxVC_getval_helper<6, ValueType, ValueCalculators...>
173 template<
typename Po
intType>
174 static inline ValueType getValue(
const int _i,
const std::array<
void*,
sizeof...(ValueCalculators)> & _valcalcs, PointType&& x)
176 tomographer_assert(_i >= 0 && _i < (
int)
sizeof...(ValueCalculators) &&
"i out of range");
178 case 0:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<0>(_valcalcs, x) ;
179 case 1:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<1>(_valcalcs, x) ;
180 case 2:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<2>(_valcalcs, x) ;
181 case 3:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<3>(_valcalcs, x) ;
182 case 4:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<4>(_valcalcs, x) ;
183 default:
return MplxVC_getval_helper_helper<ValueType,ValueCalculators...>::template callGetValue<5>(_valcalcs, x) ;
201 template<
typename ValueType_,
typename... ValueCalculators>
206 typedef ValueType_ ValueType;
208 static constexpr
int NumValueCalculators =
sizeof...(ValueCalculators);
209 static constexpr
int NumStaticallyOptimizedIfs = 6;
220 template<
int I = 0,
typename TupleCreators = void,
222 inline void _create_Ith_valcalc(
int i, TupleCreators && creators) {
224 _valcalcs[(
std::size_t)i] = (
void*)std::get<I>(creators)();
226 _create_Ith_valcalc<I+1>(i, std::forward<TupleCreators>(creators));
228 template<
int I = 0,
typename TupleCreators = void,
230 inline void _create_Ith_valcalc(
int , TupleCreators && ) { }
232 template<int I = 0, typename std::enable_if<(I<NumValueCalculators),bool>::type =
true>
233 inline void _delete_all() {
234 if (_valcalcs[I] != NULL) {
235 delete (
typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalcs[I];
239 template<int I = 0, typename std::enable_if<(I==NumValueCalculators),bool>::type =
true>
240 inline void _delete_all() { }
242 template<int I = 0, typename std::enable_if<(I<NumValueCalculators),bool>::type =
true>
243 inline void _create_Ith_copy(
int i,
const void * src) {
244 tomographer_assert( src != NULL &&
"Copy constructor invoked with invalid other object.") ;
246 typedef typename std::tuple_element<I, ValueCalculatorsTupleType>::type ValueCalculator;
247 _valcalcs[(
std::size_t)i] =
new ValueCalculator( *(
const ValueCalculator*)src ) ;
249 _create_Ith_copy<I+1>(i, src);
251 template<int I = 0, typename std::enable_if<(I==NumValueCalculators),bool>::type =
true>
252 inline void _create_Ith_copy(
int ,
const void * ) { }
267 template<
typename... CreatorFns>
271 _valcalcs.
fill(NULL);
289 : _valcalcs(x._valcalcs), _i(x._i)
291 x._valcalcs.
fill(NULL) ;
299 : _valcalcs(), _i(other._i)
301 _valcalcs.
fill(NULL) ;
302 _create_Ith_copy(_i, other._valcalcs[(
std::size_t)_i]);
307 inline const typename std::tuple_element<I, ValueCalculatorsTupleType>::type *
getValueCalculator()
const 309 return (
typename std::tuple_element<I, ValueCalculatorsTupleType>::type *) _valcalcs[I];
317 template<
typename Po
intType>
320 return tomo_internal::MplxVC_getval_helper<
321 NumValueCalculators,ValueType,ValueCalculators...
322 >::getValue(_i, _valcalcs, 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.
T forward_as_tuple(T... args)
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.
MultiplexorValueCalculator(MultiplexorValueCalculator &&x)
Move constructor.