aboutsummaryrefslogtreecommitdiff
path: root/LocalFile.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-09-22 16:09:14 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-09-22 16:09:14 +0200
commitd90cecc758d3c348f3aedf9c6e45a13ba6a0b0c3 (patch)
tree1b24e7c0fac394ef5cf0d6538b5209b89e91f86e /LocalFile.cpp
parente185fe6bc6cbe9bc1e0694fc5b11650118eeef82 (diff)
Diffstat (limited to 'LocalFile.cpp')
-rw-r--r--LocalFile.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/LocalFile.cpp b/LocalFile.cpp
new file mode 100644
index 0000000..2f4140d
--- /dev/null
+++ b/LocalFile.cpp
@@ -0,0 +1,36 @@
+#include <cstdio>
+#include <iterator>
+
+#include "LocalFile.h"
+#include "Exception.h"
+
+LocalFile LocalFile::instance(protocol);
+
+void LocalFile::open(const std::string url) {
+ std::string path = url;
+ if (path.starts_with(protocol))
+ path = path.substr(protocol.size());
+
+ std::ifstream _file(path);
+ if (!_file.is_open())
+ throw Exception("Cannot open file://%s\n", path.c_str());
+}
+
+void LocalFile::close() {
+ if (_file.is_open()) _file.close();
+}
+
+const std::string LocalFile::read() {
+ return std::string(std::istreambuf_iterator<char>(_file), std::istreambuf_iterator<char>());
+}
+
+LocalFile::~LocalFile() {
+ close();
+}
+
+LocalFile * LocalFile::clone() const {
+ return new LocalFile(this);
+}
+
+LocalFile::LocalFile(const LocalFile *) : File() { }
+