Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / starmath / source / mathml / element.cxx
blob4f8f2a64ff953fee217ee2415ebe30aea0429de5
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/element.hxx>
12 void SmMlElement::SmImplAttributeType()
14 switch (m_aElementType)
16 case SmMlElementType::NMlEmpty:
17 m_aAttributePosList = std::vector<SmMlAttributePos>(0);
18 break;
19 case SmMlElementType::NMlStructural:
20 m_aAttributePosList = std::vector<SmMlAttributePos>(0);
21 break;
22 case SmMlElementType::NMlSmNode:
23 m_aAttributePosList = std::vector<SmMlAttributePos>(0);
24 break;
25 case SmMlElementType::MlMath:
26 m_aAttributePosList = std::vector<SmMlAttributePos>(0);
27 //m_aAttributePosList = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMath), std::end(starmathdatabase::MlAttributeListMath));
28 break;
29 case SmMlElementType::MlMi:
30 m_aAttributePosList
31 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMi),
32 std::end(starmathdatabase::MlAttributeListMi));
33 break;
34 case SmMlElementType::MlMerror:
35 m_aAttributePosList
36 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMerror),
37 std::end(starmathdatabase::MlAttributeListMerror));
38 break;
39 case SmMlElementType::MlMn:
40 m_aAttributePosList
41 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMn),
42 std::end(starmathdatabase::MlAttributeListMn));
43 break;
44 case SmMlElementType::MlMo:
45 m_aAttributePosList
46 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMo),
47 std::end(starmathdatabase::MlAttributeListMo));
48 break;
49 case SmMlElementType::MlMrow:
50 m_aAttributePosList
51 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMrow),
52 std::end(starmathdatabase::MlAttributeListMrow));
53 break;
54 case SmMlElementType::MlMtext:
55 m_aAttributePosList
56 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMtext),
57 std::end(starmathdatabase::MlAttributeListMtext));
58 break;
59 case SmMlElementType::MlMstyle:
60 m_aAttributePosList
61 = std::vector<SmMlAttributePos>(std::begin(starmathdatabase::MlAttributeListMstyle),
62 std::end(starmathdatabase::MlAttributeListMstyle));
63 break;
64 default:
65 break;
67 // Create attribute vector with given pattern
68 m_aAttributeList = starmathdatabase::makeMlAttributeList(m_aAttributePosList);
71 SmMlAttribute SmMlElement::getAttribute(SmMlAttributeValueType aAttributeType) const
73 // Look for the attribute position and return if exists
74 for (size_t i = 0; i < m_aAttributePosList.size(); ++i)
76 if (m_aAttributePosList[i].m_aAttributeValueType == aAttributeType)
77 return m_aAttributeList[m_aAttributePosList[i].m_nPos];
79 return SmMlAttribute();
82 bool SmMlElement::isAttributeSet(SmMlAttributeValueType aAttributeType) const
84 // Look for the attribute position and return if exists
85 for (size_t i = 0; i < m_aAttributePosList.size(); ++i)
87 if (m_aAttributePosList[i].m_aAttributeValueType == aAttributeType)
88 return m_aAttributeList[m_aAttributePosList[i].m_nPos].isSet();
90 return false;
93 void SmMlElement::setAttribute(const SmMlAttribute* aAttribute)
95 // Look for the attribute position and assign if exists
96 for (size_t i = 0; i < m_aAttributePosList.size(); ++i)
98 if (m_aAttributePosList[i].m_aAttributeValueType == aAttribute->getMlAttributeValueType())
100 m_aAttributeList[m_aAttributePosList[i].m_nPos].setMlAttributeValue(aAttribute);
101 break;
106 void SmMlElement::setSubElement(size_t nPos, SmMlElement* aElement)
108 // This is the new parent element
109 aElement->setParentElement(this);
110 aElement->setSubElementId(nPos);
111 // Check if the vector is long enough
112 // Careful nOldSize can be 0 and -1 will underflow
113 // We must put something on the empty locations
114 size_t nOldSize = m_aSubElements.size();
115 if (nPos + 1 > nOldSize)
117 m_aSubElements.resize(nPos + 1);
118 for (; nOldSize < nPos; ++nOldSize)
119 m_aSubElements[nOldSize] = nullptr;
121 // Assign value
122 m_aSubElements[nPos] = aElement;
125 std::vector<SmMlAttribute>
126 starmathdatabase::makeMlAttributeList(std::vector<SmMlAttributePos> aAttributePosList)
128 std::vector<SmMlAttribute> aAttributeList(aAttributePosList.size());
129 for (size_t i = 0; i < aAttributePosList.size(); ++i)
131 aAttributeList[i].setMlAttributeValueType(aAttributePosList[i].m_aAttributeValueType);
133 return aAttributeList;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */