ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Inner Classes | Public Methods | Protected Fields | Protected Methods | List of all members
StringTree< T >.Walker Class Reference
Collaboration diagram for StringTree< T >.Walker:
[legend]

Class Description


This public, inner class implements an iterator that does not apply to the concept of C# iterators. The rational for this is the fact that the class provides mechanics to sorting the child nodes, which requires allocation of quite more resources than a usual container iterator. Therefore objects of this type are not supposed to be passed around and copied on the fly. Instead, instances should rather created once and then re-used in subsequent iterations.

Sorting of child nodes can be done using a built-in comparison function which works on the child names (path names) and allows to choose ascending and descending order and to ignore letter case, respectively be sensitive about it. Besides this, a custom comparison function for child name based sorting can be established as well as a custom function used to sort by attributes of the custom template type T. See methods SortByPathname and SortByValue for details on sorting.

Objects of this type can initialized, respectively reset to distinct start nodes by providing objects of type

to overloaded methods SetStart. Then the iteration is performed with method Next and its end is detected with method IsValid. During iteration, method Skip stops the iteration of the current node and continues with its next sibling.

Recursiveness of iteration is controlled with method SetRecursionDepth.

Finally, the generation of a string representing the actual path to the current iteration node relative to the start node can be activated. See PathGeneration for information about this feature.

For more information on iterators see description of outer class StringTree.

Inner Classes

struct  NameAndNode
 
class  RecursionData
 
class  Sorter
 

Public Methods

 Walker (StringTree< T > _stringTree)
 
int Depth ()
 
Cursor GetCursor ()
 
AString GetPath (AString target, CurrentData targetData=CurrentData.Clear)
 
AString GetPathToNode ()
 
StringTree< T > GetStringTree ()
 
void Invalidate ()
 
bool IsInValid ()
 
bool IsValid ()
 
String Name ()
 
bool Next ()
 
void PathGeneration (Switch generatePath)
 
void SetRecursionDepth (int _recursionDepth)
 
void SetStart (Cursor cursor)
 
void SetStart (StringTree< T > pm)
 
void SetStart (Walker other)
 
void SetValue (T value)
 
int Size ()
 
void Skip ()
 
void SortByPathname (Comparison< String > pathSorter)
 
void SortByPathname (SortOrder order=SortOrder.Ascending, StringComparison comparison=StringComparison.CurrentCultureIgnoreCase)
 
void SortByValue (Comparison< T > valueSorter)
 
Value ()
 

Protected Fields

AString actPath = new AString()
 
int recursionDepth = int.MaxValue
 
Sorter sorter = new Sorter()
 
List< RecursionDatastack = new List<RecursionData>()
 
int stackSize = 0
 
StringTree< T > stringTree
 

Protected Methods

Node actNode ()
 
void setStart (StringTree< T >.Node newNode)
 

Constructor & Destructor Documentation

◆ Walker()

Walker ( StringTree< T >  _stringTree)
inline

Constructor

Parameters
_stringTreeThe StringTree we walk on.

Member Function Documentation

◆ actNode()

Node actNode ( )
inlineprotected

Internal method to identify the actual node.

Returns
Pointer to the node object that we currently represent.

◆ Depth()

int Depth ( )
inline

Returns the depth of the current iteration. This is value is available to the algorithm which means this method executes in constant time.

To get the absolute depth of the current node, use a combination of method GetCursor and Cursor.Depth.

Returns
The distance of the current node and the node of the start of the iteration.

◆ GetCursor()

Cursor GetCursor ( )
inline

Creates a cursor referencing the same node that this walker references.

Returns
A cursor object referencing the current node.

◆ GetPath()

AString GetPath ( AString  target,
CurrentData  targetData = CurrentData.Clear 
)
inline

Writes the results of GetPathToNode and Name, separated by a separator char.

Note that this method can be used only if path generation was activated prior to the current iteration. Activation is performed with method PathGeneration.

Parameters
targetThe target to append the path to.
targetDataDenotes whether target should be cleared prior to appending the path. Defaults to CurrentData.Clear.
Returns
The given string to allow concatenated operations

◆ GetPathToNode()

AString GetPathToNode ( )
inline

Retrieves the current path of walking as a string representation. The path returned is relative to the start node and does not contain a leading separator character. Also, it does not contain the name of the current node, which can be received with method Name.

Note that this method can be used only if path generation was activated prior to the current iteration. Activation is performed with method PathGeneration.

Note, that the AString returned must not be modified by the receiver.

Returns
The path of the current node.

◆ GetStringTree()

StringTree<T> GetStringTree ( )
inline

Return the StringTree we are working on.

Returns
The StringTree object.

◆ Invalidate()

void Invalidate ( )
inline

Invalidates this object. After invoking this method, this walker can not be used further, until SetStart is invoked. After the invocation, method IsValid will return false.

◆ IsInValid()

bool IsInValid ( )
inline

Returns the opposite of IsValid.

Returns
true if this is an invalid cursor that must not be used, false otherwise.

◆ IsValid()

bool IsValid ( )
inline

Determines if this is a valid walker. Walkers may become invalid after invocations of method Next at the end of the iteration and become valid with the invocation of one of the overloaded methods SetStart (when invoked with valid objects).

Returns
true if this is a valid cursor. If invalid, false is returned and the cursor must not be used.

◆ Name()

String Name ( )
inline

Returns the name of the node that this walker currently represents. The name of the node corresponds to the path segment or child name that was used to create it.

Note
Unlike method Cursor.SearchName which needs some effort to search the name of a node represented by a cursor, this method performs in constant time, as the current child name is made available during iteration.
Returns
The name of the represented node.

◆ Next()

bool Next ( )
inline

Goes to the next node.

Returns
The result of IsValid after the 'walk'.

◆ PathGeneration()

void PathGeneration ( Switch  generatePath)
inline

With this method, the generation of the actual path string is activated. The given character is used as separation character. The current path can be received using method GetPath.
The method must be invoked prior to start walking with method Next, otherwise undefined behavior might occur while 'walking'.

Parameters
generatePathDenotes whether the path should be generated or not.

◆ SetRecursionDepth()

void SetRecursionDepth ( int  _recursionDepth)
inline

Sets the requested recursion dept. A value of 0 or negative sets unlimited recursion depth.
Please note the explanation of recursion depth parameter in section Recursive Iteration of the parent class description.

Parameters
_recursionDepthSets the new recursion dept. Use 0 for unlimited recursion.

◆ SetStart() [1/3]

void SetStart ( Cursor  cursor)
inline

Resets this walker to represent the node that the given cursor object represents.

Parameters
cursorThe cursor to copy the represented node from.

◆ SetStart() [2/3]

void SetStart ( StringTree< T >  pm)
inline

Resets this walker to work with the given StringTree. Initializes the walker to its root node.

Parameters
pmThe StringTree to use.

◆ setStart()

void setStart ( StringTree< T >.Node  newNode)
inlineprotected

Resets this walker to represent to the given node.

Parameters
newNodeThe new node to start from

◆ SetStart() [3/3]

void SetStart ( Walker  other)
inline

Resets this walker to represent the same node that the given other walker object represents.

Parameters
otherThe walker to copy the represented node from.

◆ SetValue()

void SetValue ( value)
inline

Sets the given value to the actual node object.

Parameters
valueThe value to set.

◆ Size()

int Size ( )
inline

Returns the number of direct children of the currently represented node.

Returns
The number of children of the represented node.

◆ Skip()

void Skip ( )
inline

Skips remaining children of the current node and continues with its next sibling.

◆ SortByPathname() [1/2]

void SortByPathname ( Comparison< String >  pathSorter)
inline

Sets the sorting of children by their path name, using the given delegate.

Overloaded methods, which allow different sorting mechanics exist. This method should be invoked prior to the invocation of one of the SetStart methods which start the iteration. Invocation during iteration is allowed, but only nodes that have not been visited yet will be affected by the new sorting.

Parameters
pathSorterA custom comparison method used for sorting the children of the nodes.

◆ SortByPathname() [2/2]

void SortByPathname ( SortOrder  order = SortOrder.Ascending,
StringComparison  comparison = StringComparison.CurrentCultureIgnoreCase 
)
inline

Sets the sorting of children by their path name, using the built-in comparison method, which in turn uses C# method String.Compare.

Overloaded methods, which allow different sorting mechanics exist. This method should be invoked prior to the invocation of one of the SetStart methods which start the iteration. Invocation during iteration is allowed, but only nodes that have not been visited yet will be affected by the new sorting.

Parameters
orderThe sort order. Defaults to SortOrder.Ascending.
comparisonStandard C# string comparison flags.

◆ SortByValue()

void SortByValue ( Comparison< T >  valueSorter)
inline

Sets the sorting of children by their template value, using the given delegate.

Overloaded methods, which allow different sorting mechanics exist. This method should be invoked prior to the invocation of one of the SetStart methods which start the iteration. Invocation during iteration is allowed, but only nodes that have not been visited yet will be affected by the new sorting.

Parameters
valueSorterA custom comparison method used for sorting the children of the nodes.

◆ Value()

T Value ( )
inline

Retrieves the current StringTree nodes value.

Returns
The current StringTree node templated, custom value.

Member Data Documentation

◆ actPath

AString actPath = new AString()
protected

The path to the actual node (excluding the name of the actual node).

◆ recursionDepth

int recursionDepth = int.MaxValue
protected

The requested depth of iteration recursion.

◆ sorter

Sorter sorter = new Sorter()
protected

The sorter object. This is a fixed member of the parent class providing a method to sort children by name or value type T.

◆ stack

List<RecursionData> stack = new List<RecursionData>()
protected

A stack holding the recursive list of child maps and the idx of their current child. Implemented as a vector in combination with member stackSize, to reuse allocated storage space.

◆ stackSize

int stackSize = 0
protected

The current use of the stack.

◆ stringTree

StringTree<T> stringTree
protected

The StringTree we belong to


The documentation for this class was generated from the following file: