blob: 2f4140d87282c61afd654388b1217d0e6f4b22f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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() { }
|