Пример #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>Constructs an integer from the bEncoded stream</summary>
            /// <param name="istream">Stream to construct integer from</param>
            public List(IO.Stream istream)
            {
                if (istream.CanSeek)
                {
                    this.position = (int)istream.Position - 1;
                }

                int c;

                while ((c = istream.ReadByte()) != 'e')
                {
                    BEncode.Element element = BEncode.NextElement(istream, c);
                    string          el      = element.ToString();
                    this.list.Add(element);
                }

                if (istream.CanSeek)
                {
                    this.length = (int)istream.Position - this.position;
                }
            }
Пример #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></summary>
			/// <param name="element">Object to add to list</param>
			/// <returns>Index of object added</returns>
			public int Add(BEncode.Element element)
			{
				return this.list.Add(element);
			}
Пример #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>Removes an element from the list</summary>
			/// <param name="obj">Element to remove</param>
			public void Remove(BEncode.Element element)
			{
				this.list.Remove(element);
			}
Пример #13
0
			/// <summary>Inserts an element into the list at the specified index</summary>
			/// <param name="index">Index to insert element at</param>
			/// <param name="obj">Element to insert</param>
			public void Insert(int index, BEncode.Element element)
			{
				this.list.Insert(index, element);
			}
Пример #14
0
			/// <summary>Finds the index at which the element resides</summary>
			/// <param name="obj">Element to check</param>
			/// <returns>Index of element, -1 if it does not exist</returns>
			public int IndexOf(BEncode.Element element)
			{
				return this.list.IndexOf(element);
			}
Пример #15
0
			/// <summary></summary>
			/// <param name="element">Object to check if it exists in the list</param>
			/// <returns>True if object is in the list, false otherwise</returns>
			public bool Contains(BEncode.Element element)
			{
				return this.list.Contains(element);
			}
Пример #16
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];
			}
Пример #17
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);
			}