summaryrefslogtreecommitdiffstats
path: root/src/sp-factory.cpp
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-02 18:45:20 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-02 18:45:20 +0000
commit0a7e23844c3a43203de3f5207aecb278e84ee739 (patch)
tree73368a7dd8367c23599f0027d63c1c0a06638865 /src/sp-factory.cpp
parentRegistered classes with new factory. Hkern, Vkern and FeFuncX have to be rewr... (diff)
downloadinkscape-0a7e23844c3a43203de3f5207aecb278e84ee739.tar.gz
inkscape-0a7e23844c3a43203de3f5207aecb278e84ee739.zip
Added virtual destructor to SPObject. Switched to new factory. Replaced some casts. Inkscape seems stable, car.svgz renders correctly to png.
(bzr r11608.1.70)
Diffstat (limited to 'src/sp-factory.cpp')
-rw-r--r--src/sp-factory.cpp51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp
index 192f092ed..a8d9d9f5f 100644
--- a/src/sp-factory.cpp
+++ b/src/sp-factory.cpp
@@ -3,6 +3,7 @@
#include <stdexcept>
#include "sp-object.h"
+#include "xml/node.h"
SPFactory& SPFactory::instance() {
static SPFactory factory;
@@ -13,16 +14,52 @@ bool SPFactory::registerObject(std::string id, CreateObjectMethod* createFunctio
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);
+SPObject* SPFactory::createObject(const Inkscape::XML::Node& id) const {
+ std::map<std::string, CreateObjectMethod*>::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");
+
+ if (type_name) {
+ entry = this->objectMap.find(type_name);
+ } else {
+ entry = this->objectMap.find(id.name());
+ }
+ } else {
+ entry = this->objectMap.end();
+ }
+
+ if (entry == this->objectMap.end()) {
+ g_warning("Factory: Type \"%s\" not registered!", id.name());
- 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)();
+
+// 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;
+ }
+ */