AuroraRuntime/Include/auROXTL/auCastUtils.hpp
Reece be7e9271e6 [+] Added casts for pointer types
[*] Nuke more std:: references
2022-02-19 11:43:57 +00:00

106 lines
2.4 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auCastUtils.hpp
Date: 2022-2-10
Author: Reece
***/
#pragma once
template<class T, class Z>
T *AuStaticCast(Z *other)
{
return static_cast<T *>(other);
}
template<class T, class Z>
AuSPtr<T> AuStaticCast(const AuSPtr<Z> &other)
{
return AuSPtr<T>(other, static_cast<T *>(other.get()));
}
template<class T, class Z>
AuSPtr<T> AuStaticCast(AuSPtr<Z> &&other)
{
return AuSPtr<T>(AuMove(other), static_cast<T *>(other.get()));
}
template<class T, class Z>
T *AuConstCast(Z *other)
{
return const_cast<T *>(other);
}
template<class T, class Z>
AuSPtr<T> AuConstCast(const AuSPtr<Z> &other)
{
return AuSPtr<T>(other, const_cast<T *>(other.get()));
}
template<class T, class Z>
AuSPtr<T> AuConstCast(AuSPtr<Z> &&other)
{
return AuSPtr<T>(AuMove(other), const_cast<T *>(other.get()));
}
template<class T, class Z>
T *AuReinterpretCast(Z *other)
{
return reinterpret_cast<T *>(other);
}
template<class T, class Z>
AuSPtr<T> AuReinterpretCast(const AuSPtr<Z> &other)
{
return AuSPtr<T>(other, reinterpret_cast<T *>(other.get()));
}
template<class T, class Z>
AuSPtr<T> AuReinterpretCast(AuSPtr<Z> &&other)
{
return AuSPtr<T>(AuMove(other), reinterpret_cast<T *>(other.get()));
}
template<class T, class Z>
T *AuDynamicCast(Z *other)
{
return dynamic_cast<T *>(other);
}
template<class T, class Z>
AuSPtr<T> AuDynamicCast(const AuSPtr<Z> &other)
{
return AuSPtr<T>(other, dynamic_cast<T *>(other.get()));
}
template<class T, class Z>
AuSPtr<T> AuDynamicCast(AuSPtr<Z> &&other)
{
return AuSPtr<T>(AuMove(other), dynamic_cast<T *>(other.get()));
}
template<typename T, typename Z>
AuOptional<AuSPtr<T>> AuOptionalSharedDynamicCast(AuOptional<AuSPtr<Z>> &in)
{
if (!in.has_value()) return {};
return AuDynamicCast<T>(in.value());
}
template<typename T, typename Z>
AuOptional<AuSPtr<T>> AuOptionalSharedStaticCast(AuOptional<AuSPtr<Z>> &in)
{
if (!in.has_value()) return {};
return AuStaticPointerCast<T>(in.value());
}
template<class T, class T2>
AuSPtr<T> AuStaticPointerCast(const AuSPtr<T2> &other) noexcept
{
return AuSPtr<T>(other, static_cast<typename AuSPtr<T>::element_type *>(other.get()));
}
template<class T, class T2>
AuSPtr<T> AuStaticPointerCast(AuSPtr<T2> &&other) noexcept
{
return AuSPtr<T>(AuMove(other), static_cast<typename AuSPtr<T>::element_type *>(other.get()));
}