traits: add native conversion functions
This commit is contained in:
parent
c3fc537774
commit
f4c3d1cba1
58
traits.hpp
58
traits.hpp
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user