Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved some implementation details into namespace detail. #1840

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5669,17 +5669,15 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const

usings += exceptionsLeave + "\n";

// ResultValue
auto const hardCodedResultValueTypes = std::array{ "ignore", "ResultValue", "ResultValueType", "createResultValueType" };
for ( auto const & className : hardCodedResultValueTypes )
// some hardcoded types
auto const hardCodedResultValueTypes =
std::array{ "ResultValue", "ResultValueType", "detail::createResultValueType", "detail::ignore", "detail::resultCheck" };
for ( auto const & valueType : hardCodedResultValueTypes )
{
usings += replaceWithMap( usingTemplate, { { "className", className } } );
usings += replaceWithMap( usingTemplate, { { "className", valueType } } );
}

// resultCheck
usings += replaceWithMap( usingTemplate, { { "className", "resultCheck" } } ) + "\n";

usings += generateConstexprUsings() + "\n";
usings += "\n" + generateConstexprUsings() + "\n";

// structs, handles, UniqueHandles, etc
usings += generateCppModuleStructUsings();
Expand Down Expand Up @@ -9812,7 +9810,7 @@ std::string VulkanHppGenerator::generateResultCheck(
std::string successCodeList = generateSuccessCodeList( commandData.successCodes, enumerating );

std::string const resultCheckTemplate =
R"(resultCheck( result, VULKAN_HPP_NAMESPACE_STRING "::${className}${classSeparator}${commandName}"${successCodeList} );)";
R"(VULKAN_HPP_NAMESPACE::detail::resultCheck( result, VULKAN_HPP_NAMESPACE_STRING "::${className}${classSeparator}${commandName}"${successCodeList} );)";

resultCheck = replaceWithMap(
resultCheckTemplate,
Expand Down Expand Up @@ -9918,12 +9916,12 @@ std::string VulkanHppGenerator::generateReturnStatement( std::string const & com
if ( returnVariable.empty() )
{
assert( !unique );
returnStatement = "return createResultValueType( result );";
returnStatement = "return VULKAN_HPP_NAMESPACE::detail::createResultValueType( result );";
}
else if ( unique )
{
assert( returnParam != INVALID_INDEX );
returnStatement = "return createResultValueType( result, ";
returnStatement = "return VULKAN_HPP_NAMESPACE::detail::createResultValueType( result, ";
if ( dataType.starts_with( "std::" ) )
{
returnStatement += "std::move( unique" + startUpperCase( returnVariable ) + " )";
Expand All @@ -9938,7 +9936,7 @@ std::string VulkanHppGenerator::generateReturnStatement( std::string const & com
}
else
{
returnStatement = "return createResultValueType( result, std::move( " + returnVariable + " ) );";
returnStatement = "return VULKAN_HPP_NAMESPACE::detail::createResultValueType( result, std::move( " + returnVariable + " ) );";
}
}
}
Expand Down
46 changes: 26 additions & 20 deletions snippets/ResultValue.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
template <typename T> void ignore(T const &) VULKAN_HPP_NOEXCEPT {}

template <typename T>
struct ResultValue
{
Expand Down Expand Up @@ -107,33 +105,41 @@
#endif
};

VULKAN_HPP_INLINE typename ResultValueType<void>::type createResultValueType( Result result )
namespace detail
{
template <typename T>
void ignore( T const & ) VULKAN_HPP_NOEXCEPT
{
}

VULKAN_HPP_INLINE typename VULKAN_HPP_NAMESPACE::ResultValueType<void>::type createResultValueType( VULKAN_HPP_NAMESPACE::Result result )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
return result;
return result;
#else
ignore( result );
VULKAN_HPP_NAMESPACE::detail::ignore( result );
#endif
}
}

template <typename T>
VULKAN_HPP_INLINE typename ResultValueType<T>::type createResultValueType( Result result, T & data )
{
template <typename T>
VULKAN_HPP_INLINE typename VULKAN_HPP_NAMESPACE::ResultValueType<T>::type createResultValueType( VULKAN_HPP_NAMESPACE::Result result, T & data )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
return ResultValue<T>( result, data );
return ResultValue<T>( result, data );
#else
ignore( result );
return data;
VULKAN_HPP_NAMESPACE::detail::ignore( result );
return data;
#endif
}
}

template <typename T>
VULKAN_HPP_INLINE typename ResultValueType<T>::type createResultValueType( Result result, T && data )
{
template <typename T>
VULKAN_HPP_INLINE typename VULKAN_HPP_NAMESPACE::ResultValueType<T>::type createResultValueType( VULKAN_HPP_NAMESPACE::Result result, T && data )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
return ResultValue<T>( result, std::move( data ) );
return ResultValue<T>( result, std::move( data ) );
#else
ignore( result );
return std::move( data );
VULKAN_HPP_NAMESPACE::detail::ignore( result );
return std::move( data );
#endif
}
}
} // namespace detail
44 changes: 24 additions & 20 deletions snippets/resultChecks.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
VULKAN_HPP_INLINE void resultCheck( Result result, char const * message )

namespace detail
{
VULKAN_HPP_INLINE void resultCheck( Result result, char const * message )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
ignore( message );
VULKAN_HPP_ASSERT_ON_RESULT( result == Result::eSuccess );
VULKAN_HPP_NAMESPACE::detail::ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_NAMESPACE::detail::ignore( message );
VULKAN_HPP_ASSERT_ON_RESULT( result == Result::eSuccess );
#else
if ( result != Result::eSuccess )
{
detail::throwResultException( result, message );
}
if ( result != Result::eSuccess )
{
VULKAN_HPP_NAMESPACE::detail::throwResultException( result, message );
}
#endif
}
}

VULKAN_HPP_INLINE void resultCheck( Result result, char const * message, std::initializer_list<Result> successCodes )
{
VULKAN_HPP_INLINE void resultCheck( Result result, char const * message, std::initializer_list<Result> successCodes )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
ignore( message );
ignore( successCodes ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_ASSERT_ON_RESULT( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );
VULKAN_HPP_NAMESPACE::detail::ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_NAMESPACE::detail::ignore( message );
VULKAN_HPP_NAMESPACE::detail::ignore( successCodes ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_ASSERT_ON_RESULT( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );
#else
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
detail::throwResultException( result, message );
}
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
VULKAN_HPP_NAMESPACE::detail::throwResultException( result, message );
}
#endif
}
}
} // namespace detail
6 changes: 3 additions & 3 deletions vulkan/vulkan.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ export namespace VULKAN_HPP_NAMESPACE
using VULKAN_HPP_NAMESPACE::InvalidVideoStdParametersKHRError;
#endif /*VULKAN_HPP_NO_EXCEPTIONS*/

using VULKAN_HPP_NAMESPACE::createResultValueType;
using VULKAN_HPP_NAMESPACE::ignore;
using VULKAN_HPP_NAMESPACE::resultCheck;
using VULKAN_HPP_NAMESPACE::ResultValue;
using VULKAN_HPP_NAMESPACE::ResultValueType;
using VULKAN_HPP_NAMESPACE::detail::createResultValueType;
using VULKAN_HPP_NAMESPACE::detail::ignore;
using VULKAN_HPP_NAMESPACE::detail::resultCheck;

//===========================
//=== CONSTEXPR CONSTANTs ===
Expand Down
92 changes: 49 additions & 43 deletions vulkan/vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6601,11 +6601,6 @@ namespace VULKAN_HPP_NAMESPACE
} // namespace detail
#endif

template <typename T>
void ignore( T const & ) VULKAN_HPP_NOEXCEPT
{
}

template <typename T>
struct ResultValue
{
Expand Down Expand Up @@ -6718,65 +6713,76 @@ namespace VULKAN_HPP_NAMESPACE
#endif
};

VULKAN_HPP_INLINE typename ResultValueType<void>::type createResultValueType( Result result )
namespace detail
{
template <typename T>
void ignore( T const & ) VULKAN_HPP_NOEXCEPT
{
}

VULKAN_HPP_INLINE typename VULKAN_HPP_NAMESPACE::ResultValueType<void>::type createResultValueType( VULKAN_HPP_NAMESPACE::Result result )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
return result;
return result;
#else
ignore( result );
VULKAN_HPP_NAMESPACE::detail::ignore( result );
#endif
}
}

template <typename T>
VULKAN_HPP_INLINE typename ResultValueType<T>::type createResultValueType( Result result, T & data )
{
template <typename T>
VULKAN_HPP_INLINE typename VULKAN_HPP_NAMESPACE::ResultValueType<T>::type createResultValueType( VULKAN_HPP_NAMESPACE::Result result, T & data )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
return ResultValue<T>( result, data );
return ResultValue<T>( result, data );
#else
ignore( result );
return data;
VULKAN_HPP_NAMESPACE::detail::ignore( result );
return data;
#endif
}
}

template <typename T>
VULKAN_HPP_INLINE typename ResultValueType<T>::type createResultValueType( Result result, T && data )
{
template <typename T>
VULKAN_HPP_INLINE typename VULKAN_HPP_NAMESPACE::ResultValueType<T>::type createResultValueType( VULKAN_HPP_NAMESPACE::Result result, T && data )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
return ResultValue<T>( result, std::move( data ) );
return ResultValue<T>( result, std::move( data ) );
#else
ignore( result );
return std::move( data );
VULKAN_HPP_NAMESPACE::detail::ignore( result );
return std::move( data );
#endif
}
}
} // namespace detail

VULKAN_HPP_INLINE void resultCheck( Result result, char const * message )
namespace detail
{
VULKAN_HPP_INLINE void resultCheck( Result result, char const * message )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
ignore( message );
VULKAN_HPP_ASSERT_ON_RESULT( result == Result::eSuccess );
VULKAN_HPP_NAMESPACE::detail::ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_NAMESPACE::detail::ignore( message );
VULKAN_HPP_ASSERT_ON_RESULT( result == Result::eSuccess );
#else
if ( result != Result::eSuccess )
{
detail::throwResultException( result, message );
}
if ( result != Result::eSuccess )
{
VULKAN_HPP_NAMESPACE::detail::throwResultException( result, message );
}
#endif
}
}

VULKAN_HPP_INLINE void resultCheck( Result result, char const * message, std::initializer_list<Result> successCodes )
{
VULKAN_HPP_INLINE void resultCheck( Result result, char const * message, std::initializer_list<Result> successCodes )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
ignore( message );
ignore( successCodes ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_ASSERT_ON_RESULT( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );
VULKAN_HPP_NAMESPACE::detail::ignore( result ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_NAMESPACE::detail::ignore( message );
VULKAN_HPP_NAMESPACE::detail::ignore( successCodes ); // just in case VULKAN_HPP_ASSERT_ON_RESULT is empty
VULKAN_HPP_ASSERT_ON_RESULT( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );
#else
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
detail::throwResultException( result, message );
}
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
VULKAN_HPP_NAMESPACE::detail::throwResultException( result, message );
}
#endif
}
}
} // namespace detail

//===========================
//=== CONSTEXPR CONSTANTs ===
Expand Down
Loading
Loading