Files
OpenVulkano/openVulkanoCpp/Base/Utils.cpp
2021-01-10 23:39:13 +01:00

41 lines
1.0 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Utils.hpp"
#ifdef _MSC_VER
#include <Windows.h>
#else
#include <pthread.h>
#include <fstream>
#endif
namespace openVulkanoCpp
{
void Utils::SetThreadName(const std::string& name)
{
#ifdef _MSC_VER
auto thisThread = ::GetCurrentThread();
std::wstring namew(name.begin(), name.end());
SetThreadDescription(thisThread, namew.c_str());
#else
pthread_setname_np(pthread_self(), name.c_str());
#endif
}
Array<char> Utils::ReadFile(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::ate | std::ios::binary);
if (!file.is_open()) throw std::runtime_error("Failed to open file '" + filePath + "'!");
const size_t fileSize = static_cast<size_t>(file.tellg());
Array<char> data(fileSize);
file.seekg(0);
file.read(data.Data(), fileSize);
file.close();
return data;
}
}