diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-22 16:09:14 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-22 16:09:14 +0200 |
commit | d90cecc758d3c348f3aedf9c6e45a13ba6a0b0c3 (patch) | |
tree | 1b24e7c0fac394ef5cf0d6538b5209b89e91f86e /LocalFile.cpp | |
parent | e185fe6bc6cbe9bc1e0694fc5b11650118eeef82 (diff) |
Diffstat (limited to 'LocalFile.cpp')
-rw-r--r-- | LocalFile.cpp | 36 |
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() { } + |