Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/starmath/source/mathml/iterator.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#include <mathml/iterator.hxx>
11
12
/** The purpose of this iterator is to be able to iterate threw an infinite element tree
13
  * infinite -> as much as your memory can hold
14
  * No call-backs that will end up in out of stack
15
  */
16
17
namespace mathml
18
{
19
static inline void cloneElement(SmMlElement* aSmMlElement, void* aData)
20
0
{
21
    // Prepare data
22
0
    SmMlElement* aNewSmMlElement = new SmMlElement(*aSmMlElement);
23
0
    SmMlElement* aCopyTree = *static_cast<SmMlElement**>(aData);
24
25
    // Append data
26
0
    aCopyTree->setSubElement(aCopyTree->getSubElementsCount(), aNewSmMlElement);
27
28
    // Prepare for following
29
    // If it has sub elements, then it will be the next
30
0
    if (aSmMlElement->getSubElementsCount() != 0)
31
0
        aCopyTree = aNewSmMlElement;
32
0
    else // Otherwise remounts up to where it should be
33
0
    {
34
0
        while (aSmMlElement->getParentElement() != nullptr)
35
0
        {
36
            // get parent
37
0
            SmMlElement* pParent = aSmMlElement->getParentElement();
38
0
            aCopyTree = aCopyTree->getParentElement();
39
            // was this the last branch ?
40
0
            if (aSmMlElement->getSubElementId() + 1 != pParent->getSubElementsCount())
41
0
                break; // no -> stop going up
42
            // Prepare for next round
43
0
            aSmMlElement = pParent;
44
0
        }
45
0
    }
46
47
    // Closing extras
48
0
    *static_cast<SmMlElement**>(aData) = aCopyTree;
49
0
}
50
51
void SmMlIteratorFree(SmMlElement* pMlElementTree)
52
19.3k
{
53
19.3k
    if (pMlElementTree == nullptr)
54
19.3k
        return;
55
0
    for (size_t i = 0; i < pMlElementTree->getSubElementsCount(); ++i)
56
0
    {
57
0
        SmMlIteratorFree(pMlElementTree->getSubElement(i));
58
0
    }
59
0
    delete pMlElementTree;
60
0
}
61
62
SmMlElement* SmMlIteratorCopy(SmMlElement* pMlElementTree)
63
0
{
64
0
    if (pMlElementTree == nullptr)
65
0
        return nullptr;
66
0
    SmMlElement* aDummyElement = new SmMlElement();
67
0
    SmMlIteratorTopToBottom(pMlElementTree, cloneElement, &aDummyElement);
68
0
    SmMlElement* aResultElement = aDummyElement->getSubElement(0);
69
0
    delete aDummyElement;
70
0
    return aResultElement;
71
0
}
72
73
} // end namespace mathml
74
75
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */