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.cpp54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp
index a8d9d9f5f..29b308111 100644
--- a/src/sp-factory.cpp
+++ b/src/sp-factory.cpp
@@ -10,25 +10,31 @@ SPFactory& SPFactory::instance() {
return factory;
}
-bool SPFactory::registerObject(std::string id, CreateObjectMethod* createFunction) {
+bool SPFactory::registerObject(std::string id, std::function<SPObject*()> createFunction) {
return this->objectMap.insert(std::make_pair(id, createFunction)).second;
}
SPObject* SPFactory::createObject(const Inkscape::XML::Node& id) const {
- std::map<std::string, CreateObjectMethod*>::const_iterator entry;
+ std::map<std::string, std::function<SPObject*()>>::const_iterator entry;
- if (id.type() == Inkscape::XML::TEXT_NODE) {
- entry = this->objectMap.find("string");
- } else if (id.type() == Inkscape::XML::ELEMENT_NODE) {
- gchar const* const type_name = id.attribute("sodipodi:type");
+ switch (id.type()) {
+ case Inkscape::XML::TEXT_NODE:
+ entry = this->objectMap.find("string");
+ break;
- if (type_name) {
- entry = this->objectMap.find(type_name);
- } else {
- entry = this->objectMap.find(id.name());
+ case Inkscape::XML::ELEMENT_NODE: {
+ gchar const* const type_name = id.attribute("sodipodi:type");
+
+ if (type_name) {
+ entry = this->objectMap.find(type_name);
+ } else {
+ entry = this->objectMap.find(id.name());
+ }
+
+ break;
}
- } else {
- entry = this->objectMap.end();
+ default:
+ entry = this->objectMap.end();
}
if (entry == this->objectMap.end()) {
@@ -38,28 +44,4 @@ SPObject* SPFactory::createObject(const Inkscape::XML::Node& id) const {
}
return (entry->second)();
-
-// 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 (entry->second)();
}
-
-/*
- * if ( repr->type() == Inkscape::XML::TEXT_NODE ) {
- return SP_TYPE_STRING;
- } else if ( repr->type() == Inkscape::XML::ELEMENT_NODE ) {
- gchar const * const type_name = repr->attribute("sodipodi:type");
- return ( type_name
- ? name_to_gtype(SODIPODI_TYPE, type_name)
- : name_to_gtype(REPR_NAME, repr->name()) );
- } else {
- return 0;
- }
- */