except: split try_array into try_values/try_handles
sometimes we will need to coerce types from try_array into our own wrapper types and it is a little difficult to express the required types in the one template function.
This commit is contained in:
parent
d569113f8c
commit
b3274df3a9
43
except.hpp
43
except.hpp
@ -101,7 +101,38 @@ namespace cruft::vk {
|
|||||||
typename ...Args
|
typename ...Args
|
||||||
>
|
>
|
||||||
static auto
|
static auto
|
||||||
try_array (FuncT &&func, Args &&...args)
|
try_values (FuncT &&func, Args &&...args)
|
||||||
|
{
|
||||||
|
// extract the number of elements available
|
||||||
|
uint32_t expected = 0;
|
||||||
|
try_func (func, args..., &expected, nullptr);
|
||||||
|
|
||||||
|
// find the type of the last argument, ie. the values we're
|
||||||
|
// requesting
|
||||||
|
using ValueT = std::remove_pointer_t<
|
||||||
|
std::tuple_element_t<
|
||||||
|
sizeof...(Args) + 1,
|
||||||
|
typename func_traits<FuncT>::argument_types
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
|
||||||
|
ContainerT<ValueT> values (expected);
|
||||||
|
uint32_t found = expected;
|
||||||
|
try_func (func, args..., &found, values.data ());
|
||||||
|
CHECK_EQ (expected, found);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
template <
|
||||||
|
typename ReturnT,
|
||||||
|
template <typename,typename...> class ContainerT = std::vector,
|
||||||
|
typename FuncT,
|
||||||
|
typename ...Args
|
||||||
|
>
|
||||||
|
static auto
|
||||||
|
try_handles (FuncT &&func, Args &&...args)
|
||||||
{
|
{
|
||||||
// extract the number of elements available
|
// extract the number of elements available
|
||||||
uint32_t expected = 0;
|
uint32_t expected = 0;
|
||||||
@ -118,18 +149,15 @@ namespace cruft::vk {
|
|||||||
|
|
||||||
// return the values on the stack temporarily as we may need to
|
// return the values on the stack temporarily as we may need to
|
||||||
// convert them to a seperate result type.
|
// convert them to a seperate result type.
|
||||||
//
|
|
||||||
// TODO: remove this intermediate step where we don't actually
|
|
||||||
// have a conversion to do, ie ResultT == ValueT.
|
|
||||||
ValueT values[expected];
|
ValueT values[expected];
|
||||||
uint32_t found = expected;
|
uint32_t found = expected;
|
||||||
try_func (func, args..., &found, &values[0]);
|
try_func (func, args..., &found, &values[0]);
|
||||||
CHECK_EQ (expected, found);
|
CHECK_EQ (expected, found);
|
||||||
|
|
||||||
// convert to the requested type
|
// convert to the requested type
|
||||||
return ContainerT<ValueT> {
|
return ContainerT<ReturnT> {
|
||||||
&values[0],
|
values + 0,
|
||||||
&values[found]
|
values + found,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -161,4 +189,5 @@ namespace cruft::vk {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -84,7 +84,7 @@ physical_device::memory_properties (void) const
|
|||||||
std::vector<VkQueueFamilyProperties>
|
std::vector<VkQueueFamilyProperties>
|
||||||
physical_device::queue_families (void) const
|
physical_device::queue_families (void) const
|
||||||
{
|
{
|
||||||
return error::try_array (
|
return error::try_values (
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties, native ()
|
vkGetPhysicalDeviceQueueFamilyProperties, native ()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ physical_device::queue_families (void) const
|
|||||||
std::vector<VkSurfaceFormatKHR>
|
std::vector<VkSurfaceFormatKHR>
|
||||||
physical_device::surface_formats (surface &_surface)
|
physical_device::surface_formats (surface &_surface)
|
||||||
{
|
{
|
||||||
return error::try_array (
|
return error::try_values (
|
||||||
vkGetPhysicalDeviceSurfaceFormatsKHR,
|
vkGetPhysicalDeviceSurfaceFormatsKHR,
|
||||||
native (), _surface.native ()
|
native (), _surface.native ()
|
||||||
);
|
);
|
||||||
@ -105,7 +105,7 @@ physical_device::surface_formats (surface &_surface)
|
|||||||
std::vector<VkPresentModeKHR>
|
std::vector<VkPresentModeKHR>
|
||||||
physical_device::present_modes (surface &_surface)
|
physical_device::present_modes (surface &_surface)
|
||||||
{
|
{
|
||||||
return error::try_array (
|
return error::try_values (
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR,
|
vkGetPhysicalDeviceSurfacePresentModesKHR,
|
||||||
native (), _surface.native ()
|
native (), _surface.native ()
|
||||||
);
|
);
|
||||||
|
@ -254,7 +254,7 @@ main (void)
|
|||||||
cruft::vk::error::try_code (
|
cruft::vk::error::try_code (
|
||||||
vkGetSwapchainImagesKHR (ldevice.native (), swapchain, &swap_image_count, nullptr)
|
vkGetSwapchainImagesKHR (ldevice.native (), swapchain, &swap_image_count, nullptr)
|
||||||
);
|
);
|
||||||
std::vector<VkImage> swap_images = cruft::vk::error::try_array (
|
std::vector<VkImage> swap_images = cruft::vk::error::try_values (
|
||||||
vkGetSwapchainImagesKHR, ldevice.native (), swapchain
|
vkGetSwapchainImagesKHR, ldevice.native (), swapchain
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user