DPsim
Loading...
Searching...
No Matches
Factory.h
Go to the documentation of this file.
1#include <map>
2
5
11
20
25
26#pragma once
27
28template <class BaseClass> class Creator {
29
30public:
31 virtual ~Creator() {}
32
33 virtual std::shared_ptr<BaseClass>
34 Create(const std::string &name,
35 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) = 0;
36};
37
38template <class DerivedClass, class BaseClass>
39class DerivedCreator : public Creator<BaseClass> {
40
41public:
42 std::shared_ptr<BaseClass>
43 Create(const std::string &name,
44 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
45 return std::shared_ptr<BaseClass>(new DerivedClass(name, logLevel));
46 }
47};
48
49template <class BaseClass> class Factory {
50public:
51 static Factory &get() {
52 static Factory instance;
53 return instance;
54 }
55
56 std::vector<std::string> getItems() {
57
58 std::vector<std::string> items;
59 for (auto g : functionMap) {
60 items.push_back(g.first);
61 }
62
63 return items;
64 }
65
66 std::shared_ptr<BaseClass>
67 create(std::string type, const std::string &name,
68 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
69
70 auto it = functionMap.find(type);
71 if (it != functionMap.end())
72 return it->second->Create(name, logLevel);
73 else
74 throw CPS::SystemError("Unsupported type '" + type + "'!");
75 }
76
77 void registerExciter(const std::string &type, Creator<BaseClass> *Fn) {
78
79 functionMap[type] = Fn;
80 }
81
82private:
83 Factory() {}
84 Factory(const Factory &);
85 ~Factory() {
86 auto i = functionMap.begin();
87 while (i != functionMap.end()) {
88 delete (*i).second;
89 ++i;
90 }
91 }
92
93 std::map<std::string, Creator<BaseClass> *> functionMap;
94};
95
96template <class BaseClass> class FactoryRegistration {
97public:
98 FactoryRegistration(std::string type, Creator<BaseClass> *Fn) {
100 }
101};
102
118
145
167} // namespace SynchronGeneratorFactory
168
169namespace PSSFactory {
174} // namespace PSSFactory
175
185} // namespace GovernorFactory
186
187namespace TurbineFactory {
196} // namespace TurbineFactory
Base model for Governors.
4 Order Synchronous generator model for transient stability analysis
4 Order Synchronous generator model for transient stability analysis
6 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:31
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:43
static Factory & get()
Definition Factory.h:51
void registerExciter(const std::string &type, Creator< BaseClass > *Fn)
Definition Factory.h:77
std::vector< std::string > getItems()
Definition Factory.h:56
std::shared_ptr< BaseClass > create(std::string type, const std::string &name, CPS::Logger::Level logLevel=CPS::Logger::Level::debug)
Definition Factory.h:67
FactoryRegistration(std::string type, Creator< BaseClass > *Fn)
Definition Factory.h:98
void registerExciters()
Definition Factory.h:104
void registerGovernors()
Definition Factory.h:177
void registerPSSs()
Definition Factory.h:170
void registerTurbines()
Definition Factory.h:188