blob: 2c7a50ec17db5eb6b6c36f6c262d7e423518ee5b (
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 "FileStrategy.h"
FileStrategy & FileReader::open(const std::string url) {
FileStrategy * reader = find_reader(url)->clone();
reader->open(url);
return *reader;
}
void FileReader::register_strategy(const std::string type, const FileStrategy * node) {
static FactoryMap & map = get_map();
map[type] = node;
}
FactoryMap & FileReader::get_map() {
static FactoryMap map;
return map;
}
const FileStrategy * 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;
}
|