From 3e3c16a0a17f4e3eadcbabd2a118ee978529498b Mon Sep 17 00:00:00 2001 From: Markus Tavenrath Date: Fri, 4 Nov 2016 09:14:53 +0100 Subject: [PATCH] Add constructor to Optional which accepts a RefType* in addition RefType& and nullptr. This is required since *nullptr is illegal and writing (ptr == nullptr) ? nullptr : *ptr isn't an efficient solution for the problem. (#45) --- VulkanHppGenerator.cpp | 75 +++++++++++++++++++++--------------------- vulkan/vulkan.hpp | 2 ++ 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 5652d8d..ed60728 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -136,11 +136,11 @@ const std::string flagsHeader( " return !m_mask;\n" " }\n" "\n" -" Flags operator~() const\n" -" {\n" -" Flags result(*this);\n" -" result.m_mask ^= FlagTraits::allFlags;\n" -" return result;\n" +" Flags operator~() const\n" +" {\n" +" Flags result(*this);\n" +" result.m_mask ^= FlagTraits::allFlags;\n" +" return result;\n" " }\n" "\n" " bool operator==(Flags const& rhs) const\n" @@ -187,23 +187,24 @@ const std::string flagsHeader( "\n" ); -std::string const optionalClassHeader = ( - " template \n" - " class Optional\n" - " {\n" - " public:\n" - " Optional(RefType & reference) { m_ptr = &reference; }\n" - " Optional(std::nullptr_t) { m_ptr = nullptr; }\n" - "\n" - " operator RefType*() const { return m_ptr; }\n" - " RefType const* operator->() const { return m_ptr; }\n" - " explicit operator bool() const { return !!m_ptr; }\n" - "\n" - " private:\n" - " RefType *m_ptr;\n" - " };\n" - "\n" -); +std::string const optionalClassHeader = R"( + template + class Optional + { + public: + Optional(RefType & reference) { m_ptr = &reference; } + Optional(RefType * ptr) { m_ptr = ptr; } + Optional(std::nullptr_t) { m_ptr = nullptr; } + + operator RefType*() const { return m_ptr; } + RefType const* operator->() const { return m_ptr; } + explicit operator bool() const { return !!m_ptr; } + + private: + RefType *m_ptr; + }; + +)"; std::string const arrayProxyHeader = ( "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE\n" @@ -2680,21 +2681,21 @@ void writeTypeFlags(std::ofstream & ofs, DependencyData const& dependencyData, F << " return ~( " << dependencyData.name << "( bits ) );" << std::endl << " }" << std::endl << std::endl - << " template <> struct FlagTraits<" << *dependencyData.dependencies.begin() << ">" << std::endl - << " {" << std::endl - << " enum" << std::endl - << " {" << std::endl - << " allFlags = "; - for (size_t i = 0; i < enumData->second.members.size(); i++) - { - if (i != 0) - { - ofs << " | "; - } - ofs << "VkFlags(" << *dependencyData.dependencies.begin() << "::" << enumData->second.members[i].name << ")"; - } - ofs << std::endl - << " };" << std::endl + << " template <> struct FlagTraits<" << *dependencyData.dependencies.begin() << ">" << std::endl + << " {" << std::endl + << " enum" << std::endl + << " {" << std::endl + << " allFlags = "; + for (size_t i = 0; i < enumData->second.members.size(); i++) + { + if (i != 0) + { + ofs << " | "; + } + ofs << "VkFlags(" << *dependencyData.dependencies.begin() << "::" << enumData->second.members[i].name << ")"; + } + ofs << std::endl + << " };" << std::endl << " };" << std::endl; } leaveProtect(ofs, flagData.protect); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index dcb0b61..159f36e 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -208,11 +208,13 @@ namespace vk return flags ^ bit; } + template class Optional { public: Optional(RefType & reference) { m_ptr = &reference; } + Optional(RefType * ptr) { m_ptr = ptr; } Optional(std::nullptr_t) { m_ptr = nullptr; } operator RefType*() const { return m_ptr; }