traits: add native conversion functions

This commit is contained in:
Danny Robson 2017-09-14 02:13:17 +10:00
parent c3fc537774
commit f4c3d1cba1

View File

@ -112,11 +112,69 @@ namespace cruft::vk {
#undef IS_WRAPPER
//-------------------------------------------------------------------------
template <typename T>
struct is_wrapper<owned_ptr<T>> :
public is_wrapper<T>
{ };
//-------------------------------------------------------------------------
template <typename T>
static constexpr auto is_wrapper_v = is_wrapper<T>::value;
///////////////////////////////////////////////////////////////////////////
/// return the native value for the wrapper object
template <typename SelfT>
constexpr auto
native (const object<SelfT> &obj)
{
return obj.native ();
}
///------------------------------------------------------------------------
/// return the native handle as is; supplied for implementation convenience
/// in other higher order methods.
template <
typename NativeT,
typename = std::enable_if_t<is_native_v<NativeT>, void>
>
constexpr auto
native (NativeT val)
{
return val;
}
///------------------------------------------------------------------------
/// return the underlying native value by querying the data object (not the
/// owner object).
template <typename SelfT>
constexpr auto
native (const owned_ptr<SelfT> &ptr)
{
return native (ptr.get ());
}
///------------------------------------------------------------------------
/// try to return the vulkan native type if there is one, else return the
/// value we were given.
template <typename T, typename DecayT = std::decay_t<T>>
constexpr auto
maybe_native (T &&t)
{
if constexpr (is_wrapper_v<DecayT>)
return native (t);
else if constexpr (is_native_v<DecayT>)
return native (t);
else
return t;
}
///////////////////////////////////////////////////////////////////////////
/// describes the corresponding value for sType in native structures
template <typename>