aboutsummaryrefslogtreecommitdiff
path: root/FileReader.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-18 15:48:14 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-18 15:48:14 +0200
commitd8289105193707daede1a5b59137f18e20f20aeb (patch)
tree939908b9c4c6f7aaef8aa61ee2e04be3e85610b6 /FileReader.cpp
parent76e61d68bbf568ec0d7fc4632e52d4de5496b003 (diff)
(2/2) rename
Diffstat (limited to 'FileReader.cpp')
-rw-r--r--FileReader.cpp35
1 files changed, 4 insertions, 31 deletions
diff --git a/FileReader.cpp b/FileReader.cpp
index 4b72b11..b76de50 100644
--- a/FileReader.cpp
+++ b/FileReader.cpp
@@ -1,36 +1,9 @@
-#include <memory>
+#include <string>
-#include "FileReaderFactory.h"
#include "FileReader.h"
+#include "FileReaderFactory.h"
-using namespace std;
-
-unique_ptr<FileReader> FileReaderFactory::open(const std::string url) {
- FileReader * reader = find_reader(url)->clone();
- reader->open(url);
- return unique_ptr<FileReader>(reader);
-}
-
-void FileReaderFactory::register_strategy(const std::string type, const FileReader * node) {
- static FactoryMap & map = get_map();
- map[type] = node;
-}
-
-FactoryMap & FileReaderFactory::get_map() {
- static FactoryMap map;
- return map;
-}
-
-const FileReader * FileReaderFactory::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;
+FileReader::FileReader(const std::string protocol) {
+ FileReaderFactory::register_strategy(protocol, this);
}