From a24d0a7ab229b98aa4f4c3bc433486598bc32f20 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 8 Sep 2017 17:35:24 +1000 Subject: [PATCH] traits: rename id_t/id_traits to native_t/native_traits renaming for consistency both in this project and with cruft-gl. it's easier to perform this change if we push some more code into the object.hpp header so we don't need to talk about native_t too often. --- object.cpp | 39 +-------------------------------- object.hpp | 64 +++++++++++++++++++++++------------------------------- traits.hpp | 44 ++++++++++++++++++------------------- 3 files changed, 50 insertions(+), 97 deletions(-) diff --git a/object.cpp b/object.cpp index 1dbf9a2..e60713e 100644 --- a/object.cpp +++ b/object.cpp @@ -27,43 +27,6 @@ using cruft::vk::object; using cruft::vk::enumerated; -/////////////////////////////////////////////////////////////////////////////// -template -object::object (native_t _native): - m_native (_native) -{ - CHECK_NEQ (m_native, VK_NULL_HANDLE); -} - - -//----------------------------------------------------------------------------- -template -object::object (object &&rhs): - m_native (VK_NULL_HANDLE) -{ - std::swap (m_native, rhs.m_native); -} - - -//----------------------------------------------------------------------------- -template -const typename object::native_t& -object::native (void) const& -{ - return m_native; -} - - -//----------------------------------------------------------------------------- -template -typename object::native_t& -object::native (void) & -{ - return m_native; -} - - -//----------------------------------------------------------------------------- #define OBJECT(T) template struct cruft::vk::object; VK_TYPE_MAP (OBJECT) @@ -83,7 +46,7 @@ cruft::vk::enumerated::find (const instance &parent) { // allocate an array of handles and fetch them uint32_t found = expected; - typename T::native_t handles[expected]; + native_t handles[expected]; error::try_code (enum_traits::enumerate (parent.native (), &found, handles)); // return an collection of objects from the handles diff --git a/object.hpp b/object.hpp index d86d462..7d8d385 100644 --- a/object.hpp +++ b/object.hpp @@ -29,45 +29,42 @@ namespace cruft::vk { /// management. template struct object { - using native_t = id_t; + object (native_t _native): + m_native (_native) + { + CHECK_NEQ (m_native, VK_NULL_HANDLE); + } - object (native_t); - object (object&&); + object (object &&rhs): + m_native (VK_NULL_HANDLE) + { std::swap (m_native, rhs.m_native); } object (const object&) = delete; - const native_t& native (void) const&; - native_t& native (void) &; + const auto& native (void) const& { return m_native; } + auto& native (void)& { return m_native; } protected: - native_t m_native; + native_t m_native; }; template struct root : public object { - using native_t = typename object::native_t; - template root (Args &&...args): - object (make (std::forward (args)...)) + object ( + cruft::vk::error::try_query ( + life_traits::create, + std::forward (args)... + ) + ) { ; } ~root () { life_traits::destroy (this->native (), nullptr); } - - private: - template - static native_t - make (Args &&...args) - { - native_t id; - auto res = life_traits::create (std::forward (args)..., &id); - error::try_code (res); - return id; - } }; @@ -76,28 +73,22 @@ namespace cruft::vk { /// another object. template struct descendant : public object { - using native_t = typename object::native_t; - - template - descendant (Args &&...args): - object (make (std::forward (args)...)) + template + descendant (ParentT &parent, Args &&...args): + object ( + cruft::vk::error::try_query( + life_traits::create, + parent.native (), + std::forward (args)... + ) + ) { ; } + ~descendant () { life_traits::destroy (this->native (), nullptr); } - - private: - template - static - native_t make (Base &&base, Args &&...args) - { - native_t id; - auto res = life_traits::create (base.native (), std::forward (args)..., &id); - error::try_code (res); - return id; - } }; @@ -117,7 +108,6 @@ namespace cruft::vk { /// the parent object. template struct owned : public object { - using native_t = typename object::native_t; using owner_t = OwnerT; using object::object; diff --git a/traits.hpp b/traits.hpp index 858b6dc..c055dac 100644 --- a/traits.hpp +++ b/traits.hpp @@ -89,33 +89,33 @@ namespace cruft::vk { /////////////////////////////////////////////////////////////////////////// /// describes the native type that corresponds to a given vk-cruft type. - template struct id_traits { }; + template struct native_traits { }; //------------------------------------------------------------------------- - template <> struct id_traits { using type = VkInstance; }; - template <> struct id_traits { using type = VkPhysicalDevice; }; - template <> struct id_traits { using type = VkDevice; }; - template <> struct id_traits { using type = VkQueue; }; - template <> struct id_traits { using type = VkCommandPool; }; - template <> struct id_traits { using type = VkCommandBuffer; }; - template <> struct id_traits { using type = VkFence; }; - template <> struct id_traits { using type = VkSemaphore; }; - template <> struct id_traits { using type = VkEvent; }; - template <> struct id_traits { using type = VkRenderPass; }; - template <> struct id_traits { using type = VkFramebuffer; }; - template <> struct id_traits { using type = VkShaderModule; }; - template <> struct id_traits { using type = VkPipeline; }; - template <> struct id_traits { using type = VkPipelineCache; }; - template <> struct id_traits { using type = VkDeviceMemory; }; - template <> struct id_traits { using type = VkBuffer; }; - template <> struct id_traits { using type = VkBufferView; }; - template <> struct id_traits { using type = VkSurfaceKHR; }; + template <> struct native_traits { using type = VkInstance; }; + template <> struct native_traits { using type = VkPhysicalDevice; }; + template <> struct native_traits { using type = VkDevice; }; + template <> struct native_traits { using type = VkQueue; }; + template <> struct native_traits { using type = VkCommandPool; }; + template <> struct native_traits { using type = VkCommandBuffer; }; + template <> struct native_traits { using type = VkFence; }; + template <> struct native_traits { using type = VkSemaphore; }; + template <> struct native_traits { using type = VkEvent; }; + template <> struct native_traits { using type = VkRenderPass; }; + template <> struct native_traits { using type = VkFramebuffer; }; + template <> struct native_traits { using type = VkShaderModule; }; + template <> struct native_traits { using type = VkPipeline; }; + template <> struct native_traits { using type = VkPipelineCache; }; + template <> struct native_traits { using type = VkDeviceMemory; }; + template <> struct native_traits { using type = VkBuffer; }; + template <> struct native_traits { using type = VkBufferView; }; + template <> struct native_traits { using type = VkSurfaceKHR; }; //------------------------------------------------------------------------- template - using id_t = typename id_traits::type; + using native_t = typename native_traits::type; /////////////////////////////////////////////////////////////////////////// @@ -203,8 +203,8 @@ namespace cruft::vk { static constexpr auto& create = vkGetDeviceQueue; static constexpr auto destroy = ::util::tuple::ignore< - id_t>, - id_t, + native_t>, + native_t, const VkAllocationCallbacks* >; };