android: Update app-specific/MIME type icons
[LibreOffice.git] / starmath / inc / mathml / iterator.hxx
blob559829ce82f1a96c2b6deb1a5c078853e81e1a6d
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.
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 */
10 #pragma once
12 #include "element.hxx"
14 /** The purpose of this iterator is to be able to iterate threw an infinite element tree
15 * infinite -> as much as your memory can hold
16 * No call-backs that will end up in out of stack
19 namespace mathml
21 template <typename runType>
22 void SmMlIteratorBottomToTop(SmMlElement* pMlElementTree, runType aRunType, void* aData)
24 if (pMlElementTree == nullptr)
25 return;
27 SmMlElement* pCurrent;
29 // Fetch the deepest element
30 pCurrent = pMlElementTree;
31 while (pCurrent->getSubElementsCount() != 0)
33 if (pCurrent->getSubElement(0) == nullptr)
34 break;
35 pCurrent = pCurrent->getSubElement(0);
40 // Fetch next element
41 size_t nId = pCurrent->getSubElementId();
42 // We are back to the top.
43 if (pCurrent->getParentElement() == nullptr)
44 break;
45 // If this was the last, then turn back to the parent
46 if (nId + 1 == pCurrent->getParentElement()->getSubElementsCount())
47 pCurrent = pCurrent->getParentElement();
48 else // If not, next is the one near it
50 // It could have sub elements
51 if (pCurrent->getParentElement()->getSubElement(nId + 1) == nullptr)
52 break;
53 pCurrent = pCurrent->getParentElement()->getSubElement(nId + 1);
54 // Fetch the deepest element
55 while (pCurrent->getSubElementsCount() != 0)
57 if (pCurrent->getSubElement(0) == nullptr)
58 break;
59 pCurrent = pCurrent->getSubElement(0);
63 // Just in case of, but should be forbidden
64 if (pCurrent != nullptr)
65 aRunType(pCurrent, aData);
67 } while (pCurrent != nullptr);
70 template <typename runType>
71 void SmMlIteratorTopToBottom(SmMlElement* pMlElementTree, runType aRunType, void* aData)
73 if (pMlElementTree == nullptr)
74 return;
76 SmMlElement* pCurrent;
78 // Fetch the deepest element
79 pCurrent = pMlElementTree;
80 aRunType(pCurrent, aData);
81 while (pCurrent->getSubElementsCount() != 0)
83 if (pCurrent->getSubElement(0) == nullptr)
84 break;
85 pCurrent = pCurrent->getSubElement(0);
86 aRunType(pCurrent, aData);
91 // Fetch next element
92 size_t nId = pCurrent->getSubElementId();
93 // We are back to the top.
94 if (pCurrent->getParentElement() == nullptr)
95 break;
96 // If this was the last, then turn back to the parent
97 if (nId + 1 == pCurrent->getParentElement()->getSubElementsCount())
98 pCurrent = pCurrent->getParentElement();
99 else // If not, next is the one near it
101 // It could have sub elements
102 if (pCurrent->getParentElement()->getSubElement(nId + 1) == nullptr)
103 break;
104 pCurrent = pCurrent->getParentElement()->getSubElement(nId + 1);
105 aRunType(pCurrent, aData);
106 // Fetch the deepest element
107 while (pCurrent->getSubElementsCount() != 0)
109 if (pCurrent->getSubElement(0) == nullptr)
110 break;
111 pCurrent = pCurrent->getSubElement(0);
112 aRunType(pCurrent, aData);
116 } while (pCurrent != nullptr);
119 void SmMlIteratorFree(SmMlElement* pMlElementTree);
121 SmMlElement* SmMlIteratorCopy(SmMlElement* pMlElementTree);
123 } // end namespace mathml
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */