Ejemplo n.º 1
0
        /// <summary>
        /// Gets the nth child of the provided iter.
        /// </summary>
        /// <param name="iter">Will contain the nth child.</param>
        /// <param name="parent">The iter to get the child of.</param>
        /// <param name="n">The value of n.</param>
        /// <returns>true if the iter is now set to the nth child of the parent; false otherwise</returns>
        /// <exception cref="InvalidDataException">Thrown if the iter doesn't belong to the model.</exception>
        /// <exception cref="ArgumentException">Thrown if the iter is not valid.</exception>
        public bool IterNthChild(out TreeIter iter, TreeIter parent, int n)
        {
            if (parent.Stamp != this.Stamp && !parent.Equals(TreeIter.Zero))
            {
                throw new InvalidDataException("The given parent was not valid for this model.");
            }

            iter = TreeIter.Zero;

            if (n < 0)
            {
                return(false);
            }

            FileNode node = iter.Equals(TreeIter.Zero) ? this.Tree.Root : this.Tree.GetNode((ulong)iter.UserData);

            if (node == null)
            {
                throw new ArgumentException("The given iter was not valid.", nameof(parent));
            }

            if (!node.HasChildren() || n > (int)node.ChildCount - 1)
            {
                return(false);
            }

            iter.UserData = new IntPtr((long)node.ChildOffsets[n]);
            iter.Stamp    = this.Stamp;
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the iter of the first child of the given iter.
        /// </summary>
        /// <param name="iter">Will contain the first child.</param>
        /// <param name="parent">The iter to get the first child from.</param>
        /// <returns>true if the iter is now set to the first child of the parent; false otherwise</returns>
        /// <exception cref="InvalidDataException">Thrown if the iter doesn't belong to the model.</exception>
        /// <exception cref="ArgumentException">Thrown if the iter is not valid.</exception>
        public bool IterChildren(out TreeIter iter, TreeIter parent)
        {
            if (parent.Stamp != this.Stamp)
            {
                throw new InvalidDataException("The given parent was not valid for this model.");
            }

            iter = TreeIter.Zero;

            FileNode node = parent.Equals(TreeIter.Zero) ? this.Tree.Root : this.Tree.GetNode((ulong)parent.UserData);

            if (node == null)
            {
                throw new ArgumentException("The given iter was not valid.", nameof(parent));
            }

            if (!node.HasChildren())
            {
                return(false);
            }

            iter.UserData = new IntPtr((long)node.ChildOffsets.First());
            iter.Stamp    = this.Stamp;
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether or not the given iter has any children.
        /// </summary>
        /// <param name="iter">The iter to check.</param>
        /// <returns>true if the iter has any children; false otherwise</returns>
        /// <exception cref="InvalidDataException">Thrown if the iter doesn't belong to the model.</exception>
        /// <exception cref="ArgumentException">Thrown if the iter is not valid.</exception>
        public bool IterHasChild(TreeIter iter)
        {
            if (iter.Stamp != this.Stamp)
            {
                throw new InvalidDataException("The given iter was not valid for this model.");
            }

            FileNode node = iter.Equals(TreeIter.Zero) ? this.Tree.Root : this.Tree.GetNode((ulong)iter.UserData);

            if (node == null)
            {
                throw new ArgumentException("The given iter was not valid.", nameof(iter));
            }

            return(node.HasChildren());
        }