diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-02 21:01:45 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-02 21:01:45 +0000 |
| commit | 8443720ce6429b9beec839e60b8a808595f4ba72 (patch) | |
| tree | 3e08d3c631c2590a19481613a6e31cf09f6bed42 /src/sp-factory.cpp | |
| parent | Replaced some forgotten old casting macros. (diff) | |
| download | inkscape-8443720ce6429b9beec839e60b8a808595f4ba72.tar.gz inkscape-8443720ce6429b9beec839e60b8a808595f4ba72.zip | |
Cleaned up a bit. Uses some C++11 features.
(bzr r11608.1.72)
Diffstat (limited to 'src/sp-factory.cpp')
| -rw-r--r-- | src/sp-factory.cpp | 54 |
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; - } - */ |
