aboutsummaryrefslogtreecommitdiffstats
path: root/src/iomanager.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-04-04 12:19:41 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-04-04 12:19:41 +0100
commit55a1e0ad7c9d2661c266b2e767bfcb2f944e859f (patch)
treefe3ac90ab853e2f87bd33294976a3fc56e144988 /src/iomanager.cpp
parentaa67c8bb56cb750ac83ecbd361439f5ecb5e12d9 (diff)
downloadYAGE-55a1e0ad7c9d2661c266b2e767bfcb2f944e859f.tar.gz
YAGE-55a1e0ad7c9d2661c266b2e767bfcb2f944e859f.zip
Adding spritebatch class
Diffstat (limited to 'src/iomanager.cpp')
-rw-r--r--src/iomanager.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/iomanager.cpp b/src/iomanager.cpp
new file mode 100644
index 00000000..b5e5518f
--- /dev/null
+++ b/src/iomanager.cpp
@@ -0,0 +1,32 @@
+#include "iomanager.hpp"
+
+#include <fstream>
+#include <stdexcept>
+
+namespace yage
+{
+
+bool IoManager::readFileToBuffer(const std::string &file_path, std::vector<unsigned char> &buffer)
+{
+ std::ifstream file(file_path, std::ios::binary);
+ if(!file.is_open())
+ throw std::runtime_error("Could not open '"+file_path+"'");
+
+ // seek to the end
+ file.seekg(0, std::ios::end);
+
+ // get the file size
+ int file_size = file.tellg();
+ file.seekg(0, std::ios::beg);
+
+ // reduce file size by header bytes
+ file_size -= file.tellg();
+
+ buffer.resize(file_size);
+ file.read((char *)&buffer[0], file_size);
+ file.close();
+
+ return true;
+}
+
+} // yage