Aikido
|
Call a template factory function based on runtime type of the first argument to a function. More...
#include <aikido/common/metaprogramming.hpp>
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.
Factory | factory template class with a static create function |
Pointer | pointer type information |
BaseParameter | base class |
TypeList | type_list of subclasses of BaseParameter |