示例#1
0
        /// <summary>
        /// Expands the size of the array to be 'num' long.
        /// Does this by adding the same instance of the last
        /// item in the array until the Count is num.
        /// </summary>
        /// <param name="num">The total size the array should be.</param>
        public void ExpandTo(int num)
        {
            System.Diagnostics.Debug.Assert(Count > 0 || origionalElement != null);

            DataElement item = null;

            if (Count == 0)
            {
                item = origionalElement;
            }
            else
            {
                item = this[Count - 1];
            }


            var bs = new BitStream();

            bs.Write(item.Value);
            bs.ClearElementPositions();

            var clone = item.Clone();

            clone.MutatedValue  = new Variant(bs);
            clone.mutationFlags = DataElement.MUTATE_DEFAULT | DataElement.MUTATE_OVERRIDE_TYPE_TRANSFORM;

            // Force the same element to be duplicated in the DataElementContainer
            for (int i = Count; i < num; ++i)
            {
                _childrenList.Insert(i, clone);
                _childrenDict[clone.name] = clone;
            }

            Invalidate();
        }
示例#2
0
        /// <summary>
        /// Expands the size of the array to be 'num' long.
        /// Does this by adding the same instance of the last
        /// item in the array until the Count is num.
        /// </summary>
        /// <param name="num">The total size the array should be.</param>
        public void ExpandTo(int num)
        {
            System.Diagnostics.Debug.Assert(Count > 0 || origionalElement != null);

            DataElement item = null;

            if (Count == 0)
            {
                item = origionalElement;
            }
            else
            {
                item = this[Count - 1];
            }


            var bs = new BitStream();

            item.Value.SeekBits(0, System.IO.SeekOrigin.Begin);
            item.Value.CopyTo(bs);

            var clone = item.Clone();

            clone.MutatedValue  = new Variant(bs);
            clone.mutationFlags = MutateOverride.Default | MutateOverride.TypeTransform;

            // Force the same element to be duplicated in the DataElementContainer
            for (int i = Count; i < num; ++i)
            {
                _childrenList.Insert(i, clone);
                _childrenDict[clone.name] = clone;
            }

            Invalidate();
        }
示例#3
0
        public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent)
        {
            if (node.Name != "Block")
            {
                return(null);
            }

            Block block = null;

            if (node.hasAttr("ref"))
            {
                string name    = node.getAttr("name", null);
                string refName = node.getAttrString("ref");

                DataElement refObj = context.getReference(refName, parent);
                if (refObj == null)
                {
                    throw new PeachException("Error, Block {0}could not resolve ref '{1}'. XML:\n{2}".Fmt(
                                                 name == null ? "" : "'" + name + "' ", refName, node.OuterXml));
                }

                if (!(refObj is Block))
                {
                    throw new PeachException("Error, Block {0}resolved ref '{1}' to unsupported element {2}. XML:\n{3}".Fmt(
                                                 name == null ? "" : "'" + name + "' ", refName, refObj.debugName, node.OuterXml));
                }

                if (string.IsNullOrEmpty(name))
                {
                    name = new Block().name;
                }

                block               = refObj.Clone(name) as Block;
                block.parent        = parent;
                block.isReference   = true;
                block.referenceName = refName;
            }
            else
            {
                block        = DataElement.Generate <Block>(node);
                block.parent = parent;
            }

            context.handleCommonDataElementAttributes(node, block);
            context.handleCommonDataElementChildren(node, block);
            context.handleDataElementContainer(node, block);

            return(block);
        }