summaryrefslogtreecommitdiffstats
path: root/src/xml/repr-sorting.cpp
blob: 9fd3b2289e692de53142c4b655d0f010b9fd2ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2018 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "util/longest-common-suffix.h"
#include "xml/repr.h"
#include "xml/node-iterators.h"
#include "repr-sorting.h"

Inkscape::XML::Node const *LCA(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b)
{
    using Inkscape::Algorithms::nearest_common_ancestor;
    Inkscape::XML::Node const *ancestor =
        nearest_common_ancestor<Inkscape::XML::NodeConstParentIterator>(a, b, nullptr);
    bool OK = false;
    if (ancestor) {
        if (ancestor->type() != Inkscape::XML::NodeType::DOCUMENT_NODE) {
            OK = true;
        }
    }
    if ( OK ) {
        return ancestor;
    } else {
        return nullptr;
    }
}

Inkscape::XML::Node *LCA(Inkscape::XML::Node *a, Inkscape::XML::Node *b)
{
    Inkscape::XML::Node const *tmp = LCA(const_cast<Inkscape::XML::Node const *>(a), const_cast<Inkscape::XML::Node const *>(b));
    return const_cast<Inkscape::XML::Node *>(tmp);
}

Inkscape::XML::Node const *AncetreFils(Inkscape::XML::Node const *descendent, Inkscape::XML::Node const *ancestor)
{
    Inkscape::XML::Node const *result = nullptr;
    if ( descendent && ancestor ) {
        if (descendent->parent() == ancestor) {
            result = descendent;
        } else {
            result = AncetreFils(descendent->parent(), ancestor);
        }
    }
    return result;
}

Inkscape::XML::Node *AncetreFils(Inkscape::XML::Node *descendent, Inkscape::XML::Node *ancestor)
{
    Inkscape::XML::Node const * tmp = AncetreFils(const_cast<Inkscape::XML::Node const*>(descendent), const_cast<Inkscape::XML::Node const*>(ancestor));
    return const_cast<Inkscape::XML::Node *>(tmp);
}

/*
  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:fileencoding=utf-8:textwidth=99 :