예제 #1
0
        // ----------------------------------------- TODO HERE -------------------------------------------- //
        // ----------------------------------------- TODO HERE -------------------------------------------- //
        // ----------------------------------------- TODO HERE -------------------------------------------- //
        // ----------------------------------------- TODO HERE -------------------------------------------- //
        // ----------------------------------------- TODO HERE -------------------------------------------- //
        // ----------------------------------------- TODO HERE -------------------------------------------- //

        /// <summary>
        /// Creates an iterator for iterating over all nodes which pass a predicate
        /// </summary>
        /// <param name="predicate">The predicate</param>
        /// <param name="flowDirection">The traversal direction</param>
        /// <param name="strategy">The traversal strategy</param>
        /// <param name="includeRoot">Should the root node be included</param>
        /// <param name="depthLimits">Depth limits</param>
        /// <returns>The iterator created</returns>
        public TreeIter <TTreeNode> IterateOverAllNodesWhichPass(Predicate <TTreeNode> predicate, eTraversalFlowDirection flowDirection = TreeTraversal <TTreeNode> .DefaultTraversalFlowDirection, eTraversalStrategy strategy = TreeTraversal <TTreeNode> .DefaultTraversalStrategy, bool includeRoot = true, LevelRestriction depthLimits = null)
        {
            return(TreeTraversal <TTreeNode> .IterateOverAllNodesWhichPass(this.Root, this.Root, predicate, flowDirection, strategy, includeRoot, depthLimits, this.GetChildrenOverride, this.GetParentOverride));
        }
예제 #2
0
 public static T GetFirstParentOfType <T> (TTreeNode start, Predicate <T> predicate = null, bool includeSelf = true, bool canTypeBeAncestor = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
     where T : class, TTreeNode
 {
     return(GetFirstParentOfType <T>(null, start, predicate, includeSelf, canTypeBeAncestor, depthLimits, getChildrenMethodOverride, getParentMethodOverride));
 }
예제 #3
0
        public static T GetFirstParentOfType <T> (TTreeNode root, TTreeNode start, Predicate <T> predicate = null, bool includeSelf = true, bool canTypeBeAncestor = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
            where T : class, TTreeNode
        {
            var iter = IterateOverNodesOfType <T>(root, start, predicate, eTraversalFlowDirection.ThroughParents, eTraversalStrategy.Default, includeSelf, canTypeBeAncestor, depthLimits, getChildrenMethodOverride, getParentMethodOverride);

            if (iter != TreeIter <TTreeNode> .End)
            {
                return((T)iter.Node);
            }

            return(null);
        }
예제 #4
0
 public static TTreeNode GetFirstParentWhichPasses(TTreeNode start, Predicate <TTreeNode> predicate, bool includeSelf = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
 {
     return(GetFirstParentWhichPasses(null, start, predicate, includeSelf, depthLimits, getChildrenMethodOverride, getParentMethodOverride));
 }
예제 #5
0
        public static TTreeNode GetFirstParentWhichPasses(TTreeNode root, TTreeNode start, Predicate <TTreeNode> predicate, bool includeSelf = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
        {
            var iter = IterateOverAllNodesWhichPass(root, start, predicate, eTraversalFlowDirection.ThroughParents, eTraversalStrategy.Default, includeSelf, depthLimits, getChildrenMethodOverride, getParentMethodOverride);

            if (iter != TreeIter <TTreeNode> .End)
            {
                return(iter.Node);
            }

            return(null);
        }
예제 #6
0
 public static T GetFirstChildOfType <T> (TTreeNode start, Predicate <T> predicate = null, eTraversalFlowDirection flowDirection = DefaultTraversalFlowDirection, eTraversalStrategy strategy = DefaultTraversalStrategy, bool includeSelf = true, bool canTypeBeAncestor = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
     where T : class
 {
     return(GetFirstChildOfType <T>(null, start, predicate, flowDirection, strategy, includeSelf, canTypeBeAncestor, depthLimits, getChildrenMethodOverride, getParentMethodOverride));
 }
예제 #7
0
 public static TTreeNode GetFirstChildWhichPasses(TTreeNode start, Predicate <TTreeNode> predicate, eTraversalFlowDirection flowDirection = DefaultTraversalFlowDirection, eTraversalStrategy strategy = DefaultTraversalStrategy, bool includeSelf = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
 {
     return(GetFirstChildWhichPasses(null, start, predicate, flowDirection, strategy, includeSelf, depthLimits, getChildrenMethodOverride, getParentMethodOverride));
 }
예제 #8
0
        public static TreeIter <TTreeNode> IteratorAt(TTreeNode root, TreeNodePath nodePath, Predicate <TTreeNode> predicate = null, eTraversalFlowDirection flowDirection = DefaultTraversalFlowDirection, eTraversalStrategy strategy = DefaultTraversalStrategy, bool includeSelf = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
        {
            var traversalParams = new TreeTraversalParameters <TTreeNode>(root, flowDirection, strategy, getChildrenMethodOverride, getParentMethodOverride)
            {
                Predicate   = predicate,
                DepthLimits = depthLimits,
            };

            var iter = TreeIter <TTreeNode> .CreateIteratorAtNodePath(root, nodePath, traversalParams);

            return(FinalizeAndReturnIter(iter, includeSelf, traversalParams.Predicate, start: false));
        }
예제 #9
0
        /// <summary>
        /// Iterate over all the nodes of a particaulr type
        /// </summary>
        /// <typeparam name="T">Tree node type</typeparam>
        /// <param name="root">The tree's root node</param>
        /// <param name="start">The starting point</param>
        /// <param name="predicate">The predicate</param>
        /// <param name="flowDirection">The direction the traversal flows through the tree</param>
        /// <param name="strategy">The traversal strategy</param>
        /// <param name="includeSelf">Should the start node be included</param>
        /// <param name="canTypeBeAncestor">Can the type be derivitive of the passed in type, or must it be an exact match (default is true)</param>
        /// <param name="depthLimits">Depth limits</param>
        /// <param name="getChildrenMethodOverride">The override to the default GetTreeNodeChildren method specified in <see cref="TreeTraversal{TTreeNode}"/>.SetupDefaults, or null to use the default</param>
        /// <param name="getParentMethodOverride">The override to the default GetTreeNodeParents method specified in <see cref="TreeTraversal{TTreeNode}"/>.SetupDefaults, or null to use the default</param>
        /// <returns></returns>
        public static TreeIter <TTreeNode> IterateOverNodesOfType <T> (TTreeNode root, TTreeNode start, Predicate <T> predicate = null, eTraversalFlowDirection flowDirection = DefaultTraversalFlowDirection, eTraversalStrategy strategy = DefaultTraversalStrategy, bool includeSelf = true, bool canTypeBeAncestor = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
            where T : class
        {
            var traversalParams = new TreeTraversalParameters <TTreeNode>(root ?? FindRoot(start, getParentMethodOverride), flowDirection, strategy, getChildrenMethodOverride, getParentMethodOverride)
            {
                TypeMatching        = new TypeEval(typeof(T), canTypeBeAncestor),
                PruneAfterFirstFind = false,
                DepthLimits         = depthLimits,
            };

            if (predicate != null)
            {
                traversalParams.Predicate = (_obj) => predicate(_obj as T);
            }

            var iter = CreateIterator(start, traversalParams);

            return(FinalizeAndReturnIter(iter, includeSelf, traversalParams.Predicate));
        }
예제 #10
0
        /// <summary>
        /// Creates an iterator for iterating over all nodes which pass a predicate
        /// </summary>
        /// <param name="root">The tree's root node</param>
        /// <param name="start">The starting point</param>
        /// <param name="predicate">The predicate</param>
        /// <param name="flowDirection">The direction the traversal flows through the tree</param>
        /// <param name="strategy">The traversal strategy</param>
        /// <param name="includeSelf">Should the start node be included</param>
        /// <param name="depthLimits">Depth limits</param>
        /// <param name="getChildrenMethodOverride">The override to the default GetTreeNodeChildren method specified in <see cref="TreeTraversal{TTreeNode}"/>.SetupDefaults, or null to use the default</param>
        /// <param name="getParentMethodOverride">The override to the default GetTreeNodeParents method specified in <see cref="TreeTraversal{TTreeNode}"/>.SetupDefaults, or null to use the default</param>
        /// <returns>The iterator created</returns>
        public static TreeIter <TTreeNode> IterateOverAllNodesWhichPass(TTreeNode root, TTreeNode start, Predicate <TTreeNode> predicate, eTraversalFlowDirection flowDirection = DefaultTraversalFlowDirection, eTraversalStrategy strategy = DefaultTraversalStrategy, bool includeSelf = true, LevelRestriction depthLimits = null, GetTreeNodeChildren <TTreeNode> getChildrenMethodOverride = null, GetTreeNodeParent <TTreeNode> getParentMethodOverride = null)
        {
            var iter = CreateIterator(start, new TreeTraversalParameters <TTreeNode>(root ?? FindRoot(start, getParentMethodOverride), flowDirection, strategy, getChildrenMethodOverride, getParentMethodOverride)
            {
                Predicate   = predicate,
                DepthLimits = depthLimits
            });

            return(FinalizeAndReturnIter(iter, includeSelf, predicate));
        }