Template Class Convertible

Class Documentation

template<typename BaseType, typename ...DerivedTypes>
class Convertible

Base class for a type that may be converted to its derived types via As<>()

Param <BaseType>

The type of object that will expose conversion to its derived types via As<>()

Param <DerivedTypes>

The types that an object of BaseType may be converted to

Public Functions

inline virtual ~Convertible() = 0

Destroys this instance of Convertible.

inline virtual TypeId GetTypeId() const

Gets this Convertible's TypeId.

Returns

This Convertible's TypeId

template<typename DerivedType>
inline DerivedType const *As() const

Converts this object to one of its derived types.

Note

This method will return nullptr if this object's GetType() doesn't match that of the requested derived type's

Parameters

<DerivedType> -- The derived type to convert this object to

Returns

A pointer to this object as the given DerivedType

template<typename DerivedType>
inline DerivedType *As()

Converts this object to one of its derived types.

Note

This method will return nullptr if this object's GetType() doesn't match that of the requested derived type's

Parameters

<DerivedType> -- The derived type to convert this object to

Returns

A pointer to this object as the given DerivedType

template<typename DerivedType, typename ProcessAsFunctionType>
inline bool ProcessAs(ProcessAsFunctionType processAsFunction) const

Executes a given function with this object as a given derived type.

Note

The given function's signature must be compatible with void(DerivedType const&)

Note

If the conversion to the given DerivedType is unsuccessful the given function will not be called

Parameters
  • <DerivedType> -- The derived type to convert this object to

  • <ProcessAsFunctionType> -- The type of function to call with this object as the given DerivedType

  • processAsFunction -- [in] The function to call with this object as the given DerivedType

Returns

Whether or not the conversion was successful

Public Static Functions

template<typename DerivedType>
static inline constexpr TypeId GetTypeId()

Gets the TypeId of a given type.

Note

The given type must have been specified in this Convertible<> type's DerivedTypes template parameter

Parameters

<DerivedType> -- The type to get the TypeId of

Returns

The TypeId of the given type