PLaSK library
Loading...
Searching...
No Matches
factory.hpp
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#ifndef PLASK__FILTERS_FACTORY_H
15#define PLASK__FILTERS_FACTORY_H
16
17#include "filter.hpp"
18
19#include <map>
20#include <string>
21#include <functional>
22#include "../utils/xml/reader.hpp"
23#include "../manager.hpp"
24
25namespace plask {
26
31{
32
33 typedef std::function<shared_ptr<Solver>(XMLReader& reader, Manager& manager)> FilterCreator;
34
35private:
37 std::map<std::string, FilterCreator> filterCreators;
38
39public:
40
45 static FiltersFactory& getDefault();
46
53 Register(const std::string typeName, FilterCreator filterCreator) { getDefault().add(typeName, filterCreator); }
54 };
55
61 template <typename PropertyTag>
63 RegisterStandard() { getDefault().addStandard<PropertyTag>(); }
64 };
65
67 template <typename PropertyTag>
68 static shared_ptr<Solver> standard(XMLReader& reader, Manager& manager);
69
80 shared_ptr<Solver> get(XMLReader& reader, Manager& manager);
81
82 void add(const std::string typeName, FilterCreator filterCreator);
83
84 template <typename PropertyTag>
85 void addStandard() { add(type_name<PropertyTag>(), FiltersFactory::standard<PropertyTag>); }
86
87};
88
89template <typename PropertyTag>
92 reader.requireTagEnd();
93
94 if (shared_ptr<Geometry3D> out_as_geom3D = dynamic_pointer_cast<Geometry3D>(out))
96
97 if (shared_ptr<Geometry2DCartesian> out_as_geom2D = dynamic_pointer_cast<Geometry2DCartesian>(out))
99
100 if (shared_ptr<Geometry2DCylindrical> out_as_geomCyl = dynamic_pointer_cast<Geometry2DCylindrical>(out))
102
103 throw NotImplemented("standard filter (for given configuration), geometry must be of type: Geometry3D, Geometry2DCartesian or Geometry2DCylindrical");
104}
105
106} // namespace plask
107
108#endif // PLASK__FILTERS_FACTORY_H