BARE2D
IOManager.cpp
Go to the documentation of this file.
1
#include "
IOManager.hpp
"
2
3
#include "
Logger.hpp
"
4
5
namespace
BARE2D
{
6
7
// Templated function defaults are in .tcc
8
9
bool
IOManager::readFileToBuffer
(
const
char
* filepath, std::string& buf, std::ios_base::openmode mode
/** = std::ios::binary*/
) {
10
std::ifstream file(filepath, mode);
11
12
if
(file.fail()) {
13
Logger::getInstance
()->
log
(
"Failed to load file to buffer: "
+ std::string(filepath));
14
return
false
;
15
}
16
17
// Seek to the end to get the file size
18
file.seekg(0, std::ios::end);
19
unsigned
int
fileSize = (
unsigned
int)file.tellg();
20
21
// Go back to the start
22
file.seekg(0, std::ios::beg);
23
fileSize -= (
unsigned
int)file.tellg();
24
25
// Resize for efficiency!
26
buf.resize(fileSize);
27
28
// Now read fileSize bytes
29
file.read((
char
*)&(buf[0]), fileSize);
30
31
// Close it up and return! Job done.
32
file.close();
33
34
return
true
;
35
}
36
37
}
BARE2D
Definition:
App.cpp:13
BARE2D::Logger::getInstance
static Logger * getInstance()
Definition:
Logger.cpp:34
BARE2D::Logger::log
void log(std::string message, bool important=false)
Logs a message to a file and the terminal.
Definition:
Logger.cpp:42
BARE2D::IOManager::readFileToBuffer
static bool readFileToBuffer(std::string &filepath, std::vector< T > &buf, std::ios_base::openmode mode=std::ios::binary)
Loads a file into a buffer.
IOManager.hpp
Logger.hpp
Source
IOManager.cpp
Generated by
1.8.17