mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #1425 from asuessenbach/bitmask
Templatized bitwise operators on FlagBits.
This commit is contained in:
commit
e8353b847f
@ -112,12 +112,6 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
template <typename EnumType, EnumType value>
|
||||
struct CppType
|
||||
{};
|
||||
|
||||
template <typename Type>
|
||||
struct isVulkanHandleType
|
||||
{
|
||||
static VULKAN_HPP_CONST_OR_CONSTEXPR bool value = false;
|
||||
};
|
||||
${enums}
|
||||
${indexTypeTraits}
|
||||
${bitmasks}} // namespace VULKAN_HPP_NAMESPACE
|
||||
@ -2099,49 +2093,15 @@ std::string VulkanHppGenerator::generateBitmask( std::map<std::string, BitmaskDa
|
||||
|
||||
std::string bitmaskName = stripPrefix( bitmaskIt->first, "Vk" );
|
||||
std::string enumName = stripPrefix( bitmaskBitsIt->first, "Vk" );
|
||||
std::string alias = bitmaskIt->second.alias.empty() ? "" : ( " using " + stripPrefix( bitmaskIt->second.alias, "Vk" ) + " = " + bitmaskName + ";\n" );
|
||||
|
||||
// each Flags class is using the class 'Flags' with the corresponding FlagBits enum as the template parameter
|
||||
std::string str = "\n using " + bitmaskName + " = Flags<" + enumName + ">;\n";
|
||||
|
||||
std::string alias = bitmaskIt->second.alias.empty() ? "" : ( "\n using " + stripPrefix( bitmaskIt->second.alias, "Vk" ) + " = " + bitmaskName + ";\n" );
|
||||
|
||||
std::string allFlags;
|
||||
if ( bitmaskBitsIt->second.values.empty() )
|
||||
{
|
||||
str += alias;
|
||||
allFlags = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
static const std::string bitmaskTemplate = R"(
|
||||
template <> struct FlagTraits<${enumName}>
|
||||
{
|
||||
enum : ${bitmaskType}
|
||||
{
|
||||
allFlags = ${allFlags}
|
||||
};
|
||||
};
|
||||
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR ${bitmaskName} operator|( ${enumName} bit0, ${enumName} bit1 ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ${bitmaskName}( bit0 ) | bit1;
|
||||
}
|
||||
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR ${bitmaskName} operator&( ${enumName} bit0, ${enumName} bit1 ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ${bitmaskName}( bit0 ) & bit1;
|
||||
}
|
||||
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR ${bitmaskName} operator^( ${enumName} bit0, ${enumName} bit1 ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ${bitmaskName}( bit0 ) ^ bit1;
|
||||
}
|
||||
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR ${bitmaskName} operator~( ${enumName} bits ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ~( ${bitmaskName}( bits ) );
|
||||
}
|
||||
${alias})";
|
||||
|
||||
std::string allFlags;
|
||||
bool encounteredFlag = false;
|
||||
std::string previousEnter, previousLeave;
|
||||
for ( auto const & value : bitmaskBitsIt->second.values )
|
||||
@ -2168,13 +2128,24 @@ ${alias})";
|
||||
previousLeave.resize( previousLeave.size() - strlen( "\n" ) );
|
||||
allFlags += "\n" + previousLeave;
|
||||
}
|
||||
|
||||
str += replaceWithMap(
|
||||
bitmaskTemplate,
|
||||
{ { "alias", alias }, { "allFlags", allFlags }, { "bitmaskName", bitmaskName }, { "bitmaskType", bitmaskIt->second.type }, { "enumName", enumName } } );
|
||||
}
|
||||
|
||||
return str;
|
||||
static const std::string bitmaskTemplate = R"(
|
||||
template <> struct FlagTraits<${enumName}>
|
||||
{
|
||||
static VULKAN_HPP_CONST_OR_CONSTEXPR bool isBitmask = true;
|
||||
|
||||
enum : ${bitmaskType}
|
||||
{
|
||||
allFlags = ${allFlags}
|
||||
};
|
||||
};
|
||||
using ${bitmaskName} = Flags<${enumName}>;
|
||||
${alias})";
|
||||
|
||||
return replaceWithMap(
|
||||
bitmaskTemplate,
|
||||
{ { "alias", alias }, { "allFlags", allFlags }, { "bitmaskName", bitmaskName }, { "bitmaskType", bitmaskIt->second.type }, { "enumName", enumName } } );
|
||||
}
|
||||
|
||||
std::string VulkanHppGenerator::generateBitmasks() const
|
||||
@ -5939,6 +5910,12 @@ std::string VulkanHppGenerator::generateHandles() const
|
||||
//===============
|
||||
//=== HANDLEs ===
|
||||
//===============
|
||||
|
||||
template <typename Type>
|
||||
struct isVulkanHandleType
|
||||
{
|
||||
static VULKAN_HPP_CONST_OR_CONSTEXPR bool value = false;
|
||||
};
|
||||
)";
|
||||
|
||||
std::set<std::string> listedHandles;
|
||||
|
@ -1,6 +1,8 @@
|
||||
template <typename FlagBitsType>
|
||||
struct FlagTraits
|
||||
{};
|
||||
{
|
||||
static VULKAN_HPP_CONST_OR_CONSTEXPR bool isBitmask = false;
|
||||
};
|
||||
|
||||
template <typename BitType>
|
||||
class Flags
|
||||
@ -182,3 +184,29 @@
|
||||
{
|
||||
return flags.operator^( bit );
|
||||
}
|
||||
|
||||
// bitwise operators on BitType
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator&(BitType lhs, BitType rhs) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return Flags<BitType>( lhs ) & rhs;
|
||||
}
|
||||
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator|(BitType lhs, BitType rhs) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return Flags<BitType>( lhs ) | rhs;
|
||||
}
|
||||
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator^(BitType lhs, BitType rhs) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return Flags<BitType>( lhs ) ^ rhs;
|
||||
}
|
||||
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator~( BitType bit ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ~( Flags<BitType>( bit ) );
|
||||
}
|
||||
|
||||
|
@ -377,6 +377,7 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
template <typename FlagBitsType>
|
||||
struct FlagTraits
|
||||
{
|
||||
static VULKAN_HPP_CONST_OR_CONSTEXPR bool isBitmask = false;
|
||||
};
|
||||
|
||||
template <typename BitType>
|
||||
@ -554,6 +555,31 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
return flags.operator^( bit );
|
||||
}
|
||||
|
||||
// bitwise operators on BitType
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator&( BitType lhs, BitType rhs ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return Flags<BitType>( lhs ) & rhs;
|
||||
}
|
||||
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator|( BitType lhs, BitType rhs ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return Flags<BitType>( lhs ) | rhs;
|
||||
}
|
||||
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator^( BitType lhs, BitType rhs ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return Flags<BitType>( lhs ) ^ rhs;
|
||||
}
|
||||
|
||||
template <typename BitType, typename std::enable_if<FlagTraits<BitType>::isBitmask, bool>::type = true>
|
||||
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR Flags<BitType> operator~( BitType bit ) VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ~( Flags<BitType>( bit ) );
|
||||
}
|
||||
|
||||
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE )
|
||||
template <typename T>
|
||||
class ArrayProxy
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1514,6 +1514,12 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
//=== HANDLEs ===
|
||||
//===============
|
||||
|
||||
template <typename Type>
|
||||
struct isVulkanHandleType
|
||||
{
|
||||
static VULKAN_HPP_CONST_OR_CONSTEXPR bool value = false;
|
||||
};
|
||||
|
||||
class SurfaceKHR
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user