Debian Codegraph @

plugins/dm.objectives/ce/ComponentEditorFactory.cpp

raw
1 #include "ComponentEditorFactory.h"
2
3 #include <stdexcept>
4
5 namespace objectives
6 {
7
8 namespace ce
9 {
10
11 // Static map instance owner
12 ComponentEditorMap& ComponentEditorFactory::getMap()
13 {
14 static ComponentEditorMap _instance;
15 return _instance;
16 }
17
18 // Create a named ComponentEditor type
19 ComponentEditorPtr ComponentEditorFactory::create(wxWindow* parent,
20 const std::string& type,
21 objectives::Component& comp)
22 {
23 ComponentEditorMap::const_iterator i = getMap().find(type);
24
25 if (i != getMap().end())
26 return i->second->create(parent, comp);
27 else
28 return ComponentEditorPtr();
29 }
30
31 // Register a new type
32 void ComponentEditorFactory::registerType(const std::string& type,
33 ComponentEditorPtr subclass)
34 {
35 getMap().insert(ComponentEditorMap::value_type(type, subclass));
36 }
37
38 void ComponentEditorFactory::clear() {
39 getMap().clear();
40 }
41
42 }
43
44 }