DART 6.13.2
Loading...
Searching...
No Matches
dart::common::Castable< Base > Class Template Reference

A CRTP base class that provides an interface for easily casting to the derived types. More...

#include <Castable.hpp>

Public Member Functions

template<typename Derived >
bool is () const
 Returns true if the types of this Base and the template parameter (a base class) are identical.
 
template<typename Derived >
const Derived * as () const
 Casts to pointer of Derived if Base is its base class.
 
template<typename Derived >
Derived * as ()
 Casts to pointer of Derived if Base is its base class.
 
template<typename Derived >
const Derived & asRef () const
 Casts to reference of Derived if Base is its base class. UB otherwise.
 
template<typename Derived >
Derived & asRef ()
 Casts to reference of Derived if Base is its base class. UB otherwise.
 

Private Member Functions

const Base & base () const
 Casts to Base const-reference.
 
Base & base ()
 Casts to Base reference.
 

Detailed Description

template<typename Base>
class dart::common::Castable< Base >

A CRTP base class that provides an interface for easily casting to the derived types.

Member Function Documentation

◆ as() [1/2]

template<typename Base >
template<typename Derived >
Derived * dart::common::Castable< Base >::as ( )

Casts to pointer of Derived if Base is its base class.

Returns nullptr otherwise.

◆ as() [2/2]

template<typename Base >
template<typename Derived >
const Derived * dart::common::Castable< Base >::as ( ) const

Casts to pointer of Derived if Base is its base class.

Returns nullptr otherwise.

◆ asRef() [1/2]

template<typename Base >
template<typename Derived >
Derived & dart::common::Castable< Base >::asRef ( )

Casts to reference of Derived if Base is its base class. UB otherwise.

◆ asRef() [2/2]

template<typename Base >
template<typename Derived >
const Derived & dart::common::Castable< Base >::asRef ( ) const

Casts to reference of Derived if Base is its base class. UB otherwise.

◆ base() [1/2]

template<typename Base >
Base & dart::common::Castable< Base >::base ( )
private

Casts to Base reference.

◆ base() [2/2]

template<typename Base >
const Base & dart::common::Castable< Base >::base ( ) const
private

Casts to Base const-reference.

◆ is()

template<typename Base >
template<typename Derived >
bool dart::common::Castable< Base >::is ( ) const

Returns true if the types of this Base and the template parameter (a base class) are identical.

This function is a syntactic sugar, which is identical to: (getType() == ShapeType::getStaticType()).

Example code:

if (shape->is<Sphere>())
std::cout << "The shape type is sphere!\n";