Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
Utility.cpp
Go to the documentation of this file.
1 #include "Utility.hpp"
2 #include <fstream>
3 #include <iostream>
4 
5 namespace Engine
6 {
7  eastl::vector<char> Utility::ReadFile(const eastl::string& fileName, int fileOpenMode)
8  {
9  std::ifstream file(fileName.c_str());
10 
11  if (!file)
12  {
13  throw std::runtime_error("Failed to find file!");
14  }
15 
16  if (!file.is_open())
17  {
18  throw std::runtime_error("Failed to open file!");
19  }
20 
21  file.seekg(0, file.end);
22  size_t fileSize = size_t(file.tellg());
23  eastl::vector<char> buffer(fileSize);
24 
25  file.seekg(0, file.beg);
26  file.read(buffer.data(), fileSize);
27  file.close();
28 
29  return buffer;
30  }
31 
32  bool Utility::FileExists(const eastl::string& fileName)
33  {
34  std::ifstream file(fileName.c_str());
35 
36  bool fileExists = file.is_open();
37  file.close();
38 
39  return fileExists;
40  }
41 } // namespace Engine
static bool FileExists(const eastl::string &fileName)
Definition: Utility.cpp:32
static eastl::vector< char > ReadFile(const eastl::string &fileName, int fileOpenMode=1)
Definition: Utility.cpp:7