ElementChildIterator.h [plain text]
#pragma once
#include "ElementIterator.h"
namespace WebCore {
template<typename> class ElementChildRange;
template <typename ElementType> ElementChildRange<ElementType> childrenOfType(ContainerNode&);
template <typename ElementType> ElementChildRange<const ElementType> childrenOfType(const ContainerNode&);
template <typename ElementType>
class ElementChildIterator : public ElementIterator<ElementType> {
public:
ElementChildIterator() = default;
ElementChildIterator(const ContainerNode& parent, ElementType* current);
ElementChildIterator& operator--();
ElementChildIterator& operator++();
};
template <typename ElementType>
class ElementChildRange {
public:
ElementChildRange(const ContainerNode& parent);
ElementChildIterator<ElementType> begin() const;
static constexpr std::nullptr_t end() { return nullptr; }
ElementChildIterator<ElementType> beginAt(ElementType&) const;
ElementType* first() const;
ElementType* last() const;
private:
const ContainerNode& m_parent;
};
template <typename ElementType>
inline ElementChildIterator<ElementType>::ElementChildIterator(const ContainerNode& parent, ElementType* current)
: ElementIterator<ElementType>(&parent, current)
{
}
template <typename ElementType>
inline ElementChildIterator<ElementType>& ElementChildIterator<ElementType>::operator--()
{
ElementIterator<ElementType>::traversePreviousSibling();
return *this;
}
template <typename ElementType>
inline ElementChildIterator<ElementType>& ElementChildIterator<ElementType>::operator++()
{
ElementIterator<ElementType>::traverseNextSibling();
return *this;
}
template <typename ElementType>
inline ElementChildRange<ElementType>::ElementChildRange(const ContainerNode& parent)
: m_parent(parent)
{
}
template <typename ElementType>
inline ElementChildIterator<ElementType> ElementChildRange<ElementType>::begin() const
{
return ElementChildIterator<ElementType>(m_parent, Traversal<ElementType>::firstChild(m_parent));
}
template <typename ElementType>
inline ElementType* ElementChildRange<ElementType>::first() const
{
return Traversal<ElementType>::firstChild(m_parent);
}
template <typename ElementType>
inline ElementType* ElementChildRange<ElementType>::last() const
{
return Traversal<ElementType>::lastChild(m_parent);
}
template <typename ElementType>
inline ElementChildIterator<ElementType> ElementChildRange<ElementType>::beginAt(ElementType& child) const
{
ASSERT(child.parentNode() == &m_parent);
return ElementChildIterator<ElementType>(m_parent, &child);
}
template <typename ElementType>
inline ElementChildRange<ElementType> childrenOfType(ContainerNode& parent)
{
return ElementChildRange<ElementType>(parent);
}
template <typename ElementType>
inline ElementChildRange<const ElementType> childrenOfType(const ContainerNode& parent)
{
return ElementChildRange<const ElementType>(parent);
}
}