Support casting back to TileElement

This commit is contained in:
Matt 2021-02-04 17:59:06 +02:00
parent 71174b8de7
commit 41c6c0bee3
No known key found for this signature in database
GPG Key ID: 6D4C24A61C93E208
1 changed files with 11 additions and 2 deletions

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