diff --git a/openVulkanoCpp/Base/Utils.cpp b/openVulkanoCpp/Base/Utils.cpp index 4987888..f9bb154 100644 --- a/openVulkanoCpp/Base/Utils.cpp +++ b/openVulkanoCpp/Base/Utils.cpp @@ -12,6 +12,7 @@ #include #endif #include +#include #include #include #include @@ -61,13 +62,21 @@ namespace OpenVulkano #endif } - Array Utils::ReadFile(const std::string& filePath, bool emptyOnMissing, bool nullTerminateString) + template + Array Utils::ReadFile(const T& filePath, bool emptyOnMissing, bool nullTerminateString) { std::ifstream file(filePath, std::ios::ate | std::ios::binary); if (!file.is_open()) { if (emptyOnMissing) return {}; - throw std::runtime_error("Failed to open file '" + filePath + "'!"); + if constexpr (std::is_same_v>, std::filesystem::path>) + { + throw std::runtime_error("Failed to open file '" + filePath.string() + "'!"); + } + else + { + throw std::runtime_error("Failed to open file '" + filePath + "'!"); + } } const size_t fileSize = static_cast(file.tellg()); Array data(fileSize + nullTerminateString); @@ -77,4 +86,9 @@ namespace OpenVulkano file.close(); return data; } + + template Array Utils::ReadFile(const std::string& filePath, bool emptyOnMissing, bool nullTerminateString); + template Array Utils::ReadFile(const std::filesystem::path& filePath, + bool emptyOnMissing, bool nullTerminateString); + } diff --git a/openVulkanoCpp/Base/Utils.hpp b/openVulkanoCpp/Base/Utils.hpp index 803995c..3b8f880 100644 --- a/openVulkanoCpp/Base/Utils.hpp +++ b/openVulkanoCpp/Base/Utils.hpp @@ -185,7 +185,8 @@ namespace OpenVulkano return subs; } - static Array ReadFile(const std::string& filePath, bool emptyOnMissing = false, + template + static Array ReadFile(const T& filePath, bool emptyOnMissing = false, bool nullTerminateString = false); template