aboutsummaryrefslogtreecommitdiff
path: root/FileReaderFactory.cpp
blob: e40dbb9e702e1ad7ce6062c6957d2386599fe3f0 (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
#include <memory>

#include "FileReaderFactory.h"
#include "FileReader.h"

#include "LocalFileReader.h"
#include "HTTPFileReader.h"

using namespace std;

unique_ptr<FileReader> FileReaderFactory::create(const string & url) {
	FileReader * reader = nullptr;

	// protocol handlers
	if (url.starts_with("file://"))
		reader = new LocalFileReader(url);
	else if (url.starts_with("http://"))
		reader = new HTTPFileReader(url);
	else if (url.starts_with("https://"))
		reader = new HTTPFileReader(url);

	// no protocol = treat as file://
	if (reader == nullptr)
		reader = new LocalFileReader(url);

	reader->open();

	return unique_ptr<FileReader>(reader);
}