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
25
namespace
plask
{
26
30
struct
PLASK_API
FiltersFactory
31
{
32
33
typedef
std::function<shared_ptr<Solver>(
XMLReader
& reader,
Manager
& manager)>
FilterCreator
;
34
35
private
:
37
std::map<std::string, FilterCreator> filterCreators;
38
39
public
:
40
45
static
FiltersFactory
& getDefault();
46
52
struct
PLASK_API
Register
{
53
Register
(
const
std::string typeName,
FilterCreator
filterCreator) { getDefault().add(typeName, filterCreator); }
54
};
55
61
template
<
typename
PropertyTag>
62
struct
RegisterStandard
{
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
89
template
<
typename
PropertyTag>
90
inline
shared_ptr<Solver>
FiltersFactory::standard
(
XMLReader
& reader,
Manager
& manager) {
91
shared_ptr<GeometryObject>
out = manager.
requireGeometryObject
(reader.
requireAttribute
(
"geometry"
));
92
reader.
requireTagEnd
();
93
94
if
(shared_ptr<Geometry3D>
out_as_geom3D
=
dynamic_pointer_cast<Geometry3D>
(out))
95
return
shared_ptr<Solver>
(
new
Filter<PropertyTag, Geometry3D>
(
out_as_geom3D
));
96
97
if
(shared_ptr<Geometry2DCartesian>
out_as_geom2D
=
dynamic_pointer_cast<Geometry2DCartesian>
(out))
98
return
shared_ptr<Solver>
(
new
Filter<PropertyTag, Geometry2DCartesian>
(
out_as_geom2D
));
99
100
if
(shared_ptr<Geometry2DCylindrical>
out_as_geomCyl
=
dynamic_pointer_cast<Geometry2DCylindrical>
(out))
101
return
shared_ptr<Solver>
(
new
Filter<PropertyTag, Geometry2DCylindrical>
(
out_as_geomCyl
));
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
plask
filters
factory.hpp
Generated by
1.9.8