using System.Collections.Generic;

namespace WS
{
    ///<summary>内存数据对象池-属性类</summary>
    public class ComponentQueue : WSComponent
    {
		///<summary>类型名称</summary>
		public string TypeName { get; }
		///<summary>示例队列</summary>
		private readonly Queue<WSComponent> queue = new Queue<WSComponent>();

		public ComponentQueue(string typeName)
		{
			TypeName = typeName;
		}
		///<summary>入队</summary>
		public void Enqueue(WSComponent component)
		{
			component.Parent = this;
			queue.Enqueue(component);
		}
		///<summary>出列</summary>
		public WSComponent Dequeue()
		{
			return queue.Dequeue();
		}
		///<summary>查看开始处的对象但不将其移除</summary>
		public WSComponent Peek()
		{
			return queue.Peek();
		}
		///<summary>数量</summary>
		public int Count
		{
			get
			{
				return queue.Count;
			}
		}

		public override void Dispose()
		{
			if (IsDisposed)
			{
				return;
			}
			base.Dispose();

			while (this.queue.Count > 0)
			{
				WSComponent component = queue.Dequeue();
				component.IsFromPool = false;
				component.Dispose();
			}
		}
	}
}