1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <mathml/element.hxx>
12 void SmMlElement::SmImplAttributeType()
14 switch (m_aElementType
)
16 case SmMlElementType::NMlEmpty
:
17 m_aAttributePosList
= std::vector
<SmMlAttributePos
>(0);
19 case SmMlElementType::NMlStructural
:
20 m_aAttributePosList
= std::vector
<SmMlAttributePos
>(0);
22 case SmMlElementType::NMlSmNode
:
23 m_aAttributePosList
= std::vector
<SmMlAttributePos
>(0);
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));
29 case SmMlElementType::MlMi
:
31 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMi
),
32 std::end(starmathdatabase::MlAttributeListMi
));
34 case SmMlElementType::MlMerror
:
36 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMerror
),
37 std::end(starmathdatabase::MlAttributeListMerror
));
39 case SmMlElementType::MlMn
:
41 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMn
),
42 std::end(starmathdatabase::MlAttributeListMn
));
44 case SmMlElementType::MlMo
:
46 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMo
),
47 std::end(starmathdatabase::MlAttributeListMo
));
49 case SmMlElementType::MlMrow
:
51 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMrow
),
52 std::end(starmathdatabase::MlAttributeListMrow
));
54 case SmMlElementType::MlMtext
:
56 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMtext
),
57 std::end(starmathdatabase::MlAttributeListMtext
));
59 case SmMlElementType::MlMstyle
:
61 = std::vector
<SmMlAttributePos
>(std::begin(starmathdatabase::MlAttributeListMstyle
),
62 std::end(starmathdatabase::MlAttributeListMstyle
));
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();
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
);
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;
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: */