PLaSK library

Loading...
Searching...
No Matches
factory.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "factory.hpp"
15#include "../utils/string.hpp"
16
17 namespace plask {
18
19 FiltersFactory &FiltersFactory::getDefault() {
20 static FiltersFactory defaultDb;
21 return defaultDb;
22}
23
24 shared_ptr<Solver> FiltersFactory::get(XMLReader &reader, Manager& manager) {
25 if (reader.getTagName() != "filter")
26 return shared_ptr<Solver>();
27 std::string typeName = reader.requireAttribute("for");
28 auto it = filterCreators.find(typeName);
29 if (it == filterCreators.end())
30 throw Exception("no filter for {0}", typeName);
31 return it->second(reader, manager);
32}
33
34 void FiltersFactory::add(const std::string typeName, FiltersFactory::FilterCreator filterCreator) {
35 filterCreators[typeName] = filterCreator;
36}
37
38
39} // namespace plask