Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::dispatching Namespace Reference

Namespaces

namespace  filter
 

Classes

class  DispatchException
 

Functions

template<typename Result , template< class > class Predicate, typename Callable , typename... Args>
auto singleDispatch (DataFormatId format, Callable &&obj, Args &&... args) -> Result
 
template<typename Result , template< class > class Predicate1, template< class > class Predicate2, typename Callable , typename... Args>
auto doubleDispatch (DataFormatId format1, DataFormatId format2, Callable &&obj, Args &&... args) -> Result
 
template<typename Result , template< class > class Predicate1, template< class > class Predicate2, template< class > class Predicate3, typename Callable , typename... Args>
auto tripleDispatch (DataFormatId format1, DataFormatId format2, DataFormatId format3, Callable &&obj, Args &&... args) -> Result
 
template<typename Result , template< class > class Predicate, typename Callable , typename... Args>
auto dispatch (DataFormatId format, Callable &&obj, Args &&... args) -> Result
 

Detailed Description

dispatching

Function Documentation

◆ dispatch()

template<typename Result , template< class > class Predicate, typename Callable , typename... Args>
auto inviwo::dispatching::dispatch ( DataFormatId format,
Callable && obj,
Args &&... args ) -> Result

Same functionality as singleDispatch, but the callable is passed both the dispatch type and the return type as template arguments. And the dispatch type is passed as a DataFormat<T> where as singleDispatch passes T directly.

See also
singleDispatch

◆ doubleDispatch()

template<typename Result , template< class > class Predicate1, template< class > class Predicate2, typename Callable , typename... Args>
auto inviwo::dispatching::doubleDispatch ( DataFormatId format1,
DataFormatId format2,
Callable && obj,
Args &&... args ) -> Result

Function for dispatching on two DataFormats

Example

Add two VolumeRAMPrecisions with different runtime types

std::shared_ptr<VolumeRAMPrecision<double>> sum(const VolumeRAM& v1, const VolumeRAM& v2) {
auto sum = std::make_shared<VolumeRAMPrecision<double>>(v1.getDimensions());
v1.getDataFormat()->getId(), v2.getDataFormat()->getId(), [&]<typename T1, typename T2>() {
const auto& ram1 = static_cast<const VolumeRAMPrecision<T1>&>(v1);
const auto& ram2 = static_cast<const VolumeRAMPrecision<T2>&>(v2);
const auto data1 = ram1.getView();
const auto data2 = ram2.getView();
auto dest = sum->getView();
for (size_t i = 0; data1.size(); ++i) {
dest[i] = static_cast<double>(data1[i]) + static_cast<double>(data2[i]);
}
});
return sum;
}
Template Parameters
Resultthe return type of the lambda.
Predicate1a type that is used to filter the list of types to consider in the dispatching for the first format1. The dispatching::filter namespace have a few standard ones predefined.
Predicate2a type that is used to filter the list of types to consider in the dispatching for the second format2. The dispatching::filter namespace have a few standard ones predefined.
Parameters
format1ID if for the first dataformat to dispatch on
format2ID if for the second dataformat to dispatch on
objThis should be a callable with a generic call operator taking two template arguments T1 and T2 of the dispatch types. The callable will be called with the supplied arguments (args). For example []<typename T1, typename T2>() {}. T1 and T2 here will be, float, double, int, ... vec2, dvec2, etc.
argsAny arguments that should be passed on to the callable.
Exceptions
dispatching::DispatchExceptionin the case that the format is not in the list of formats after the filtering.

◆ singleDispatch()

template<typename Result , template< class > class Predicate, typename Callable , typename... Args>
auto inviwo::dispatching::singleDispatch ( DataFormatId format,
Callable && obj,
Args &&... args ) -> Result

Function for dispatching on a DataFormat

Example

Create a VolumeRAMPrecision<T> with the type of T given by the runtime dataFormatId.

std::shared_ptr<VolumeRAM> create(DataFormatId dataFormatId) {
return dispatching::singleDispatch<std::shared_ptr<VolumeRAM>, dispatching::filter::All>(
dataFormatId, []<typename T>() {
return std::make_shared<VolumeRAMPrecision<T>>(size3_t{128, 128, 128});
});
}
Template Parameters
Resultthe return type of the lambda.
Predicatea type that is used to filter the list of types to consider in the dispatching. The dispatching::filter namespace have a few standard ones predefined.
Parameters
formatID if for the dataformat to dispatch on
objThis should be a callable with a generic call operator taking a template argument T of the dispatch type. The callable will be called with the supplied arguments (args). For example []<typename T>() {}. T here will be, float, double, int, ... vec2, dvec2, etc.
argsAny arguments that should be passed on to the callable.
Exceptions
dispatching::DispatchExceptionin the case that the format is not in the list of formats after the filtering.

◆ tripleDispatch()

template<typename Result , template< class > class Predicate1, template< class > class Predicate2, template< class > class Predicate3, typename Callable , typename... Args>
auto inviwo::dispatching::tripleDispatch ( DataFormatId format1,
DataFormatId format2,
DataFormatId format3,
Callable && obj,
Args &&... args ) -> Result

Function for dispatching on three DataFormats

Example

Add two VolumeRAMPrecisions with different runtime types and a runtime result type

std::shared_ptr<VolumeRAM> sum(const VolumeRAM& v1, const VolumeRAM& v2, DataFormatId sumType) {
return dispatching::tripleDispatch<std::shared_ptr<VolumeRAM>, dispatching::filter::Scalars,
dispatching::filter::Scalars, dispatching::filter::Scalars>(
v1.getDataFormat()->getId(), v2.getDataFormat()->getId(), sumType,
[&]<typename T1, typename T2, typename T3>() {
auto sum = std::make_shared<VolumeRAMPrecision<T3>>(v1.getDimensions());
const auto& ram1 = static_cast<const VolumeRAMPrecision<T1>&>(v1);
const auto& ram2 = static_cast<const VolumeRAMPrecision<T2>&>(v2);
const auto data1 = ram1.getView();
const auto data2 = ram2.getView();
auto dest = sum->getView();
for (size_t i = 0; data1.size(); ++i) {
dest[i] = static_cast<T3>(data1[i]) + static_cast<T3>(data2[i]);
}
return sum;
});
}
Template Parameters
Resultthe return type of the lambda.
Predicate1a type that is used to filter the list of types to consider in the dispatching for the first format1. The dispatching::filter namespace have a few standard ones predefined.
Predicate2a type that is used to filter the list of types to consider in the dispatching for the second format2. The dispatching::filter namespace have a few standard ones predefined.
Predicate3a type that is used to filter the list of types to consider in the dispatching for the third format3. The dispatching::filter namespace have a few standard ones predefined.
Parameters
format1ID if for the first dataformat to dispatch on
format2ID if for the second dataformat to dispatch on
format3ID if for the third dataformat to dispatch on
objThis should be a callable with a generic call operator taking three template arguments T1, T2 and T3 of the dispatch types. The callable will be called with the supplied arguments (args). For example []<typename T1, typename T2, typename T3>() {}. T1 and T2 here will be, float, double, int, ... vec2, dvec2, etc.
argsAny arguments that should be passed on to the callable.
Exceptions
dispatching::DispatchExceptionin the case that the format is not in the list of formats after the filtering.