blob: 192f092ed27ae213b6f2392ea7f4637c2ca6099d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include "sp-factory.h"
#include <stdexcept>
#include "sp-object.h"
SPFactory& SPFactory::instance() {
static SPFactory factory;
return factory;
}
bool SPFactory::registerObject(std::string id, CreateObjectMethod* createFunction) {
return this->objectMap.insert(std::make_pair(id, createFunction)).second;
}
SPObject* SPFactory::createObject(std::string id) const {
std::map<std::string, CreateObjectMethod*>::const_iterator entry = this->objectMap.find(id);
if (entry == objectMap.end()) {
//g_warning("Factory: Type \"%s\" not registered!", id.c_str());
// SPObject* o = new SPObject();
//
// return o;
return 0;
}
return (entry->second)();
}
|