I have a for loop that iterates through an XML document and finds a specified attribute, the pointer that points to the current node sits inside a boost::interprocess::unique_ptr and has a custom deletor to call the object's release()
function. It seems that on every loop iteration the pointer gets deleted, but the release()
function throws when that happens.
Could anyone suggest a solution? I thought about implementing a mechanism to check if it should be deleted, but I'm not sure how I'd do that...
Code:
typedef bi::unique_ptr<DOMNodeIterator, release_deleter> iterator_ptr;
typedef bi::unique_ptr<DOMNode, release_deleter> node_ptr;
iterator_ptr itera(document->createNodeIterator(rootelement, DOMNodeFilter::SHOW_ALL, NULL, true));
for(node_ptr current(itera->nextNode()); current != 0; current.reset(itera->nextNode())) // throws after one iteration...
{
....
objects release()
void DOMElementNSImpl::release()
{
if (fNode.isOwned() && !fNode.isToBeReleased())
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager); // throws here if released after each loop iteration
DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
if (doc) {
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
fParent.release();
doc->release(this, DOMMemoryManager::ELEMENT_NS_OBJECT);
}
else {
// shouldn't reach here
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
}
}
deleter:
struct release_deleter
{
template <typename T>
void operator()(T* pPtr) const
{
pPtr->release();
}
};
EDIT:
virtual DOMNodeIterator *createNodeIterator(DOMNode* root,
DOMNodeFilter::ShowType whatToShow,
DOMNodeFilter* filter,
bool entityReferenceExpansion) = 0;
virtual DOMNode* nextNode() = 0;