| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <AnKi/Util/Assert.h>
- namespace anki
- {
- /// @addtogroup util_private
- /// @{
- template<typename T>
- struct ExtractType
- {
- using Type = T;
- };
- template<typename T>
- struct ExtractType<const T&>
- {
- using Type = T;
- };
- template<typename T>
- struct ExtractType<T&>
- {
- using Type = T;
- };
- template<typename T>
- struct ExtractType<const T*>
- {
- using Type = T;
- };
- template<typename T>
- struct ExtractType<T*>
- {
- using Type = T;
- };
- /// @}
- /// @addtogroup util_other
- /// @{
- /// Check if a class is of certain type.
- template<typename TTo, typename TFrom>
- inline Bool isa(const TFrom& c)
- {
- return TTo::classof(&c);
- }
- /// Check if a class is of certain type.
- template<typename TTo, typename TFrom>
- inline Bool isa(TFrom& c)
- {
- return TTo::classof(&c);
- }
- /// Check if a class is of certain type.
- template<typename TTo, typename TFrom>
- inline Bool isa(const TFrom* c)
- {
- return TTo::classof(c);
- }
- /// Check if a class is of certain type.
- template<typename TTo, typename TFrom>
- inline Bool isa(TFrom* c)
- {
- return TTo::classof(c);
- }
- /// Custom dynamic cast.
- template<typename TTo, typename TFrom>
- inline TTo dcast(TFrom& c)
- {
- ANKI_ASSERT(isa<typename ExtractType<TTo>::Type>(c));
- return static_cast<TTo>(c);
- }
- /// Custom dynamic cast.
- template<typename TTo, typename TFrom>
- inline TTo dcast(TFrom* c)
- {
- ANKI_ASSERT(isa<typename ExtractType<TTo>::Type>(c));
- return static_cast<TTo>(c);
- }
- /// @}
- } // end namespace anki
|