summaryrefslogtreecommitdiffstats
path: root/src/sp-factory.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-02 14:06:06 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-02 14:06:06 +0000
commit4a56b453e43a53508f13d263cde7cf083f00cd26 (patch)
treebec14d62085ac818a0e89744c8febb75c7c88222 /src/sp-factory.cpp
parentAdded constructors to SP classes. (diff)
downloadinkscape-4a56b453e43a53508f13d263cde7cf083f00cd26.tar.gz
inkscape-4a56b453e43a53508f13d263cde7cf083f00cd26.zip
Added new factory for SPObject tree objects.
(bzr r11608.1.68)
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)();
+}