Added invalidate_document_order, now detaching deleted nodes and setting name/value to 0 after deleting (less bugs/debugging confusion)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@110 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
bf160df125
commit
0949bd80b6
@ -140,8 +140,19 @@ namespace pugi
|
||||
|
||||
void destroy()
|
||||
{
|
||||
if (!name_insitu) delete[] name;
|
||||
if (!value_insitu) delete[] value;
|
||||
parent = 0;
|
||||
|
||||
if (!name_insitu)
|
||||
{
|
||||
delete[] name;
|
||||
name = 0;
|
||||
}
|
||||
|
||||
if (!value_insitu)
|
||||
{
|
||||
delete[] value;
|
||||
value = 0;
|
||||
}
|
||||
|
||||
for (xml_attribute_struct* attr = first_attribute; attr; attr = attr->next_attribute)
|
||||
attr->destroy();
|
||||
@ -2584,7 +2595,7 @@ namespace pugi
|
||||
return empty() ? 0 : _root->document_order;
|
||||
}
|
||||
|
||||
void xml_node::precompute_document_order_impl()
|
||||
void xml_node::precompute_document_order_impl(unsigned int mask)
|
||||
{
|
||||
if (type() != node_document) return;
|
||||
|
||||
@ -2593,10 +2604,10 @@ namespace pugi
|
||||
|
||||
for (;;)
|
||||
{
|
||||
cur._root->document_order = current++;
|
||||
cur._root->document_order = mask & current++;
|
||||
|
||||
for (xml_attribute a = cur.first_attribute(); a; a = a.next_attribute())
|
||||
a._attr->document_order = current++;
|
||||
a._attr->document_order = mask & current++;
|
||||
|
||||
if (cur.first_child())
|
||||
cur = cur.first_child();
|
||||
@ -2976,9 +2987,14 @@ namespace pugi
|
||||
|
||||
void xml_document::precompute_document_order()
|
||||
{
|
||||
precompute_document_order_impl();
|
||||
precompute_document_order_impl(~0u);
|
||||
}
|
||||
|
||||
void xml_document::invalidate_document_order()
|
||||
{
|
||||
precompute_document_order_impl(0);
|
||||
}
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
std::string as_utf8(const wchar_t* str)
|
||||
{
|
||||
|
||||
@ -621,7 +621,7 @@ namespace pugi
|
||||
explicit xml_node(xml_node_struct* p);
|
||||
|
||||
/// \internal Precompute document order (valid only for document node)
|
||||
void precompute_document_order_impl();
|
||||
void precompute_document_order_impl(unsigned int mask);
|
||||
|
||||
/// \internal Get allocator
|
||||
xml_allocator& get_allocator() const;
|
||||
@ -1600,6 +1600,13 @@ namespace pugi
|
||||
* Sometimes this makes evaluation of XPath queries faster.
|
||||
*/
|
||||
void precompute_document_order();
|
||||
|
||||
/**
|
||||
* Invalidate document order for the whole tree
|
||||
* If you precomputed document order for the tree and inserted new nodes/attributes after that,
|
||||
* XPath queries will sometimes give incorrect results.
|
||||
*/
|
||||
void invalidate_document_order();
|
||||
};
|
||||
|
||||
#ifndef PUGIXML_NO_XPATH
|
||||
|
||||
Loading…
Reference in New Issue
Block a user