support file reading from string literal
This commit is contained in:
@@ -70,7 +70,7 @@ namespace OpenVulkano
|
||||
if (!file.is_open())
|
||||
{
|
||||
if (emptyOnMissing) return {};
|
||||
if constexpr (std::is_same_v<std::remove_reference_t<std::remove_cv_t<T>>, std::filesystem::path>)
|
||||
if constexpr (std::is_same_v<std::decay_t<T>, std::filesystem::path>)
|
||||
{
|
||||
throw std::runtime_error("Failed to open file '" + filePath.string() + "'!");
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <cassert>
|
||||
#include <cinttypes>
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include "Data/Containers/Array.hpp"
|
||||
|
||||
namespace OpenVulkano
|
||||
@@ -190,6 +191,31 @@ namespace OpenVulkano
|
||||
static Array<char> ReadFile(const T& filePath, bool emptyOnMissing = false,
|
||||
bool nullTerminateString = false);
|
||||
|
||||
template<size_t N>
|
||||
static Array<char> ReadFile(const char (&filePath)[N], bool emptyOnMissing = false,
|
||||
bool nullTerminateString = false)
|
||||
{
|
||||
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 '" + std::string(filePath) + "'!");
|
||||
}
|
||||
const size_t fileSize = static_cast<size_t>(file.tellg());
|
||||
Array<char> data(fileSize + nullTerminateString);
|
||||
file.seekg(0);
|
||||
file.read(data.Data(), fileSize);
|
||||
if (nullTerminateString)
|
||||
{
|
||||
data[fileSize] = '\0';
|
||||
}
|
||||
file.close();
|
||||
return data;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static int GetUniqueTypeId()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user