Esempio n. 1
0
        /// <summary>
        /// Sets the value of a subnode if this node is an SblGroup. If this is an SblValue or the gameItem specified is an SblGroup a type
        /// cast exception will be thrown. If there are multiple nodes with the specified name an exception will be thrown. If no
        /// node exists with the specified name, the node will be created.
        /// </summary>
        /// <param name="name">The name of the value to set.</param>
        /// <param name="value">The value to set.</param>
        public void SetValue(string name, object value)
        {
            SblGroup group  = (SblGroup)this;
            SblNode  target = null;

            for (int i = 0; i < ((SblGroup)this).Items.Count; i++)
            {
                if (group.Items[i].Name.Equals(name))
                {
                    if (target == null)
                    {
                        target = Items[i];
                    }
                    else
                    {
                        throw new InvalidOperationException("The specified name resulted in an ambiguous match.");
                    }
                }
            }
            if (target == null)
            {
                Items.Add(new WeakSblValue(name, value));
            }
            else
            {
                target.Value = value;
            }
        }
Esempio n. 2
0
 /// <summary>Creates an SblNodeEnumerator.</summary>
 /// <param name="container">The node whose subnodes to enumerate.</param>
 public SblNodeEnumerator(SblNode container)
 {
     group = container as SblGroup;
     if (group == null)
     {
         throw new ArgumentException("Container must be an SblGroup object.", "container");
     }
 }
Esempio n. 3
0
        /// <summary>Creates a deep copy of this object.</summary>
        /// <returns>a deep copy of this object</returns>
        public override SblNode Clone()
        {
            SblGroup result = new SblGroup(Name);

            foreach (SblNode item in Items)
            {
                result.Items.Add(item.Clone());
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Reads SblNodes from a stream until the end of the stream is encountered.
        /// </summary>
        /// <param name="s">The stream from which to read nodes.</param>
        /// <returns>T group containing all the read nodes.</returns>
        /// <remarks>This overload requires that the stream allows the Reposition and Length properties to be
        /// read.</remarks>
        public static SblNode GroupFromStream(Stream s)
        {
            SblGroup group = new SblGroup("StreamData");

            while (s.Position < s.Length)
            {
                group.Items.Add(FromStream(s));
            }

            return(group);
        }
Esempio n. 5
0
        /// <summary>
        /// Reads the specified number of SblNodes from a stream.
        /// </summary>
        /// <param name="s">The stream from which to read nodes.</param>
        /// <param name="nodeCount">The number of nodes to read.</param>
        /// <returns>T group containing all the read nodes.</returns>
        public static SblNode GroupFromStream(Stream s, int nodeCount)
        {
            SblGroup group = new SblGroup("StreamData");

            for (int i = 0; i < nodeCount; i++)
            {
                group.Items.Add(FromStream(s));
            }

            return(group);
        }
Esempio n. 6
0
        /// <summary>
        /// Adds an SBL value node to this node.
        /// </summary>
        /// <param name="name">The name of the node.</param>
        /// <param name="value">The value of the node.</param>
        /// <remarks>This method is provided for convenience and is not optimised for speed.</remarks>
        public SblNode AddItem(string name, char value)
        {
            SblGroup me = this as SblGroup;

            if (me == null)
            {
                throw new InvalidOperationException("This operation is only valid on SBL groups.");
            }

            me.Items.Add(new StrongSblValue <char>(name, value));
            return(me.Items[me.Items.Count - 1]);
        }
Esempio n. 7
0
        private static SblNode FromBinary(BinaryReader b)
        {
            DataType type = (DataType)(b.ReadByte());

            switch (type)
            {
            case DataType.Group:
                SblGroup newGroup  = new SblGroup(b.ReadString());
                int      itemCount = b.ReadInt32();
                for (int i = 0; i < itemCount; i++)
                {
                    newGroup.Items.Add(SblNode.FromBinary(b));
                }

                return(newGroup);

            case DataType.Int32:
                return(new StrongSblValue <int>(b.ReadString(), b.ReadInt32()));

            case DataType.Int64:
                return(new StrongSblValue <long>(b.ReadString(), b.ReadInt64()));

            case DataType.Int8:
                return(new StrongSblValue <byte>(b.ReadString(), b.ReadByte()));

            case DataType.Float:
                return(new StrongSblValue <float>(b.ReadString(), b.ReadSingle()));

            case DataType.Date:
                return(new StrongSblValue <DateTime>(b.ReadString(), DateTime.FromBinary(b.ReadInt64())));

            case DataType.Binary:
                string name  = b.ReadString();
                int    count = b.ReadInt32();
                return(new StrongSblValue <byte[]>(name, b.ReadBytes(count)));

            case DataType.Char:
                return(new StrongSblValue <char>(b.ReadString(), b.ReadChar()));

            case DataType.String:
                return(new StrongSblValue <string>(b.ReadString(), b.ReadString()));

            default:
                throw new InvalidDataException("Invalid data was encountered when reading SBL data from a stream.");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Sets the value of a subnode if this node is an SblGroup. If this is an SblValue or the gameItem specified is an SblGroup a type
        /// cast exception will be thrown. If there are multiple nodes with the specified name an exception will be thrown. If no
        /// node exists with the specified name, the node will be created.
        /// </summary>
        /// <param name="name">The name of the value to set.</param>
        /// <param name="value">The value to set.</param>
        /// <param name="ignoreCase">Whether or not to ignore the casing of the node name.</param>
        public void SetValue(string name, object value, bool ignoreCase)
        {
            SblGroup group  = (SblGroup)this;
            SblNode  target = null;

            for (int i = 0; i < ((SblGroup)this).Items.Count; i++)
            {
                if (group.Items[i].Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (target == null)
                    {
                        target = Items[i];
                    }
                    else
                    {
                        throw new InvalidOperationException("The specified name resulted in an ambiguous match.");
                    }
                }

                target.Value = value;
            }
        }
Esempio n. 9
0
 /// <summary>Disposes of this object.</summary>
 public void Dispose()
 {
     group = null;
 }