blob: 53bfbc58ec04193a6ca9b350a90231e5d9d2df03 (
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
33
|
#include "ParserFactory.h"
#include "Exception.h"
#include "XMLParser.h"
#include "TXTParser.h"
#include "CSVParser.h"
using namespace std;
ParserFactory::ParserFactory() {
this->parsers.push_back(unique_ptr<Parser>(new XMLParser()));
this->parsers.push_back(unique_ptr<Parser>(new TXTParser()));
this->parsers.push_back(unique_ptr<Parser>(new CSVParser()));
}
Parser & ParserFactory::get_parser(FileReader & file) {
unsigned int best_score = 0;
Parser * best_strategy = nullptr;
for (auto & parser : this->parsers) {
parser->set_file(file);
unsigned int score = parser->heuristic();
if (score <= best_score) continue;
best_score = score;
best_strategy = parser.get();
}
if (best_strategy == nullptr)
throw Exception("ParserFactory: unknown file type");
return *best_strategy;
}
|