Explorar el Código

Added a generic big endian value load function

Eiyeron Fulmincendii hace 10 años
padre
commit
0f9525d83b
Se han modificado 1 ficheros con 24 adiciones y 0 borrados
  1. 24 0
      src/piaf/Archive.cpp

+ 24 - 0
src/piaf/Archive.cpp

@@ -1,12 +1,36 @@
 #include "Archive.h"
 #include <cstring>
+#include <cstdio>
 
 using WalrusRPG::PIAF::Archive;
 using WalrusRPG::PIAF::FileEntry;
 using WalrusRPG::PIAF::FileType;
 
+namespace
+{
+    template <typename T> T read_big_endian_value(void *ptr)
+    {
+        T result = 0;
+        uint8_t *data = (uint8_t *) ptr;
+        for (int i = 0; i < sizeof(T); i++)
+            result |= data[i] << (8 * (sizeof(T) - 1 - i));
+        return result;
+    }
+}
+
 Archive::Archive(char *filepath)
 {
+    if (filepath == nullptr)
+    {
+    }
+    // TODO : throw NPE
+    FILE *file = fopen(filepath, "rb");
+    if (file == nullptr)
+    {
+        // TODO : throw Couldn't open
+    }
+
+
     // loading stuff happens NOW
     // ...
     // entries = new File_Entry[];