object: push enumerated::find into the header

This commit is contained in:
Danny Robson 2017-09-09 15:34:06 +10:00
parent b3274df3a9
commit 01ec49efe9
5 changed files with 12 additions and 29 deletions

View File

@ -24,9 +24,9 @@
namespace cruft::vk {
template <typename T> struct descendant;
template <typename T> struct enumerated;
template <typename T, typename O> struct owned;
template <typename SelfT> struct descendant;
template <typename SelfT, typename ParentT> struct enumerated;
template <typename SelfT, typename OwnerT> struct owned;
struct instance;
struct physical_device;

View File

@ -35,25 +35,3 @@ VK_TYPE_MAP (OBJECT)
#define DESCENDANT(T) template struct cruft::vk::descendant<cruft::vk::T>;
VK_DESCENDANT_TYPE_MAP (DESCENDANT)
///////////////////////////////////////////////////////////////////////////////
template <typename T>
std::vector<T>
cruft::vk::enumerated<T>::find (const instance &parent) {
// find the total number of objects
uint32_t expected = 0;
error::try_code (enum_traits<native_t<T>>::enumerate (parent.native (), &expected, nullptr));
// allocate an array of handles and fetch them
uint32_t found = expected;
native_t<T> handles[expected];
error::try_code (enum_traits<native_t<T>>::enumerate (parent.native (), &found, handles));
// return an collection of objects from the handles
return std::vector<T> (handles, handles + found);
}
//-----------------------------------------------------------------------------
#define ENUMERATED(T) template struct cruft::vk::enumerated<cruft::vk::T>;
VK_ENUMERATED_TYPE_MAP (ENUMERATED)

View File

@ -97,12 +97,17 @@ namespace cruft::vk {
///////////////////////////////////////////////////////////////////////////
/// a vulkan object that is obtained by listings from a parent object.
template <typename SelfT>
template <typename SelfT, typename ParentT>
struct enumerated : public object<SelfT> {
using object<SelfT>::object;
static std::vector<SelfT>
find (const instance &parent);
find (const ParentT &parent)
{
return error::try_handles<SelfT> (
enum_traits<native_t<SelfT>>::enumerate, parent.native ()
);
}
};

View File

@ -26,7 +26,7 @@
#include <string>
namespace cruft::vk {
struct physical_device : public enumerated<physical_device> {
struct physical_device : public enumerated<physical_device,instance> {
using enumerated::enumerated;
std::set<std::string> extensions (void) const;

View File

@ -297,7 +297,7 @@ namespace cruft::vk {
template <typename> struct enum_traits { };
template <> struct enum_traits<VkPhysicalDevice> {
static constexpr auto enumerate = vkEnumeratePhysicalDevices;
static constexpr auto &enumerate = vkEnumeratePhysicalDevices;
};
}