Add method to get last child of file element
This commit is contained in:
parent
bf31c9e89f
commit
fdb23e3cd0
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue