tng 2003/01/16 11:10:41 Modified: c/src/xercesc/dom/impl DOMDocumentImpl.cpp DOMDocumentImpl.hpp DOMNodeIteratorImpl.cpp DOMNodeIteratorImpl.hpp DOMParentNode.cpp Log: DOM Fix: iterator should be updated when a node is removed from the dom tree Revision Changes Path 1.29 +44 -2 xml-xerces/c/src/xercesc/dom/impl/DOMDocumentImpl.cpp Index: DOMDocumentImpl.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMDocumentImpl.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- DOMDocumentImpl.cpp 20 Dec 2002 22:10:58 -0000 1.28 +++ DOMDocumentImpl.cpp 16 Jan 2003 19:10:41 -0000 1.29 @@ -118,6 +118,7 @@ fNamePool(0), fNodeIDMap(0), fRanges(0), + fNodeIterators(0), fChanges(0), fNodeListPool(0), fActualEncoding(0), @@ -148,6 +149,7 @@ fNamePool(0), fNodeIDMap(0), fRanges(0), + fNodeIterators(0), fChanges(0), fNodeListPool(0), fActualEncoding(0), @@ -207,6 +209,9 @@ if (fRanges) fRanges->cleanup(); + if (fNodeIterators) + fNodeIterators->cleanup(); + if (fUserDataTable) fUserDataTable->cleanup(); @@ -386,12 +391,49 @@ DOMNodeIterator* DOMDocumentImpl::createNodeIterator ( DOMNode *root, unsigned long whatToShow, DOMNodeFilter* filter, bool entityReferenceExpansion) { - return new (this) DOMNodeIteratorImpl(root, whatToShow, filter, entityReferenceExpansion); + if (!root) { + throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0); + return 0; + } + + DOMNodeIteratorImpl* nodeIterator = new (this) DOMNodeIteratorImpl(this, root, whatToShow, filter, entityReferenceExpansion); + + if (fNodeIterators == 0L) { + fNodeIterators = new (this) NodeIterators(1, false); + } + fNodeIterators->addElement(nodeIterator); + + return nodeIterator; } +NodeIterators* DOMDocumentImpl::getNodeIterators() const +{ + return fNodeIterators; +} + +void DOMDocumentImpl::removeNodeIterator(DOMNodeIteratorImpl* nodeIterator) +{ + if (fNodeIterators != 0) { + XMLSize_t sz = fNodeIterators->size(); + if (sz !=0) { + for (XMLSize_t i =0; i<sz; i++) { + if (fNodeIterators->elementAt(i) == nodeIterator) { + fNodeIterators->removeElementAt(i); + break; + } + } + } + } +} + DOMTreeWalker* DOMDocumentImpl::createTreeWalker (DOMNode *root, unsigned long whatToShow, DOMNodeFilter* filter, bool entityReferenceExpansion) { + if (!root) { + throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0); + return 0; + } + return new (this) DOMTreeWalkerImpl(root, whatToShow, filter, entityReferenceExpansion); } 1.14 +5 -1 xml-xerces/c/src/xercesc/dom/impl/DOMDocumentImpl.hpp Index: DOMDocumentImpl.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMDocumentImpl.hpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- DOMDocumentImpl.hpp 20 Dec 2002 22:10:58 -0000 1.13 +++ DOMDocumentImpl.hpp 16 Jan 2003 19:10:41 -0000 1.14 @@ -112,6 +112,7 @@ class DOMBuffer; typedef RefVectorOf<DOMRangeImpl> Ranges; +typedef RefVectorOf<DOMNodeIteratorImpl> NodeIterators; typedef KeyRefPair<void, DOMUserDataHandler> DOMUserDataRecord; typedef RefHashTableOf<DOMUserDataRecord> DOMNodeUserDataTable; typedef RefStackOf<DOMNode> DOMNodePtr; @@ -190,7 +191,9 @@ virtual DOMRange* createRange(); virtual Ranges* getRanges() const; //non-standard api + virtual NodeIterators* getNodeIterators() const; //non-standard api virtual void removeRange(DOMRangeImpl* range); //non-standard api + virtual void removeNodeIterator(DOMNodeIteratorImpl* nodeIterator); //non-standard api // @@ -367,6 +370,7 @@ DOMStringPool* fNamePool; Ranges* fRanges; + NodeIterators* fNodeIterators; int fChanges; bool errorChecking; // Bypass error checking. 1.5 +20 -22 xml-xerces/c/src/xercesc/dom/impl/DOMNodeIteratorImpl.cpp Index: DOMNodeIteratorImpl.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMNodeIteratorImpl.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DOMNodeIteratorImpl.cpp 4 Nov 2002 15:07:34 -0000 1.4 +++ DOMNodeIteratorImpl.cpp 16 Jan 2003 19:10:41 -0000 1.5 @@ -75,25 +75,7 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -DOMNodeIteratorImpl::DOMNodeIteratorImpl () -: fDetached(false), - fNodeFilter(0) -{ -} - -DOMNodeIteratorImpl::~DOMNodeIteratorImpl () -{ - fDetached = false; -} - - -void DOMNodeIteratorImpl::detach () -{ - fDetached = true; -} - - -DOMNodeIteratorImpl::DOMNodeIteratorImpl ( +DOMNodeIteratorImpl::DOMNodeIteratorImpl (DOMDocument* doc, DOMNode* root, unsigned long whatToShow, DOMNodeFilter* nodeFilter, @@ -104,7 +86,8 @@ fWhatToShow(whatToShow), fNodeFilter(nodeFilter), fForward(true), - fExpandEntityReferences(expandEntityRef) + fExpandEntityReferences(expandEntityRef), + fDocument(doc) { } @@ -117,7 +100,8 @@ fWhatToShow(toCopy.fWhatToShow), fNodeFilter(toCopy.fNodeFilter), fForward(toCopy.fForward), - fExpandEntityReferences(toCopy.fExpandEntityReferences) + fExpandEntityReferences(toCopy.fExpandEntityReferences), + fDocument(toCopy.fDocument) { } @@ -130,8 +114,22 @@ fForward = other.fForward; fDetached = other.fDetached; fExpandEntityReferences = other.fExpandEntityReferences; + fDocument = other.fDocument; return *this; } + +DOMNodeIteratorImpl::~DOMNodeIteratorImpl () +{ + fDetached = false; +} + + +void DOMNodeIteratorImpl::detach () +{ + fDetached = true; + ((DOMDocumentImpl *)fDocument)->removeNodeIterator(this); +} + DOMNode* DOMNodeIteratorImpl::getRoot() { return fRoot; 1.4 +6 -5 xml-xerces/c/src/xercesc/dom/impl/DOMNodeIteratorImpl.hpp Index: DOMNodeIteratorImpl.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMNodeIteratorImpl.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DOMNodeIteratorImpl.hpp 4 Nov 2002 15:07:34 -0000 1.3 +++ DOMNodeIteratorImpl.hpp 16 Jan 2003 19:10:41 -0000 1.4 @@ -88,6 +88,9 @@ // The root. DOMNode* fRoot; + // The Document used to create this iterator + DOMDocument* fDocument; + // The whatToShow mask. unsigned long fWhatToShow; @@ -120,12 +123,10 @@ // </pre> bool fForward; - protected: - DOMNodeIteratorImpl (); - public: virtual ~DOMNodeIteratorImpl (); DOMNodeIteratorImpl ( + DOMDocument* fDocument, DOMNode* root, unsigned long whatToShow, DOMNodeFilter* nodeFilter, @@ -145,12 +146,12 @@ virtual void detach (); virtual void release(); + void removeNode (DOMNode* node); private: DOMNode* matchNodeOrParent (DOMNode* node); DOMNode* nextNode (DOMNode* node, bool visitChildren); DOMNode* previousNode (DOMNode* node); - void removeNode (DOMNode* node); bool acceptNode (DOMNode* node); }; 1.11 +15 -2 xml-xerces/c/src/xercesc/dom/impl/DOMParentNode.cpp Index: DOMParentNode.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMParentNode.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- DOMParentNode.cpp 4 Nov 2002 15:07:34 -0000 1.10 +++ DOMParentNode.cpp 16 Jan 2003 19:10:41 -0000 1.11 @@ -65,6 +65,7 @@ #include "DOMDocumentImpl.hpp" #include "DOMNodeListImpl.hpp" #include "DOMRangeImpl.hpp" +#include "DOMNodeIteratorImpl.hpp" #include "DOMParentNode.hpp" #include "DOMCasts.hpp" @@ -310,8 +311,20 @@ if (oldChild != 0 && oldChild->getParentNode() != castToNode(this)) throw DOMException(DOMException::NOT_FOUND_ERR, 0); - //fix other ranges for change before deleting the node if (this->getOwnerDocument() != 0 ) { + //notify iterators + NodeIterators* nodeIterators = ((DOMDocumentImpl *)this->getOwnerDocument())->getNodeIterators(); + if (nodeIterators != 0) { + XMLSize_t sz = nodeIterators->size(); + if (sz != 0) { + for (XMLSize_t i =0; i<sz; i++) { + if (nodeIterators->elementAt(i) != 0) + nodeIterators->elementAt(i)->removeNode(oldChild); + } + } + } + + //fix other ranges for change before deleting the node Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges(); if (ranges != 0) { XMLSize_t sz = ranges->size();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]