Enhanced C#
Language of your choice: library documentation
Public Member Functions | List of all members
Loyc.Collections.Impl.IAListTreeObserver< K, T > Interface Template Reference

An interface that is called to notify observers when items or nodes in the tree of a class derived from AListBase<K,T> (e.g. AList or BList) are added or removed. More...


Source file:
Inheritance diagram for Loyc.Collections.Impl.IAListTreeObserver< K, T >:
Loyc.Collections.AListBase< K, T >.ObserverMgr Loyc.Collections.Impl.AListIndexer< K, T >

Remarks

An interface that is called to notify observers when items or nodes in the tree of a class derived from AListBase<K,T> (e.g. AList or BList) are added or removed.

Template Parameters
K
T

This interface is useful for keeping track of information about a collection that is impossible to track efficiently by any other means. It can be used to:

An observer object should be attached to only one list, because change notifications do not indicate which list is being changed.

When an A-list is cloned, observers do are not included in the clone.

IMPORTANT: unless otherwise noted, implementations of this interface must not throw exceptions because these methods are called during operations in progress. If you throw an exception, the tree can be left in an invalid state. Attach() can safety throw, but the exception will propagate out of the AListBase<K,T>.AddObserver method.

Public Member Functions

void Attach (AListBase< K, T > list, Action< bool > populate)
 Called when the observer is being attached to an AList. More...
 
void Detach ()
 Called when the observer is being detached from an AList. More...
 
void RootChanged (AListNode< K, T > newRoot, bool clear)
 Called when the root of the tree changes, or when the list is cleared. More...
 
void ItemAdded (T item, AListLeaf< K, T > parent)
 Called when an item is added to a leaf node. More...
 
void ItemRemoved (T item, AListLeaf< K, T > parent)
 Called when an item is removed from a leaf node. More...
 
void NodeAdded (AListNode< K, T > child, AListInnerBase< K, T > parent)
 Called when a child node is added to an inner node. More...
 
void NodeRemoved (AListNode< K, T > child, AListInnerBase< K, T > parent)
 Called when a child node is removed from an inner node. More...
 
void RemoveAll (AListNode< K, T > node)
 Called when all children are being removed from a node (leaf or inner). Notifications are not sent for individual children. More...
 
void AddAll (AListNode< K, T > node)
 Called when all children are being added to a node (leaf or inner). Notifications are not sent for individual children. More...
 
void CheckPoint ()
 Called when a tree modification operation is completed. More...
 

Member Function Documentation

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.AddAll ( AListNode< K, T >  node)

Called when all children are being added to a node (leaf or inner). Notifications are not sent for individual children.

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.Attach ( AListBase< K, T >  list,
Action< bool >  populate 
)

Called when the observer is being attached to an AList.

Parameters
listThe list that the observer is being attached to.
populateThe observer can invoke this delegate to cause notifications to be sent about all the nodes in the tree through a depth-first search that calls AddAll for each node in the tree. When calling this delegate, use a parameter of True if you want AddAll to be called for children before parents (roughly, leaves first). Use False if you want AddAll to be called for inner nodes before their children. populate() also calls RootChanged() before scanning the tree.

If Attach() throws an exception, AListBase<K,T> will cancel the AddObserver() operation and it will not catch the exception.

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

Called when a tree modification operation is completed.

This is called after each modification operation (Add, Insert, Remove, Replace, etc.); the list will normally be in a read-only state ("frozen for concurrency") when this method is called, so do not initiate changes from here.

This method can safely throw an exception, and the list class will not swallow it. Note: if there are multiple observers, throwing an exception from one observers will prevent this notification from reaching other observers that have not been notified yet.

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

Referenced by Loyc.Collections.AListBase< K, T >.AListBase().

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.ItemAdded ( item,
AListLeaf< K, T >  parent 
)

Called when an item is added to a leaf node.

Note: this may be called as part of a move operation (remove+add)

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.ItemRemoved ( item,
AListLeaf< K, T >  parent 
)

Called when an item is removed from a leaf node.

Note: this may be called as part of a move operation (remove+add)

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.NodeAdded ( AListNode< K, T >  child,
AListInnerBase< K, T >  parent 
)

Called when a child node is added to an inner node.

Note: this may be called as part of a move operation (remove+add)

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.NodeRemoved ( AListNode< K, T >  child,
AListInnerBase< K, T >  parent 
)

Called when a child node is removed from an inner node.

Note: this may be called as part of a move operation (remove+add)

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

Referenced by Loyc.Collections.Impl.AListInnerBase< int, T >.HandleUndersized().

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.RemoveAll ( AListNode< K, T >  node)

Called when all children are being removed from a node (leaf or inner). Notifications are not sent for individual children.

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

void Loyc.Collections.Impl.IAListTreeObserver< K, T >.RootChanged ( AListNode< K, T >  newRoot,
bool  clear 
)

Called when the root of the tree changes, or when the list is cleared.

Parameters
cleartrue if the root is changing due to a Clear() operation. If this parameter is true, the observer should clear its own state. If this parameter is false but newRoot is null, it means that the list was cleared by removing all the items (rather than by calling Clear() on the list). In that case, if the observer still believes that any items exist in leaf nodes, it means that there is a bookkeeping error somewhere.
newRootThe new root (null if the tree is cleared).

Implemented in Loyc.Collections.Impl.AListIndexer< K, T >, and Loyc.Collections.AListBase< K, T >.ObserverMgr.

Referenced by Loyc.Collections.AListBase< K, T >.AListBase().