diff options
Diffstat (limited to 'FileReader.cpp')
-rw-r--r-- | FileReader.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/FileReader.cpp b/FileReader.cpp new file mode 100644 index 0000000..503aee5 --- /dev/null +++ b/FileReader.cpp @@ -0,0 +1,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; +} + |