2 #include "algorithms/longest-common-suffix.h"
3 #include "xml/repr.h"
4 #include "xml/node-iterators.h"
6 static bool
7 same_repr(Inkscape::XML::Node &a, Inkscape::XML::Node &b)
8 {
9 /* 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. */
10 return &a == &b;
11 }
13 Inkscape::XML::Node *
14 LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b)
15 {
16 using Inkscape::Algorithms::longest_common_suffix;
17 Inkscape::XML::Node *ancestor = longest_common_suffix<Inkscape::XML::NodeParentIterator>(
18 a, b, NULL, &same_repr
19 );
20 if ( ancestor && ancestor->type() != Inkscape::XML::DOCUMENT_NODE ) {
21 return ancestor;
22 } else {
23 return NULL;
24 }
25 }
27 /**
28 * Returns a child of \a ancestor such that ret is itself an ancestor of \a descendent.
29 *
30 * The current version returns NULL if ancestor or descendent is NULL, though future versions may
31 * call g_log. Please update this comment if you rely on the current behaviour.
32 */
33 Inkscape::XML::Node *
34 AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor)
35 {
36 if (descendent == NULL || ancestor == NULL)
37 return NULL;
38 if (sp_repr_parent(descendent) == ancestor)
39 return descendent;
40 return AncetreFils(sp_repr_parent(descendent), ancestor);
41 }
44 /*
45 Local Variables:
46 mode:c++
47 c-file-style:"stroustrup"
48 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
49 indent-tabs-mode:nil
50 fill-column:99
51 End:
52 */
53 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :