mirror of https://github.com/deavmi/niknaks
Compare commits
3 Commits
9339b87ab3
...
5f66b99434
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 5f66b99434 | |
Tristan B. Velloza Kildaire | 51499dab47 | |
Tristan B. Velloza Kildaire | 13145bd83a |
|
@ -624,12 +624,20 @@ public template Always(T)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A touching stratergy
|
||||
* that does nothing
|
||||
*/
|
||||
public template Nothing(T)
|
||||
{
|
||||
public void Nothing(Tree!(T) treeNode)
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* Consumes a tree node
|
||||
* and does zilch with it
|
||||
*
|
||||
* Params:
|
||||
* treeNode = the node
|
||||
*/
|
||||
public void Nothing(Tree!(T));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -660,8 +668,6 @@ public template TouchStratergy(T)
|
|||
public alias TouchStratergy = void delegate(Tree!(T) item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: Technically this is a graph
|
||||
public class Tree(T)
|
||||
{
|
||||
|
@ -751,7 +757,7 @@ public class Tree(T)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static bool isTreeNodeType(E)()
|
||||
{
|
||||
return __traits(isSame, E, Tree!(T));
|
||||
|
@ -762,6 +768,15 @@ public class Tree(T)
|
|||
return __traits(isSame, E, T);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a slice of the requested
|
||||
* type. This is either `Tree!(T)`
|
||||
* or `T` itself, therefore returning
|
||||
* an array of either
|
||||
*
|
||||
* Returns: an array of the requested
|
||||
* type of children
|
||||
*/
|
||||
public E[] opSlice(E)()
|
||||
if(isTreeNodeType!(E) || isTreeValueType!(E))
|
||||
{
|
||||
|
@ -784,11 +799,33 @@ public class Tree(T)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the childrens'
|
||||
* associated values
|
||||
*
|
||||
* Returns: a `T[]`
|
||||
*/
|
||||
public T[] opSlice()
|
||||
{
|
||||
return opSlice!(T)();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element of the child
|
||||
* at the given index.
|
||||
*
|
||||
* The type `E` can be specified
|
||||
* as either `Tree!(T)` or `T`
|
||||
* which will hence return a node
|
||||
* from the children array at the
|
||||
* given index of that tyope (either
|
||||
* the child node or the child node's
|
||||
* value).
|
||||
*
|
||||
* Params:
|
||||
* idx = the index
|
||||
* Returns: the type `E`
|
||||
*/
|
||||
public E opIndex(E)(size_t idx)
|
||||
if(isTreeNodeType!(E) || isTreeValueType!(E))
|
||||
{
|
||||
|
@ -804,6 +841,15 @@ public class Tree(T)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of
|
||||
* the child node at
|
||||
* the provided index
|
||||
*
|
||||
* Params:
|
||||
* idx = the index
|
||||
* Returns: the value
|
||||
*/
|
||||
public T opIndex(size_t idx)
|
||||
{
|
||||
return opIndex!(T)(idx);
|
||||
|
|
Loading…
Reference in New Issue