summaryrefslogtreecommitdiffstats
path: root/src/sp-factory.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-12 22:37:18 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-12 22:37:18 +0000
commitfbb85064cfaaf03cc09bacedb16a8561f61f2b3d (patch)
treee2a26a8e4fbbcfd1180522452d7b4db23408d39d /src/sp-factory.cpp
parentvarious little changes (diff)
downloadinkscape-fbb85064cfaaf03cc09bacedb16a8561f61f2b3d.tar.gz
inkscape-fbb85064cfaaf03cc09bacedb16a8561f61f2b3d.zip
Added prefPaths to contexts; modified SPFactory
(bzr r11608.1.94)
Diffstat (limited to 'src/sp-factory.cpp')
-rw-r--r--src/sp-factory.cpp39
1 files changed, 8 insertions, 31 deletions
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp
index 272584ca6..389589d09 100644
--- a/src/sp-factory.cpp
+++ b/src/sp-factory.cpp
@@ -10,7 +10,7 @@ SPFactory::TypeNotRegistered::TypeNotRegistered(const std::string& type)
: std::exception(), type(type) {
}
-const char* SPFactory::TypeNotRegistered::what() const noexcept {
+const char* SPFactory::TypeNotRegistered::what() const throw() {
return type.c_str();
}
@@ -19,39 +19,16 @@ SPFactory& SPFactory::instance() {
return factory;
}
-bool SPFactory::registerObject(const std::string& id, std::function<SPObject* ()> createFunction) {
+bool SPFactory::registerObject(const std::string& id, CreateFunction* createFunction) {
return this->objectMap.insert(std::make_pair(id, createFunction)).second;
-
- // replace when gcc supports this
- //return this->objectMap.emplace(id, createFunction).second;
}
-SPObject* SPFactory::createObject(const Inkscape::XML::Node& id) const {
- std::string name;
-
- switch (id.type()) {
- case Inkscape::XML::TEXT_NODE:
- name = "string";
- break;
-
- case Inkscape::XML::ELEMENT_NODE: {
- gchar const* const sptype = id.attribute("sodipodi:type");
-
- if (sptype) {
- name = sptype;
- } else {
- name = id.name();
- }
- break;
- }
- default:
- break;
- }
+SPObject* SPFactory::createObject(const std::string& id) const {
+ std::map<const std::string, CreateFunction*>::const_iterator it = this->objectMap.find(id);
- try {
- std::function<SPObject* ()> createFunction = this->objectMap.at(name);
- return createFunction();
- } catch (const std::out_of_range& ex) {
- std::throw_with_nested(TypeNotRegistered(name));
+ if (it == this->objectMap.end()) {
+ throw TypeNotRegistered(id);
}
+
+ return (*it).second();
}