summaryrefslogtreecommitdiffstats
path: root/src/xml
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-01-25 04:07:20 +0000
committermental <mental@users.sourceforge.net>2007-01-25 04:07:20 +0000
commitccd951a0896e15fb0c1e0324438dac149707a36b (patch)
treeccd0876ee3439e6b0d26df31ec92d28bc242c276 /src/xml
parentremove sp_repr_new use from document creation (diff)
downloadinkscape-ccd951a0896e15fb0c1e0324438dac149707a36b.tar.gz
inkscape-ccd951a0896e15fb0c1e0324438dac149707a36b.zip
eliminate last uses of sp_repr_new*
(bzr r2283)
Diffstat (limited to 'src/xml')
-rw-r--r--src/xml/repr-io.cpp39
-rw-r--r--src/xml/repr.cpp21
-rw-r--r--src/xml/repr.h2
-rw-r--r--src/xml/simple-document.h4
4 files changed, 19 insertions, 47 deletions
diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp
index a7425ccb3..c1d764a8b 100644
--- a/src/xml/repr-io.cpp
+++ b/src/xml/repr-io.cpp
@@ -20,6 +20,7 @@
#include "xml/repr.h"
#include "xml/attribute-record.h"
+#include "xml/simple-document.h"
#include "io/sys.h"
#include "io/uristream.h"
@@ -31,11 +32,12 @@ using Inkscape::IO::Writer;
using Inkscape::Util::List;
using Inkscape::Util::cons;
using Inkscape::XML::Document;
+using Inkscape::XML::SimpleDocument;
using Inkscape::XML::Node;
using Inkscape::XML::AttributeRecord;
static Document *sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns);
-static Node *sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
+static Node *sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
static gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar *default_ns, GHashTable *prefix_map);
static void sp_repr_write_stream_root_element (Node *repr, Writer &out, bool add_whitespace, gchar const *default_ns, int inlineattrs, int indent);
static void sp_repr_write_stream (Node *repr, Writer &out, gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, int inlineattrs, int indent);
@@ -374,13 +376,14 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns)
GHashTable * prefix_map;
prefix_map = g_hash_table_new (g_str_hash, g_str_equal);
- GSList *reprs=NULL;
- Node *root=NULL;
+ Document *rdoc = new Inkscape::XML::SimpleDocument();
+ Node *root=NULL;
for ( node = doc->children ; node != NULL ; node = node->next ) {
if (node->type == XML_ELEMENT_NODE) {
- Node *repr=sp_repr_svg_read_node (node, default_ns, prefix_map);
- reprs = g_slist_append(reprs, repr);
+ Node *repr=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
+ rdoc->appendChild(repr);
+ Inkscape::GC::release(repr);
if (!root) {
root = repr;
@@ -389,13 +392,12 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns)
break;
}
} else if ( node->type == XML_COMMENT_NODE ) {
- Node *comment=sp_repr_svg_read_node(node, default_ns, prefix_map);
- reprs = g_slist_append(reprs, comment);
+ Node *comment=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
+ rdoc->appendChild(comment);
+ Inkscape::GC::release(comment);
}
}
- Document *rdoc=NULL;
-
if (root != NULL) {
/* promote elements of SVG documents that don't use namespaces
* into the SVG namespace */
@@ -404,15 +406,7 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns)
{
promote_to_svg_namespace(root);
}
-
- rdoc = sp_repr_document_new_list(reprs);
- }
-
- for ( GSList *iter = reprs ; iter ; iter = iter->next ) {
- Node *repr=(Node *)iter->data;
- Inkscape::GC::release(repr);
}
- g_slist_free(reprs);
g_hash_table_destroy (prefix_map);
@@ -437,7 +431,7 @@ sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, co
}
static Node *
-sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
+sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
{
Node *repr, *crepr;
xmlAttrPtr prop;
@@ -459,17 +453,16 @@ sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *pre
return NULL; // we do not preserve all-whitespace nodes unless we are asked to
}
- Node *rdoc = sp_repr_new_text((const gchar *)node->content);
- return rdoc;
+ return xml_doc->createTextNode((const gchar *)node->content);
}
if (node->type == XML_COMMENT_NODE)
- return sp_repr_new_comment((const gchar *)node->content);
+ return xml_doc->createComment((const gchar *)node->content);
if (node->type == XML_ENTITY_DECL) return NULL;
sp_repr_qualified_name (c, 256, node->ns, node->name, default_ns, prefix_map);
- repr = sp_repr_new (c);
+ repr = xml_doc->createElement(c);
/* TODO remember node->ns->prefix if node->ns != NULL */
for (prop = node->properties; prop != NULL; prop = prop->next) {
@@ -485,7 +478,7 @@ sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *pre
child = node->xmlChildrenNode;
for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
- crepr = sp_repr_svg_read_node (child, default_ns, prefix_map);
+ crepr = sp_repr_svg_read_node (xml_doc, child, default_ns, prefix_map);
if (crepr) {
repr->appendChild(crepr);
Inkscape::GC::release(crepr);
diff --git a/src/xml/repr.cpp b/src/xml/repr.cpp
index bd64afc34..c6943a252 100644
--- a/src/xml/repr.cpp
+++ b/src/xml/repr.cpp
@@ -60,7 +60,7 @@ sp_repr_new_comment(gchar const *comment)
Inkscape::XML::Document *
sp_repr_document_new(char const *rootname)
{
- Inkscape::XML::Document *doc = new Inkscape::XML::SimpleDocument(g_quark_from_static_string("xml"));
+ Inkscape::XML::Document *doc = new Inkscape::XML::SimpleDocument();
if (!strcmp(rootname, "svg:svg")) {
doc->setAttribute("version", "1.0");
doc->setAttribute("standalone", "no");
@@ -76,25 +76,6 @@ sp_repr_document_new(char const *rootname)
return doc;
}
-/// Returns new document having reprs as first child.
-Inkscape::XML::Document *
-sp_repr_document_new_list(GSList *reprs)
-{
- g_assert(reprs != NULL);
-
- Inkscape::XML::Document *doc = sp_repr_document_new("void");
- doc->removeChild(doc->firstChild());
-
- for ( GSList *iter = reprs ; iter ; iter = iter->next ) {
- Inkscape::XML::Node *repr = (Inkscape::XML::Node *) iter->data;
- doc->appendChild(repr);
- }
-
- g_assert(sp_repr_document_root(doc) != NULL);
-
- return doc;
-}
-
/*
Local Variables:
mode:c++
diff --git a/src/xml/repr.h b/src/xml/repr.h
index ac7ca3218..416c979f9 100644
--- a/src/xml/repr.h
+++ b/src/xml/repr.h
@@ -244,8 +244,6 @@ Inkscape::XML::Node *sp_repr_lookup_child(Inkscape::XML::Node *repr,
gchar const *value);
-Inkscape::XML::Document *sp_repr_document_new_list(GSList *reprs);
-
inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document const *doc) {
return const_cast<Inkscape::XML::Node *>(doc->firstChild());
}
diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h
index c8ee4d9b4..11d0ef4a2 100644
--- a/src/xml/simple-document.h
+++ b/src/xml/simple-document.h
@@ -29,8 +29,8 @@ class SimpleDocument : public SimpleNode,
public NodeObserver
{
public:
- explicit SimpleDocument(int code)
- : SimpleNode(code), _in_transaction(false)
+ explicit SimpleDocument()
+ : SimpleNode(g_quark_from_static_string("xml")), _in_transaction(false)
{
_initBindings();
}