1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 04:53:12 +01:00

Support casting back to TileElement

This commit is contained in:
Matt
2021-02-04 17:59:06 +02:00
parent 71174b8de7
commit 41c6c0bee3

View File

@@ -56,6 +56,7 @@ enum class TileElementType : uint8_t
Corrupt = (8 << 2),
};
struct TileElement;
struct SurfaceElement;
struct PathElement;
struct TrackElement;
@@ -102,11 +103,19 @@ struct TileElementBase
template<typename TType> const TType* as() const
{
return static_cast<TileElementType>(GetType()) == TType::ElementType ? reinterpret_cast<const TType*>(this) : nullptr;
if constexpr (std::is_same_v<TType, TileElement>)
return reinterpret_cast<const TileElement*>(this);
else
return static_cast<TileElementType>(GetType()) == TType::ElementType ? reinterpret_cast<const TType*>(this)
: nullptr;
}
template<typename TType> TType* as()
{
return static_cast<TileElementType>(GetType()) == TType::ElementType ? reinterpret_cast<TType*>(this) : nullptr;
if constexpr (std::is_same_v<TType, TileElement>)
return reinterpret_cast<TileElement*>(this);
else
return static_cast<TileElementType>(GetType()) == TType::ElementType ? reinterpret_cast<TType*>(this) : nullptr;
}
const SurfaceElement* AsSurface() const