ParentNode.h 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <LibHTML/DOM/Node.h>
  3. class ParentNode : public Node {
  4. public:
  5. void append_child(Retained<Node>);
  6. Node* first_child() { return m_first_child; }
  7. Node* last_child() { return m_last_child; }
  8. const Node* first_child() const { return m_first_child; }
  9. const Node* last_child() const { return m_last_child; }
  10. template<typename F> void for_each_child(F) const;
  11. template<typename F> void for_each_child(F);
  12. protected:
  13. explicit ParentNode(NodeType type)
  14. : Node(type)
  15. {
  16. }
  17. private:
  18. Node* m_first_child { nullptr };
  19. Node* m_last_child { nullptr };
  20. };
  21. template<typename Callback>
  22. inline void ParentNode::for_each_child(Callback callback) const
  23. {
  24. for (auto* node = first_child(); node; node = node->next_sibling())
  25. callback(*node);
  26. }
  27. template<typename Callback>
  28. inline void ParentNode::for_each_child(Callback callback)
  29. {
  30. for (auto* node = first_child(); node; node = node->next_sibling())
  31. callback(*node);
  32. }