25 lines
750 B
C++
25 lines
750 B
C++
|
|
// EditItemFactory.cpp - 工厂管理器
|
||
|
|
#include "diagramEditor/editItemFactory.h"
|
||
|
|
#include "diagramEditor/busItemFactory.h"
|
||
|
|
#include "diagramEditor/bayItemFactory.h"
|
||
|
|
#include "diagramEditor/transItemFactory.h"
|
||
|
|
#include <map>
|
||
|
|
#include <memory>
|
||
|
|
|
||
|
|
EditItemFactory* EditItemFactory::getFactory(int itemType) {
|
||
|
|
static std::map<int, std::unique_ptr<EditItemFactory>> factories;
|
||
|
|
|
||
|
|
// 延迟初始化
|
||
|
|
if (factories.empty()) {
|
||
|
|
factories[1] = std::make_unique<BusItemFactory>();
|
||
|
|
factories[2] = std::make_unique<BayItemFactory>();
|
||
|
|
factories[3] = std::make_unique<TransItemFactory>();
|
||
|
|
}
|
||
|
|
|
||
|
|
auto it = factories.find(itemType);
|
||
|
|
if (it != factories.end()) {
|
||
|
|
return it->second.get();
|
||
|
|
}
|
||
|
|
return nullptr;
|
||
|
|
}
|