33#ifndef DART_COMMON_CASTABLE_HPP_
34#define DART_COMMON_CASTABLE_HPP_
38#define DART_STRING_TYPE(type_name) \
40 [[nodiscard]] static const std::string& getStaticType() \
42 static const std::string type = #type_name; \
46 [[nodiscard]] const std::string& getType() const override \
48 return getStaticType(); \
50 void _ANONYMOUS_FUNCTION_1()
56template <
typename Base>
69 template <
typename Derived>
70 [[nodiscard]]
bool is()
const;
74 template <
typename Derived>
75 [[nodiscard]]
const Derived*
as()
const;
79 template <
typename Derived>
80 [[nodiscard]] Derived*
as();
83 template <
typename Derived>
84 [[nodiscard]]
const Derived&
asRef()
const;
87 template <
typename Derived>
88 [[nodiscard]] Derived&
asRef();
92 [[nodiscard]]
const Base&
base()
const;
95 [[nodiscard]] Base&
base();
A CRTP base class that provides an interface for easily casting to the derived types.
Definition Castable.hpp:58
const Base & base() const
Casts to Base const-reference.
Definition Castable-impl.hpp:98
const Derived & asRef() const
Casts to reference of Derived if Base is its base class. UB otherwise.
Definition Castable-impl.hpp:81
bool is() const
Returns true if the types of this Base and the template parameter (a base class) are identical.
Definition Castable-impl.hpp:48
const Derived * as() const
Casts to pointer of Derived if Base is its base class.
Definition Castable-impl.hpp:65