Esempio n. 1
0
 // Constructor
 protected CTreeNode(UInt32 uId, System.Object objData)
 {
     m_uNodeId    = uId;
     m_objData    = null;
     m_NodeParent = null;
     m_Children   = null;
 }
Esempio n. 2
0
        /// <summary>
        /// 挂接子节点
        /// </summary>
        /// <param name="childNode"></param>
        /// <returns></returns>
        public bool AttachChild(CTreeNode childNode)
        {
            if (childNode == null)
            {
                return(false);
            }
            if (childNode.m_NodeParent != null)
            {
                return(false);
            }
            UInt32 uChildID = childNode.GetNodeID();

            if (ContainChild(uChildID) == true)
            {
                return(false);
            }

            // 挂接到父节点
            childNode.m_NodeParent = this;
            // 添加到子节点
            if (m_Children == null)
            {
                m_Children = new QuickList <UInt32, CTreeNode>();
            }
            if (m_Children.Add(uChildID, childNode) == false)
            {
                childNode.m_NodeParent = null;
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 深度
        /// </summary>
        /// <returns></returns>
        public Int32 Depth()
        {
            if (m_Children == null)
            {
                return(1);
            }
            Int32 nChildSize = m_Children.Count;

            if (nChildSize == 0)
            {
                return(1);
            }
            Int32 nMaxDepth = 1;

            for (Int32 i = 0; i < nChildSize; ++i)
            {
                CTreeNode childNode = m_Children[i];
                if (childNode == null)
                {
                    continue;
                }
                Int32 nDepth = childNode.Depth();
                if (nDepth >= nMaxDepth)
                {
                    nMaxDepth = nDepth + 1;
                }
            }
            return(nMaxDepth);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取子节点
        /// </summary>
        /// <param name="uChildId"></param>
        /// <returns></returns>
        public CTreeNode GetChildNode(UInt32 uChildId)
        {
            if (m_Children == null)
            {
                return(null);
            }
            CTreeNode child = null;

            if (m_Children.QuickFind(uChildId, ref child) == false)
            {
                return(null);
            }
            return(child);
        }
Esempio n. 5
0
        /// <summary>
        /// 移出子节点
        /// </summary>
        /// <param name="uChildId"></param>
        /// <returns></returns>
        public CTreeNode RemoveChild(UInt32 uChildId)
        {
            if (m_Children == null)
            {
                return(null);
            }
            CTreeNode childNode = GetChildNode(uChildId);

            if (childNode == null)
            {
                return(null);
            }
            childNode.m_NodeParent = null;
            return(childNode);
        }
Esempio n. 6
0
        /// <summary>
        /// 移出子节点
        /// </summary>
        /// <param name="uChildId"></param>
        /// <returns></returns>
        public CTreeNode RemoveChild(UInt32 uChildId)
        {
            if (m_Children == null)
            {
                return(null);
            }
            CTreeNode childNode = null;

            if (m_Children.Pop(uChildId, ref childNode) == false || childNode == null)
            {
                return(null);
            }
            childNode.m_NodeParent = null;

            return(childNode);
        }
Esempio n. 7
0
        /// <summary>
        /// 添加子节点
        /// </summary>
        /// <param name="uNodeId"></param>
        /// <param name="sysObj"></param>
        /// <returns></returns>
        public bool AddChild(UInt32 uNodeId, System.Object sysObj)
        {
            if (m_Children.ContainKey(uNodeId) == true)
            {
                return(false);
            }
            if (m_Children == null)
            {
                m_Children = new QuickList <UInt32, CTreeNode>();
            }

            CTreeNode newNode = new CTreeNode(uNodeId, sysObj);
            bool      bAdd    = AttachChild(newNode);

            return(bAdd);
        }
Esempio n. 8
0
        /// <summary>
        /// 获取子节点
        /// </summary>
        /// <param name="uChildId"></param>
        /// <returns></returns>
        public CTreeNode GetChildNode(UInt32 uChildId)
        {
            if (m_Children == null)
            {
                return(null);
            }
            Int32 nSize = m_Children.Count;

            for (Int32 i = 0; i < nSize; ++i)
            {
                CTreeNode node = m_Children[i];
                if (node == null)
                {
                    continue;
                }
                if (node.GetNodeID() == uChildId)
                {
                    return(node);
                }
            }
            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// 包含子节点
        /// </summary>
        /// <param name="uNodeId"></param>
        /// <returns></returns>
        public bool ContainChild(UInt32 uNodeId)
        {
            if (m_Children == null)
            {
                return(false);
            }
            Int32 nSize = m_Children.Count;

            for (Int32 i = 0; i < nSize; ++i)
            {
                CTreeNode node = m_Children[i];
                if (node == null)
                {
                    continue;
                }
                if (node.GetNodeID() == uNodeId)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 10
0
 public CBTTree(System.Object objRootData)
 {
     m_NodeRoot = CTreeNode.NewTreeRootNode(objRootData);
 }
Esempio n. 11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="objData"></param>
        /// <returns></returns>
        public static CTreeNode NewTreeRootNode(System.Object objData)
        {
            CTreeNode rootNode = new CTreeNode(0, objData);

            return(rootNode);
        }