docthemes: Save themes def. to a file when added to ColorSets
[LibreOffice.git] / starmath / source / mathml / iterator.cxx
blobfa19f11b019b6dd4d37ec8ec86983b0bcbb5ba93
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 #include <mathml/iterator.hxx>
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
17 namespace mathml
19 static inline void cloneElement(SmMlElement* aSmMlElement, void* aData)
21 // Prepare data
22 SmMlElement* aNewSmMlElement = new SmMlElement(*aSmMlElement);
23 SmMlElement* aCopyTree = *static_cast<SmMlElement**>(aData);
25 // Append data
26 aCopyTree->setSubElement(aCopyTree->getSubElementsCount(), aNewSmMlElement);
28 // Prepare for following
29 // If it has sub elements, then it will be the next
30 if (aSmMlElement->getSubElementsCount() != 0)
31 aCopyTree = aNewSmMlElement;
32 else // Otherwise remounts up to where it should be
34 while (aSmMlElement->getParentElement() != nullptr)
36 // get parent
37 SmMlElement* pParent = aSmMlElement->getParentElement();
38 aCopyTree = aCopyTree->getParentElement();
39 // was this the last branch ?
40 if (aSmMlElement->getSubElementId() + 1 != pParent->getSubElementsCount())
41 break; // no -> stop going up
42 // Prepare for next round
43 aSmMlElement = pParent;
47 // Closing extras
48 *static_cast<SmMlElement**>(aData) = aCopyTree;
51 void SmMlIteratorFree(SmMlElement* pMlElementTree)
53 if (pMlElementTree == nullptr)
54 return;
55 for (size_t i = 0; i < pMlElementTree->getSubElementsCount(); ++i)
57 SmMlIteratorFree(pMlElementTree->getSubElement(i));
59 delete pMlElementTree;
62 SmMlElement* SmMlIteratorCopy(SmMlElement* pMlElementTree)
64 if (pMlElementTree == nullptr)
65 return nullptr;
66 SmMlElement* aDummyElement = new SmMlElement();
67 SmMlIteratorTopToBottom(pMlElementTree, cloneElement, &aDummyElement);
68 SmMlElement* aResultElement = aDummyElement->getSubElement(0);
69 delete aDummyElement;
70 return aResultElement;
73 } // end namespace mathml
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */