コード例 #1
0
        public static DocumentMapNode CreateNode(IDocumentMap docMap)
        {
            if (docMap == null)
            {
                return(null);
            }
            Stack <NodeStackEntry>  stack     = new Stack <NodeStackEntry>();
            List <DocumentMapNode>  workspace = new List <DocumentMapNode>();
            OnDemandDocumentMapNode onDemandDocumentMapNode = null;

            while (docMap.MoveNext())
            {
                onDemandDocumentMapNode = docMap.Current;
                NodeStackEntry item = default(NodeStackEntry);
                item.Node  = DocumentMapNode.FromOnDemandNode(onDemandDocumentMapNode);
                item.Level = onDemandDocumentMapNode.Level;
                while (stack.Count > 0 && onDemandDocumentMapNode.Level < stack.Peek().Level)
                {
                    DocumentMapNode.CollapseTopLevel(stack, workspace);
                }
                stack.Push(item);
            }
            while (stack.Count > 1)
            {
                DocumentMapNode.CollapseTopLevel(stack, workspace);
            }
            return(stack.Pop().Node);
        }
コード例 #2
0
        public static DocumentMapNode CreateTree(IDocumentMap docMap, string rootName)
        {
            DocumentMapNode documentMapNode = DocumentMapNode.CreateNode(docMap);

            if (documentMapNode != null)
            {
                documentMapNode.m_label = rootName;
            }
            return(documentMapNode);
        }
コード例 #3
0
 private static void CollapseTopLevel(Stack <NodeStackEntry> nodeStack, List <DocumentMapNode> workspace)
 {
     if (nodeStack != null && nodeStack.Count > 1)
     {
         int level = nodeStack.Peek().Level;
         workspace.Clear();
         while (nodeStack.Peek().Level == level)
         {
             workspace.Add(nodeStack.Pop().Node);
         }
         DocumentMapNode node = nodeStack.Peek().Node;
         node.SetNodeChildren(new DocumentMapNode[workspace.Count]);
         for (int num = workspace.Count - 1; num >= 0; num--)
         {
             node.Children[workspace.Count - num - 1] = workspace[num];
         }
     }
 }