aboutsummaryrefslogtreecommitdiff
path: root/LocalFileReader.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-22 14:00:41 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-22 14:00:41 +0200
commitbc02054d56118110a36aea72d21f9d5e73d07d1f (patch)
tree2fc49dd3f93307df6242b8e63bca0e26b2e62168 /LocalFileReader.cpp
parentfab0fccc0aaa18e915bcd08e81e5a04177e435cd (diff)
refactor file reading factory
Diffstat (limited to 'LocalFileReader.cpp')
-rw-r--r--LocalFileReader.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/LocalFileReader.cpp b/LocalFileReader.cpp
index 1f9d574..a505616 100644
--- a/LocalFileReader.cpp
+++ b/LocalFileReader.cpp
@@ -1,17 +1,18 @@
#include <cstdio>
+#include <cstring>
#include <iterator>
#include "LocalFileReader.h"
#include "Exception.h"
-LocalFileReader LocalFileReader::instance(protocol);
+using namespace std;
-void LocalFileReader::open(const std::string url) {
- std::string path = url;
- if (path.starts_with(protocol))
- path = path.substr(protocol.size());
+void LocalFileReader::open() {
+ string path = this->url;
+ if (path.starts_with("file://"))
+ path = path.substr(strlen("file://"));
- this->file = new std::ifstream(path, std::ios::in);
+ this->file = new ifstream(path, ios::in);
if (this->file->fail() || !this->file->is_open())
throw Exception("cannot open file://%s\n", path.c_str());
}
@@ -23,7 +24,7 @@ void LocalFileReader::close() {
this->file->close();
}
-const std::string LocalFileReader::read() {
+const string LocalFileReader::read() {
if (this->content != nullptr)
return *this->content;
@@ -33,9 +34,9 @@ const std::string LocalFileReader::read() {
if (!this->file->is_open())
throw Exception("FileReader read after close\n");
- this->content = new std::string(
- std::istreambuf_iterator<char>(*this->file),
- std::istreambuf_iterator<char>()
+ this->content = new string(
+ istreambuf_iterator<char>(*this->file),
+ istreambuf_iterator<char>()
);
return *this->content;
@@ -55,9 +56,3 @@ LocalFileReader::~LocalFileReader() {
}
}
-LocalFileReader * LocalFileReader::clone() const {
- return new LocalFileReader(this);
-}
-
-LocalFileReader::LocalFileReader(const LocalFileReader *) : FileReader() { }
-