Add method to get last child of file element

This commit is contained in:
Martchus 2017-08-18 00:08:03 +02:00
parent 611ae0916a
commit 8e66378b81
1 changed files with 35 additions and 0 deletions

View File

@ -166,6 +166,8 @@ public:
const ImplementationType* nextSibling() const;
ImplementationType* firstChild();
const ImplementationType* firstChild() const;
ImplementationType* lastChild();
const ImplementationType* lastChild() const;
ImplementationType* subelementByPath(const std::initializer_list<IdentifierType> &path);
ImplementationType* subelementByPath(std::list<IdentifierType> &path);
ImplementationType* childById(const IdentifierType &id);
@ -557,6 +559,39 @@ inline const ImplementationType *GenericFileElement<ImplementationType>::firstCh
return m_firstChild.get();
}
/*!
* \brief Returns the last child of the element.
*
* The current element keeps ownership over the returned element.
* If no childs are present nullptr is returned.
*
* \remarks parse() needs to be called before.
*/
template <class ImplementationType>
inline ImplementationType *GenericFileElement<ImplementationType>::lastChild()
{
for(ImplementationType *child = firstChild(); child; child = child->nextSibling()) {
if(!child->m_nextSibling) {
return child;
}
}
return nullptr;
}
/*!
* \brief Returns the last child of the element.
*
* The current element keeps ownership over the returned element.
* If no childs are present nullptr is returned.
*
* \remarks parse() needs to be called before.
*/
template <class ImplementationType>
inline const ImplementationType *GenericFileElement<ImplementationType>::lastChild() const
{
return const_cast<GenericFileElement<ImplementationType> *>(this)->lastChild();
}
/*!
* \brief Returns the sub element for the specified \a path.
*