Aikido
aikido::common::DynamicCastFactory< Factory, Pointer, BaseParameter, TypeList > Struct Template Reference

Call a template factory function based on runtime type of the first argument to a function. More...

#include <aikido/common/metaprogramming.hpp>

Detailed Description

template<template< class > class Factory, template< class > class Pointer, class BaseParameter, class TypeList>
struct aikido::common::DynamicCastFactory< Factory, Pointer, BaseParameter, TypeList >

Call a template factory function based on runtime type of the first argument to a function.

This class has a create function that takes a pointer to BaseParameter as its first parameter, optionally followed by arbitrary other parameters. If the runtime type of that argument is in TypeList, then it is cast to the Derived type and forwarded to the the template class Factory<Derived>::create function. Other parameters, and the return value of create, are perfectly forwarded. If the first argument is none of those types, then create returns nullptr.

RTTI is implemented by attempting to dynamic_cast the first parameter of create to each derived type in TypeList, in the order that they are specified in. This is a potentially expensive operation.

The Pointer<Derived> parameter is a template class that defines: (1) a pointer type Pointer<Derived>::type and (2) a corresponding dynamic_cast operator Pointer<T>::cast that attempts to cast a Pointer<BaseParameter>::type to a Pointer<Derived>>:type. The provided DynamicCastFactory_shared_ptr and DynamicCastFactory_raw_pointer classes implement this functionality for std::shared_ptr and raw pointers, respectively.

Template Parameters
Factoryfactory template class with a static create function
Pointerpointer type information
BaseParameterbase class
TypeListtype_list of subclasses of BaseParameter