Add methods to get n-th parent of file element

This commit is contained in:
Martchus 2017-08-18 00:07:42 +02:00
parent 90dccb2bd9
commit 611ae0916a
1 changed files with 28 additions and 0 deletions

View File

@ -160,6 +160,8 @@ public:
byte level() const;
ImplementationType* parent();
const ImplementationType* parent() const;
ImplementationType* parent(byte n);
const ImplementationType* parent(byte n) const;
ImplementationType* nextSibling();
const ImplementationType* nextSibling() const;
ImplementationType* firstChild();
@ -473,6 +475,32 @@ inline const ImplementationType *GenericFileElement<ImplementationType>::parent(
return m_parent;
}
/*!
* \brief Returns the n-th parent of the element.
* \remarks
* - The returned element has ownership (at least indirect) over the current instance.
* - Returns nullptr if level() < \a n.
*/
template <class ImplementationType>
ImplementationType *GenericFileElement<ImplementationType>::parent(byte n)
{
ImplementationType *parent = static_cast<ImplementationType *>(this);
for(; n && parent; --n, parent = parent->m_parent);
return parent;
}
/*!
* \brief Returns the n-th parent of the element.
* \remarks
* - The returned element has ownership (at least indirect) over the current instance.
* - Returns nullptr if level() < \a n.
*/
template <class ImplementationType>
inline const ImplementationType *GenericFileElement<ImplementationType>::parent(byte n) const
{
return const_cast<GenericFileElement<ImplementationType> *>(this)->parent(n);
}
/*!
* \brief Returns the next sibling of the element.
*