Code

056236d333379665909bf6a89251a344661eb11f
[inkscape.git] / src / xml / repr-sorting.cpp
2 #include "util/longest-common-suffix.h"
3 #include "xml/repr.h"
4 #include "xml/node-iterators.h"
6 static bool same_repr(Inkscape::XML::Node const &a, Inkscape::XML::Node const &b)
7 {
8   /* 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. */
9     return &a == &b;
10 }
12 Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b)
13 {
14     using Inkscape::Algorithms::longest_common_suffix;
15     Inkscape::XML::Node const *ancestor = longest_common_suffix<Inkscape::XML::NodeConstParentIterator>(
16         a, b, NULL, &same_repr
17     );
18     if ( ancestor && ancestor->type() != Inkscape::XML::DOCUMENT_NODE ) {
19         return ancestor;
20     } else {
21         return NULL;
22     }
23 }
25 Inkscape::XML::Node *LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b)
26 {
27     Inkscape::XML::Node const *tmp = LCA(const_cast<Inkscape::XML::Node const *>(a), const_cast<Inkscape::XML::Node const *>(b));
28     return const_cast<Inkscape::XML::Node *>(tmp);
29 }
31 Inkscape::XML::Node const *AncetreFils(Inkscape::XML::Node const *descendent, Inkscape::XML::Node const *ancestor)
32 {
33     Inkscape::XML::Node const *result = 0;
34     if ( descendent && ancestor ) {
35         if (descendent->parent() == ancestor) {
36             result = descendent;
37         } else {
38             result = AncetreFils(descendent->parent(), ancestor);
39         }
40     }
41     return result;
42 }
44 Inkscape::XML::Node *AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor)
45 {
46     Inkscape::XML::Node const * tmp = AncetreFils(const_cast<Inkscape::XML::Node const*>(descendent), const_cast<Inkscape::XML::Node const*>(ancestor));
47     return const_cast<Inkscape::XML::Node *>(tmp);
48 }
50 /*
51   Local Variables:
52   mode:c++
53   c-file-style:"stroustrup"
54   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
55   indent-tabs-mode:nil
56   fill-column:99
57   End:
58 */
59 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :