DPsim
Loading...
Searching...
No Matches
Factory.h
Go to the documentation of this file.
1#include <map>
2
5
11
18
23
24#pragma once
25
26template <class BaseClass> class Creator {
27
28public:
29 virtual ~Creator() {}
30
31 virtual std::shared_ptr<BaseClass>
32 Create(const std::string &name,
33 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) = 0;
34};
35
36template <class DerivedClass, class BaseClass>
37class DerivedCreator : public Creator<BaseClass> {
38
39public:
40 std::shared_ptr<BaseClass>
41 Create(const std::string &name,
42 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
43 return std::shared_ptr<BaseClass>(new DerivedClass(name, logLevel));
44 }
45};
46
47template <class BaseClass> class Factory {
48public:
49 static Factory &get() {
50 static Factory instance;
51 return instance;
52 }
53
54 std::vector<std::string> getItems() {
55
56 std::vector<std::string> items;
57 for (auto g : functionMap) {
58 items.push_back(g.first);
59 }
60
61 return items;
62 }
63
64 std::shared_ptr<BaseClass>
65 create(std::string type, const std::string &name,
66 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
67
68 auto it = functionMap.find(type);
69 if (it != functionMap.end())
70 return it->second->Create(name, logLevel);
71 else
72 throw CPS::SystemError("Unsupported type '" + type + "'!");
73 }
74
75 void registerExciter(const std::string &type, Creator<BaseClass> *Fn) {
76
77 functionMap[type] = Fn;
78 }
79
80private:
81 Factory() {}
82 Factory(const Factory &);
83 ~Factory() {
84 auto i = functionMap.begin();
85 while (i != functionMap.end()) {
86 delete (*i).second;
87 ++i;
88 }
89 }
90
91 std::map<std::string, Creator<BaseClass> *> functionMap;
92};
93
94template <class BaseClass> class FactoryRegistration {
95public:
99};
100
116
143
155} // namespace SynchronGeneratorFactory
156
157namespace PSSFactory {
162} // namespace PSSFactory
163
173} // namespace GovernorFactory
174
175namespace TurbineFactory {
184} // namespace TurbineFactory
Base model for Governors.
4 Order Synchronous generator model for transient stability analysis
spdlog::level::level_enum Level
Definition Logger.h:33
Base class for SP VBR synchronous generator model single phase.
Voltage-Behind-Reactance (VBR) implementation of 3rd order synchronous generator model.
Voltage-Behind-Reactance (VBR) implementation of 4th order synchronous generator model.
Voltage-Behind-Reactance (VBR) implementation of 5th type 2 order synchronous generator model Ref: Mi...
Voltage-Behind-Reactance (VBR) implementation of 6th order synchronous generator model Marconato's mo...
Voltage-Behind-Reactance (VBR) implementation of 6th order synchronous generator model Anderson-Fouad...
virtual ~Creator()
Definition Factory.h:29
virtual std::shared_ptr< BaseClass > Create(const std::string &name, CPS::Logger::Level logLevel=CPS::Logger::Level::debug)=0
std::shared_ptr< BaseClass > Create(const std::string &name, CPS::Logger::Level logLevel=CPS::Logger::Level::debug)
Definition Factory.h:41
static Factory & get()
Definition Factory.h:49
void registerExciter(const std::string &type, Creator< BaseClass > *Fn)
Definition Factory.h:75
std::vector< std::string > getItems()
Definition Factory.h:54
std::shared_ptr< BaseClass > create(std::string type, const std::string &name, CPS::Logger::Level logLevel=CPS::Logger::Level::debug)
Definition Factory.h:65
FactoryRegistration(std::string type, Creator< BaseClass > *Fn)
Definition Factory.h:96
void registerExciters()
Definition Factory.h:102
void registerGovernors()
Definition Factory.h:165
void registerPSSs()
Definition Factory.h:158
void registerTurbines()
Definition Factory.h:176