//-----------------------------------------------------------------------------
// BatchRemovalCollection.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace NetRumble
{
    /// 
    /// A collection with an additional feature to isolate the
    /// removal of the objects.
    /// 
    public class BatchRemovalCollection : List
    {
        /// 
        /// The list of objects to be removed on the next ApplyPendingRemovals().
        /// 
        private List pendingRemovals;
        /// 
        /// Constructs a new collection.
        /// 
        public BatchRemovalCollection()
        {
            pendingRemovals = new List();
        }
        /// 
        /// Queue an item for removal.
        /// 
        /// 
        public void QueuePendingRemoval(T item)
        {
            pendingRemovals.Add(item);
        }
        /// 
        /// Remove all of the "garbage" objects from this collection.
        /// 
        public void ApplyPendingRemovals()
        {
            for (int i = 0; i < pendingRemovals.Count; i++)
            {
                Remove(pendingRemovals[i]);
            }
            pendingRemovals.Clear();
        }
    }
}