示例#1
0
            /// <summary>
            /// Constructs a dictionary
            /// </summary>
            /// <param name="istream">Stream to construct dictionary from</param>
            public Dictionary(IO.Stream istream)
            {
                if (istream.CanSeek)
                {
                    this.position = (int)istream.Position - 1;
                }
                int c;

                while ((c = istream.ReadByte()) != 'e')
                {
                    BEncode.String key     = new BEncode.String(istream, c);                 // keys are always strings
                    string         strkey  = key;
                    Element        element = BEncode.NextElement(istream);

                    if (!this.map.Contains(key))
                    {
                        this.map.Add(key, element);
                    }
                }

                if (istream.CanSeek)
                {
                    this.length = (int)istream.Position - this.position;
                }
            }
示例#2
0
            /// <summary>Compares the object passed in to see if it is the same</summary>
            /// <param name="obj">Object to compare to</param>
            /// <returns>True if the same, false otherwise</returns>
            public override bool Equals(object obj)
            {
                if (obj is BEncode.String)
                {
                    BEncode.String str = (BEncode.String)obj;
                    if (str.data.Length != this.data.Length)
                    {
                        return(false);
                    }

                    for (int i = 0; i < str.data.Length; ++i)
                    {
                        if (str.data[i] != this.data[i])
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
示例#3
0
 /// <summary>Adds a key-value pair to the dictionary</summary>
 /// <param name="key">Key</param>
 /// <param name="val">Value</param>
 public void Add(BEncode.String key, BEncode.Element val)
 {
     this.map.Add(key, val);
 }
示例#4
0
 /// <summary>Checks if the key exists in the dictionary</summary>
 /// <param name="key">Key to check</param>
 /// <returns>True if the key exists</returns>
 public bool Contains(BEncode.String key)
 {
     return(this.map.Contains(key));
 }
示例#5
0
 /// <summary>Removes a key-value pair from the dictionary</summary>
 /// <param name="key">Key to remove</param>
 public void Remove(BEncode.String key)
 {
     this.map.Remove(key);
 }
示例#6
0
 /// <summary>Retrieves the value associated with the specified key</summary>
 /// <param name="key">Key</param>
 /// <returns>Value</returns>
 public BEncode.Element this[BEncode.String key]
 {
     get { return((BEncode.Element) this.map[key]); }
     set { this.map[key] = value; }
 }
示例#7
0
 /// <summary>
 /// Gets the integer with the specified key. Same as GetElement(), except performs the casting automatically.
 /// </summary>
 /// <param name="key">Key name</param>
 /// <returns>Integer element</returns>
 public int GetInteger(BEncode.String key)
 {
     return((BEncode.Integer) this[key]);
 }
示例#8
0
 /// <summary>
 /// Gets the bytes with the specified key. Same as GetElement(), except performs the casting automatically.
 /// </summary>
 /// <param name="key">Key name</param>
 /// <returns>Bytes element</returns>
 public byte[] GetBytes(BEncode.String key)
 {
     return(((BEncode.String) this[key]).Data);
 }
示例#9
0
 /// <summary>
 /// Gets the string with the specified key. Same as GetElement(), except performs the casting automatically.
 /// </summary>
 /// <param name="key">Key name</param>
 /// <returns>String element</returns>
 public string GetString(BEncode.String key)
 {
     return((BEncode.String) this[key]);
 }
示例#10
0
 /// <summary>
 /// Gets the list with the specified key. Same as GetElement(), except performs the casting automatically.
 /// </summary>
 /// <param name="key">Key name</param>
 /// <returns>List element</returns>
 public List GetList(BEncode.String key)
 {
     return((BEncode.List) this[key]);
 }
示例#11
0
 /// <summary>
 /// Gets the dictionary with the specified key. Same as GetElement(), except performs the casting automatically.
 /// </summary>
 /// <param name="key">Key name</param>
 /// <returns>Dictionary element</returns>
 public Dictionary GetDictionary(BEncode.String key)
 {
     return((BEncode.Dictionary) this[key]);
 }
示例#12
0
 /// <summary>Compares the two objects</summary>
 /// <param name="str">String to compare to</param>
 /// <returns>Zero if they are the same</returns>
 public int CompareTo(BEncode.String str)
 {
     return(this.ToString().CompareTo(str));
 }
示例#13
0
			/// <summary>
			/// Constructs a dictionary
			/// </summary>
			/// <param name="istream">Stream to construct dictionary from</param>
			public Dictionary(IO.Stream istream)
			{
				if (istream.CanSeek)
					this.position = (int)istream.Position - 1;
				int c;

				while ((c = istream.ReadByte()) != 'e')
				{
					BEncode.String key = new BEncode.String(istream, c); // keys are always strings
					string strkey = key;
					Element element = BEncode.NextElement(istream);

					if (!this.map.Contains(key))
						this.map.Add(key, element);
				}

				if (istream.CanSeek)
					this.length = (int)istream.Position - this.position;
			}