82 lines
2.0 KiB
C++
82 lines
2.0 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>
|
||
|
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>
|
||
|
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>
|
||
|
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>
|
||
|
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()));
|
||
|
}
|