Class Viserator<TItem, TState, TNode, TComponent>
A Viserator is a scene visitor which returns an enumerator of a user defined type. Serves as a base class for use-cases where traversing a node-component-graph should yield a list (enumerator) of results.
Inheritance
Implements
Inherited Members
Namespace: Fusee.Xene
Assembly: Fusee.Xene.dll
Syntax
public abstract class Viserator<TItem, TState, TNode, TComponent> : ViseratorBase<TItem, TNode, TComponent>, IEnumerator<TItem>, IEnumerator, IDisposable where TState : IStateStack, new()
where TNode : class, INode where TComponent : class, IComponent
Type Parameters
Name | Description |
---|---|
TItem | The type of the result yielded by the enumerator. |
TState | The type of the state to use during traversal. See VisitorState how to implement your own state type. |
TNode | The root type of nodes the trees passed to the constructor is built from. |
TComponent | The root type of components used in the given trees. |
Remarks
Very often you want to traverse a node-component-graph while maintaining a traversal state keeping track of individual values and their changes while traversing. At certain points during the traversal a result arises that should be promoted to the outside of the traversal. Typically the result is derived from the state at a certain time during traversal and some additional information of the tree object currently visited.
To implement your own Viserator you should consider which state information the Viserator must keep track of. Either you assemble your own State type by deriving from VisitorState or choose to use one of the standard state types like StandardState. Then you need to derive your own class from Viserator<TItem, TState, TNode, TComponent> with the TState replaced by your choice of State and TItem replaced by the type of the items you want your Viserator to yield during the traversal.
The word Viserator is a combination of a visitor and enumerator. Look up "to viscerate" in a dictionary and judge for yourself if a Viserator's operation resembles disemboweling the innards of a tree structure.
Constructors
Viserator()
Initializes a new instance of the Viserator<TItem, TState, TNode, TComponent> class.
Declaration
public Viserator()
Viserator(IEnumerable<TNode>)
Initializes a new instance of the Viserator<TItem, TState, TNode, TComponent> class.
Declaration
public Viserator(IEnumerable<TNode> rootList)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TNode> | rootList | The root list. |
Fields
State
The state to keep track of during traversal. You can use your own implementation (as long as it implements IStateStack or use one of the predefined implementations. See VisitorState how to implement your own state type.
Declaration
protected TState State
Field Value
Type | Description |
---|---|
TState |
Methods
Init(IEnumerable<TNode>)
Initializes this viserator using the specified root list.
Declaration
protected override void Init(IEnumerable<TNode> rootList)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TNode> | rootList | The tree to traverse. |
Overrides
InitState()
This method is called when traversal starts to initialize the traversal state. Override this method in derived classes to initialize any state beyond the standard State. Most visitors will simply initialize the State and will thus NOT need to override this method. Make sure to call the base implementation in overridden versions.
Declaration
protected override void InitState()
Overrides
PopState()
This method is called when going up one hierarchy level while traversing. Pops the traversal state stack State. Most visitors will simply perform pop on the State and will thus NOT need to override this method. Make sure to call the base implementation in overridden versions.
Declaration
protected override void PopState()
Overrides
PushState()
This method is called when going down one hierarchy level while traversing. Pushes the traversal state stack State. Most visitors will simply push the State and will thus NOT need to override this method. Make sure to call the base implementation in overridden versions.
Declaration
protected override void PushState()