Inviwo  0.9.10.1
Inviwo documentation
inviwo::dispatching Namespace Reference

Namespaces

 filter
 

Classes

class  DispatchException
 

Functions

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

Function for dispatching a DataFormat based on the DataFormatId. The matching DataFormat is found using binary search in the type list.

Template arguments:

  • Result the return type of the lambda.
  • Predicate A 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.

Example

struct BufferRamCreationDispatcher {
template <typename Result, typename T>
Result operator()(size_t size, BufferUsage usage, BufferTarget target) {
using F = typename T::type;
switch (target) {
case BufferTarget::Index:
return std::make_shared<BufferRAMPrecision<F, BufferTarget::Index>>(size, usage);
case BufferTarget::Data:
default:
return std::make_shared<BufferRAMPrecision<F, BufferTarget::Data>>(size, usage);
}
}
};
std::shared_ptr<BufferRAM> createBufferRAM(size_t size, const DataFormatBase *format,
BufferUsage usage, BufferTarget target) {
BufferRamCreationDispatcher disp;
return dispatching::dispatch<std::shared_ptr<BufferRAM>, dispatching::filter::All>(
format->getId(), disp, size, usage, target);
}
Parameters
formatID if for the dataformat to dispatch on
objThis should be a struct with a generic call operator taking two template arguments the result type and DataFormat type. The callable will be called with the supplied arguments (args).
argsAny arguments that should be passed on to the lambda.
Exceptions
dispatching::DispatchExceptionin the case that the format of the buffer is not in the list of formats after the filtering.