summaryrefslogtreecommitdiffhomepage
path: root/FoundationEx/src/reader/file.h
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-03-18 23:41:20 +0100
committerAki <please@ignore.pl>2024-03-18 23:41:20 +0100
commit2066e4911948d11cac5a234d2f7773dc5f06ba96 (patch)
tree27c7672aad884d1307736b3d15e704d7d786b314 /FoundationEx/src/reader/file.h
parent3df6ccddcbd881c2474746f5f1758b095c866a67 (diff)
downloadstarshatter-2066e4911948d11cac5a234d2f7773dc5f06ba96.zip
starshatter-2066e4911948d11cac5a234d2f7773dc5f06ba96.tar.gz
starshatter-2066e4911948d11cac5a234d2f7773dc5f06ba96.tar.bz2
Added filesystem-only starshatter::data DataLoader replacement
Step by step. The intent is to find a good spot between current data representations and the standard library and put the intermediate stage there. After it matures a bit, we can move further away.
Diffstat (limited to 'FoundationEx/src/reader/file.h')
-rw-r--r--FoundationEx/src/reader/file.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/FoundationEx/src/reader/file.h b/FoundationEx/src/reader/file.h
new file mode 100644
index 0000000..22810b6
--- /dev/null
+++ b/FoundationEx/src/reader/file.h
@@ -0,0 +1,49 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#pragma once
+
+#include <fstream>
+
+#include <starshatter/foundation/reader.h>
+#include <Text.h>
+
+
+namespace starshatter
+{
+namespace foundation
+{
+
+
+struct FileReader : public BaseReader<char>
+{
+ FileReader() = default;
+ FileReader(std::fstream src);
+ FileReader(const FileReader& other) = delete;
+ FileReader& operator=(const FileReader& other) = delete;
+ FileReader(FileReader&& other) = default;
+ FileReader& operator=(FileReader&& other) = default;
+ ~FileReader() override = default;
+
+ bool valid() const override;
+ Count available() const override;
+ Count seek(Count pos) override;
+ Count seek(Offset offset, Direction dir) override;
+ Count read(char* dest) override;
+ Count read(char* dest, Count bytes) override;
+ Count peek(char* dest) const override;
+ Count peek(char* dest, Count bytes) const override;
+ Text more() override;
+
+private:
+ mutable std::fstream file = {};
+ Count size = {};
+ Count position = {};
+};
+
+
+} // namespace foundation
+} // namespace starshatter