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;
|
byte level() const;
|
||||||
ImplementationType* parent();
|
ImplementationType* parent();
|
||||||
const ImplementationType* parent() const;
|
const ImplementationType* parent() const;
|
||||||
|
ImplementationType* parent(byte n);
|
||||||
|
const ImplementationType* parent(byte n) const;
|
||||||
ImplementationType* nextSibling();
|
ImplementationType* nextSibling();
|
||||||
const ImplementationType* nextSibling() const;
|
const ImplementationType* nextSibling() const;
|
||||||
ImplementationType* firstChild();
|
ImplementationType* firstChild();
|
||||||
|
@ -473,6 +475,32 @@ inline const ImplementationType *GenericFileElement<ImplementationType>::parent(
|
||||||
return m_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.
|
* \brief Returns the next sibling of the element.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue