Add methods to get n-th parent of file element
This commit is contained in:
parent
4231f2679e
commit
bf31c9e89f
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue