GenericIndexIterator: Add node change helpers
Add NodeChangeBegin()/NodeChangeEnd() methods that can be used by the index when the respective node attribute has changed. They make sure that the iterator doesn't move with the node, should it be inserted into the index at a different position.
This commit is contained in:
parent
0209c404dc
commit
d56e19fb9e
@ -46,6 +46,9 @@ public:
|
||||
bool SetTo(Index* index, const Value& name,
|
||||
bool ignoreValue = false);
|
||||
|
||||
inline void NodeChangeBegin(Node* node);
|
||||
inline void NodeChangeEnd(Node* node);
|
||||
|
||||
virtual void NodeRemoved(Node* node);
|
||||
|
||||
protected:
|
||||
@ -160,6 +163,47 @@ GenericIndexIterator<Policy>::SetTo(Index* index, const Value& value,
|
||||
}
|
||||
|
||||
|
||||
/*! Moves the iterator temporarily off the current node.
|
||||
Called when the node the iterator currently points to has been modified and
|
||||
the index is about to remove it from and reinsert it into the tree. After
|
||||
having done that NodeChangeEnd() must be called.
|
||||
*/
|
||||
template<typename Policy>
|
||||
void
|
||||
GenericIndexIterator<Policy>::NodeChangeBegin(Node* node)
|
||||
{
|
||||
fNextTreeNode = Policy::GetNodeTree(fIndex)->Previous(fNextTreeNode);
|
||||
}
|
||||
|
||||
|
||||
/*! Brackets a NodeChangeBegin() call.
|
||||
*/
|
||||
template<typename Policy>
|
||||
void
|
||||
GenericIndexIterator<Policy>::NodeChangeEnd(Node* node)
|
||||
{
|
||||
if (fNextTreeNode != NULL) {
|
||||
fNextTreeNode = Policy::GetNodeTree(fIndex)->Next(fNextTreeNode);
|
||||
} else {
|
||||
typename NodeTree::Iterator iterator;
|
||||
Policy::GetNodeTree(fIndex)->GetIterator(&iterator);
|
||||
fNextTreeNode = iterator.CurrentNode();
|
||||
}
|
||||
|
||||
// If the node is no longer the one we originally pointed to, re-register
|
||||
// the node listener.
|
||||
if (fNextTreeNode == NULL) {
|
||||
fIndex->GetVolume()->RemoveNodeListener(this);
|
||||
} else {
|
||||
Node* newNode = _ToNode();
|
||||
if (newNode != node) {
|
||||
fIndex->GetVolume()->RemoveNodeListener(this);
|
||||
fIndex->GetVolume()->AddNodeListener(this, newNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename Policy>
|
||||
void
|
||||
GenericIndexIterator<Policy>::NodeRemoved(Node* node)
|
||||
|
Loading…
x
Reference in New Issue
Block a user