NodeIterator.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // NodeIterator.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: NodeIterator
  7. //
  8. // Definition of the DOM NodeIterator class.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef DOM_NodeIterator_INCLUDED
  16. #define DOM_NodeIterator_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. namespace Poco {
  19. namespace XML {
  20. class Node;
  21. class NodeFilter;
  22. class XML_API NodeIterator
  23. /// Iterators are used to step through a set of nodes, e.g. the set of nodes
  24. /// in a NodeList, the document subtree governed by a particular Node, the results
  25. /// of a query, or any other set of nodes. The set of nodes to be iterated is
  26. /// determined by the implementation of the NodeIterator. DOM Level 2 specifies
  27. /// a single NodeIterator implementation for document-order traversal of a document
  28. /// subtree.
  29. ///
  30. /// A NodeIterator can be directly instantiated using one of its constructors -
  31. /// the DocumentTraversal interface is not needed and therefore not implemented.
  32. /// Unlike most other DOM classes, NodeIterator supports value semantics.
  33. ///
  34. /// If the NodeIterator's current node is removed from the document, the
  35. /// result of calling any of the movement methods is undefined. This behavior does
  36. /// not conform to the DOM Level 2 Traversal specification.
  37. {
  38. public:
  39. NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter = 0);
  40. /// Creates a NodeIterator over the subtree rooted at the specified node.
  41. NodeIterator(const NodeIterator& iterator);
  42. /// Creates a NodeIterator by copying another NodeIterator.
  43. NodeIterator& operator = (const NodeIterator& iterator);
  44. /// Assignment operator.
  45. ~NodeIterator();
  46. /// Destroys the NodeIterator.
  47. Node* root() const;
  48. /// The root node of the NodeIterator, as specified when it was created.
  49. unsigned long whatToShow() const;
  50. /// This attribute determines which node types are presented via the iterator.
  51. /// The available set of constants is defined in the NodeFilter interface.
  52. /// Nodes not accepted by whatToShow will be skipped, but their children may
  53. /// still be considered. Note that this skip takes precedence over the filter,
  54. /// if any.
  55. NodeFilter* filter() const;
  56. /// The NodeFilter used to screen nodes.
  57. bool expandEntityReferences() const;
  58. /// The value of this flag determines whether the children of entity reference
  59. /// nodes are visible to the iterator. If false, they and their descendants
  60. /// will be rejected. Note that this rejection takes precedence over whatToShow
  61. /// and the filter. Also note that this is currently the only situation where
  62. /// NodeIterators may reject a complete subtree rather than skipping individual
  63. /// nodes.
  64. ///
  65. /// To produce a view of the document that has entity references expanded and
  66. /// does not expose the entity reference node itself, use the whatToShow flags
  67. /// to hide the entity reference node and set expandEntityReferences to true
  68. /// when creating the iterator. To produce a view of the document that has entity
  69. /// reference nodes but no entity expansion, use the whatToShow flags to show
  70. /// the entity reference node and set expandEntityReferences to false.
  71. ///
  72. /// This implementation does not support entity reference expansion and
  73. /// thus always returns false.
  74. Node* nextNode();
  75. /// Returns the next node in the set and advances the position of the iterator
  76. /// in the set. After a NodeIterator is created, the first call to nextNode()
  77. /// returns the first node in the set.
  78. Node* previousNode();
  79. /// Returns the previous node in the set and moves the position of the NodeIterator
  80. /// backwards in the set.
  81. Node* currentNodeNP() const;
  82. /// Returns the current node in the set.
  83. ///
  84. /// Leaves the NodeIterator unchanged.
  85. ///
  86. /// Warning: This is a proprietary extension to the DOM Level 2 NodeIterator
  87. /// interface.
  88. void detach();
  89. /// Detaches the NodeIterator from the set which it iterated over, releasing
  90. /// any computational resources and placing the iterator in the INVALID state.
  91. /// After detach has been invoked, calls to nextNode or previousNode will raise
  92. /// the exception INVALID_STATE_ERR.
  93. protected:
  94. bool accept(Node* pNode) const;
  95. Node* next() const;
  96. Node* previous() const;
  97. Node* last();
  98. private:
  99. NodeIterator();
  100. Node* _pRoot;
  101. unsigned long _whatToShow;
  102. NodeFilter* _pFilter;
  103. Node* _pCurrent;
  104. };
  105. //
  106. // inlines
  107. //
  108. inline Node* NodeIterator::root() const
  109. {
  110. return _pRoot;
  111. }
  112. inline Node* NodeIterator::currentNodeNP() const
  113. {
  114. return _pCurrent;
  115. }
  116. inline unsigned long NodeIterator::whatToShow() const
  117. {
  118. return _whatToShow;
  119. }
  120. inline NodeFilter* NodeIterator::filter() const
  121. {
  122. return _pFilter;
  123. }
  124. inline bool NodeIterator::expandEntityReferences() const
  125. {
  126. return false;
  127. }
  128. } } // namespace Poco::XML
  129. #endif // DOM_NodeIterator_INCLUDED