Tomographer  v5.4
Tomographer C++ Framework Documentation
Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators > Class Template Reference

A ValueCalculator implementation which the choice of which ValueCalculator to use at run-time. More...

#include <tomographer/valuecalculator.h>

+ Inheritance diagram for Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >:
+ Collaboration diagram for Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >:

Public Types

typedef ValueType_ ValueType
 Value type returned by getValue() (see ValueCalculator Interface)
 
typedef std::tuple< ValueCalculators... > ValueCalculatorsTupleType
 

Public Member Functions

template<typename... CreatorFns>
 MultiplexorValueCalculator (const int i, CreatorFns &&... creators)
 Constructor. More...
 
 ~MultiplexorValueCalculator ()
 Destructor. Frees resources.
 
 MultiplexorValueCalculator (const MultiplexorValueCalculator &other)
 Copy constructor. More...
 
template<int I>
const std::tuple_element< I, ValueCalculatorsTupleType >::type * getValueCalculator () const
 Get a particular value calculator [static index] (const) More...
 
template<int I>
std::tuple_element< I, ValueCalculatorsTupleType >::type * getValueCalculator ()
 Get a particular value calculator [static index] (non-const) More...
 
template<typename PointType >
ValueType getValue (PointType &&x) const
 The main method which computes the value according to the pre-chosen ValueCalculator (const version) More...
 
template<typename PointType >
ValueType getValue (PointType &&x)
 The main method which computes the value according to the pre-chosen ValueCalculator (non-const version) More...
 

Static Public Attributes

static constexpr int NumValueCalculators = sizeof...(ValueCalculators)
 Number of ValueCalculators given as template parameters.
 
static constexpr int NumStaticallyOptimizedIfs = 6
 Internal implementation detail, don't use.
 

Detailed Description

template<typename ValueType_, typename... ValueCalculators>
class Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >

A ValueCalculator implementation which the choice of which ValueCalculator to use at run-time.

A MultiplexorValueCalculator is a proxy ValueCalculator (which you can use, e.g., in ValueHistogramMHRWStatsCollector), which allows you to choose one among several ValueCalculator types to use at runtime. The possible choices of ValueCalculator s has to be defined at compile-time as template parameters. The constructor of the MultiplexorValueCalculator takes as many "creator functions" as defined ValueCalculator types, and calls only the one which we'd like to use.

The choice of the ValueCalculator is fixed upon instantiation of the MultiplexorValueCalculator. I.e., once decided, the choice of which ValueCalculator to use cannot be changed.

Template Parameters
ValueTypethe ValueType returned by the MultiplexorValueCalculator's getValue(). All ValueCalculator s must have ValueTypes which can be implicitily converted to this type. (See ValueCalculator Interface)
ValueCalculators...The list of ValueCalculator types among which to choose at runtime.

For example, if you woule like to leave open at compile-time whether to use a TrDistToRefCalculator or a FidelityToRefCalculator, you could write something along the lines of:

TrDistToRefCalculator<...>,
FidelityToRefCalculator<...> >
MyValueCalculator;
...
// choose which value calculator to use at run-time
int which_value_calculator =
use_trace_distance ? 0 : 1; // 0 or 1 is index in the list of
// possible ValueCalculators
MyValueCalculator valcalc(
which_value_calculator,
[&]() { return new TrDistToRefCalculator<...>(...); }
[&]() { return new FidelityTORefCalculator<...>(...); }
) ;
...
Since
Changed in Tomographer 5.0: Design slightly different; not all value calculators are instantiated; Constructor now takes lambdas (or callables) which can create individual value calculators.
Changed in Tomographer 5.4: Now correctly handles both const and non-const calls to getValue()

Definition at line 276 of file valuecalculator.h.

Constructor & Destructor Documentation

§ MultiplexorValueCalculator() [1/2]

template<typename ValueType_ , typename... ValueCalculators>
template<typename... CreatorFns>
Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >::MultiplexorValueCalculator ( const int  i,
CreatorFns &&...  creators 
)
inline

Constructor.

The first parameter i selects which value calculator is applied, given as an index in the list of possible ValueCalculators (starting at zero, of course).

The creators... are a list of callables which are responsible for instantiating the required value calculator. Each callable should take no arguments and create a ValueCalculator of the corresponding type using the new operator. Only the callable corresponding to the chosen i will be called. The created ValueCalculator will be automatically deleted.

Definition at line 379 of file valuecalculator.h.

§ MultiplexorValueCalculator() [2/2]

template<typename ValueType_ , typename... ValueCalculators>
Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >::MultiplexorValueCalculator ( const MultiplexorValueCalculator< ValueType_, ValueCalculators > &  other)
inline

Copy constructor.

Create the corresponding valcalc using its copy constructor

Definition at line 398 of file valuecalculator.h.

Member Function Documentation

§ getValue() [1/2]

template<typename ValueType_ , typename... ValueCalculators>
template<typename PointType >
ValueType Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >::getValue ( PointType &&  x) const
inline

The main method which computes the value according to the pre-chosen ValueCalculator (const version)

Calculates the value according to the ValueCalculator instance which was chosen at constructor-time (via the index i).

Definition at line 438 of file valuecalculator.h.

§ getValue() [2/2]

template<typename ValueType_ , typename... ValueCalculators>
template<typename PointType >
ValueType Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >::getValue ( PointType &&  x)
inline

The main method which computes the value according to the pre-chosen ValueCalculator (non-const version)

Calculates the value according to the ValueCalculator instance which was chosen at constructor-time (via the index i).

Definition at line 452 of file valuecalculator.h.

§ getValueCalculator() [1/2]

template<typename ValueType_ , typename... ValueCalculators>
template<int I>
const std::tuple_element<I, ValueCalculatorsTupleType>::type* Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >::getValueCalculator ( ) const
inline

Get a particular value calculator [static index] (const)

Returns
The pointer to the corresponding ValueCalculator, or NULL if the run-time value calculactor chosen is not equal to I.

Definition at line 409 of file valuecalculator.h.

§ getValueCalculator() [2/2]

template<typename ValueType_ , typename... ValueCalculators>
template<int I>
std::tuple_element<I, ValueCalculatorsTupleType>::type* Tomographer::MultiplexorValueCalculator< ValueType_, ValueCalculators >::getValueCalculator ( )
inline

Get a particular value calculator [static index] (non-const)

Returns
The pointer to the corresponding ValueCalculator, or NULL if the run-time value calculactor chosen is not equal to I.

Definition at line 423 of file valuecalculator.h.


The documentation for this class was generated from the following file: