#include #include "Parser.h" #include "Exception.h" void Parser::parse(File & file, Deserializer & deserializer) { auto & col = Parser::get_collection(); if (col.size() < 1) throw Exception("no parsers registered"); unsigned int best_score = 0; ParserStrategy * best_strategy = nullptr; for (ParserStrategy * strategy : col) { unsigned int score = strategy->heuristic(file); if (score <= best_score) continue; best_score = score; best_strategy = strategy; } if (best_strategy == nullptr) throw Exception("unknown file type"); best_strategy->parse(file, deserializer); } void Parser::register_strategy(ParserStrategy * ps) { auto & col = Parser::get_collection(); if (std::find(col.begin(), col.end(), ps) != col.end()) return; col.push_back(ps); }