summaryrefslogtreecommitdiffstats
path: root/src/xml/repr-sorting.cpp
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-01-16 02:36:01 +0000
committermental <mental@users.sourceforge.net>2006-01-16 02:36:01 +0000
commit179fa413b047bede6e32109e2ce82437c5fb8d34 (patch)
treea5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/xml/repr-sorting.cpp
downloadinkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz
inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/xml/repr-sorting.cpp')
-rw-r--r--src/xml/repr-sorting.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp
new file mode 100644
index 000000000..123df33ee
--- /dev/null
+++ b/src/xml/repr-sorting.cpp
@@ -0,0 +1,53 @@
+
+#include "algorithms/longest-common-suffix.h"
+#include "xml/repr.h"
+#include "xml/node-iterators.h"
+
+static bool
+same_repr(Inkscape::XML::Node &a, Inkscape::XML::Node &b)
+{
+ /* todo: I'm not certain that it's legal to take the address of a reference. Check the exact wording of the spec on this matter. */
+ return &a == &b;
+}
+
+Inkscape::XML::Node *
+LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b)
+{
+ using Inkscape::Algorithms::longest_common_suffix;
+ Inkscape::XML::Node *ancestor = longest_common_suffix<Inkscape::XML::NodeParentIterator>(
+ a, b, NULL, &same_repr
+ );
+ if ( ancestor && ancestor->type() != Inkscape::XML::DOCUMENT_NODE ) {
+ return ancestor;
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * Returns a child of \a ancestor such that ret is itself an ancestor of \a descendent.
+ *
+ * The current version returns NULL if ancestor or descendent is NULL, though future versions may
+ * call g_log. Please update this comment if you rely on the current behaviour.
+ */
+Inkscape::XML::Node *
+AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor)
+{
+ if (descendent == NULL || ancestor == NULL)
+ return NULL;
+ if (sp_repr_parent(descendent) == ancestor)
+ return descendent;
+ return AncetreFils(sp_repr_parent(descendent), ancestor);
+}
+
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :