aboutsummaryrefslogtreecommitdiff
path: root/src/reader.h
diff options
context:
space:
mode:
authorBossCode45 <boss@tehbox.org>2025-06-27 14:54:46 +1200
committerBossCode45 <boss@tehbox.org>2025-07-24 12:48:21 +1200
commitf953c730af2b90db99f709258c5d5e50fdcaadf7 (patch)
treeadbc79f0d48a74a42fd0eb22d85f03696a99dc42 /src/reader.h
parent06a2928d96b3d9aeaffb19013ba71a5cb6d96381 (diff)
downloadtehimage-f953c730af2b90db99f709258c5d5e50fdcaadf7.tar.gz
tehimage-f953c730af2b90db99f709258c5d5e50fdcaadf7.zip
Initial commit
Bringing a lot of stuff over from my maze-reader project in an attempt to split the image reading code off into a library.
Diffstat (limited to 'src/reader.h')
-rw-r--r--src/reader.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/reader.h b/src/reader.h
new file mode 100644
index 0000000..ab01092
--- /dev/null
+++ b/src/reader.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <cstddef>
+#include <cstdio>
+#include <string>
+
+#define BUFFER_SIZE 1024
+
+class Reader
+{
+public:
+ //Bytes are big endian
+ Reader(std::string file);
+ ~Reader();
+
+ template <typename T>
+ T readData();
+
+ char readByte();
+
+ void readBytes(char* out, size_t len);
+
+ void skipBytes(size_t len);
+
+ void close();
+private:
+ char buffer[BUFFER_SIZE];
+ size_t pos;
+ FILE* file;
+ bool ready = false;
+
+ void refreshBuffer();
+};