blob: 503aee5c681c2452bf686dcebc5ceb31d09f8785 (
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
|
#include "FileReader.h"
#include "File.h"
File & FileReader::open(const std::string url) {
File * reader = find_reader(url)->clone();
reader->open(url);
return *reader;
}
void FileReader::assign(const std::string type, const File * node) {
static FactoryMap & map = get_map();
map[type] = node;
}
FactoryMap & FileReader::get_map() {
static FactoryMap map;
return map;
}
const File * FileReader::find_reader(const std::string type) {
static FactoryMap & map = get_map();
// try to find protocol by prefix
for (auto item : map) {
if (!type.starts_with(item.first)) continue;
return item.second;
}
// fallback is local file
return map.find("file://")->second;
}
|