summaryrefslogtreecommitdiffstats
path: root/src/sp-factory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp-factory.cpp')
-rw-r--r--src/sp-factory.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp
new file mode 100644
index 000000000..192f092ed
--- /dev/null
+++ b/src/sp-factory.cpp
@@ -0,0 +1,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)();
+}